Files
skills_repo/event-publisher/scripts/generate_content.sh
jeremygan2021 f5117a90d1 first commit
2026-03-04 19:24:05 +08:00

97 lines
3.4 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 活动文案生成脚本 - Event Publisher Skill
# 使用豆包大模型生成 Markdown 格式的活动文案
# 获取脚本所在目录的绝对路径
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SKILL_DIR="$(dirname "$SCRIPT_DIR")"
ASSETS_DIR="$SKILL_DIR/assets"
# 确保 assets 目录存在
mkdir -p "$ASSETS_DIR"
# 加载环境变量
if [ -f "$SCRIPT_DIR/.env" ]; then
source "$SCRIPT_DIR/.env"
elif [ -f "$SKILL_DIR/.env" ]; then
source "$SKILL_DIR/.env"
fi
# 默认值
DOUBAO_API_KEY="${DOUBAO_API_KEY:-db1f8b60-0ffc-473c-98da-40daa3a95df8}"
generate_content() {
local topic="$1"
local time="$2"
local location="$3"
local extra_info="$4"
echo "======================================"
echo "📝 正在生成活动文案..."
echo "======================================"
echo ">>> 主题: $topic"
echo ">>> 时间: $time"
echo ">>> 地点: $location"
# 构建 Prompt
local system_prompt="你是一个专业的活动策划师。请根据用户提供的信息生成一份精美的活动文案Markdown格式
要求:
1. 包含主标题H1和副标题
2. 开头要有吸引人的活动介绍包含emoji表情
3. 活动亮点部分(使用列表)
4. 时间安排(使用表格)
5. 活动流程(使用表格)
6. 结尾要有号召性用语
7. 整体风格要热情、活泼、有感染力
8. 直接输出Markdown内容不要包含```markdown```标记,也不要包含其他解释性文字。"
local user_prompt="请生成一份活动文案:
- 活动主题:$topic
- 活动时间:$time
- 活动地点:$location
- 其他要求:$extra_info"
# URL编码
local user_prompt_encoded=$(python3 -c "import urllib.parse; print(urllib.parse.quote('''$user_prompt'''))")
# JSON数据
local json_data="{\"model\":\"doubao-seed-2-0-pro-260215\",\"messages\":[{\"role\":\"system\",\"content\":\"$system_prompt\"},{\"role\":\"user\",\"content\":\"$user_prompt_encoded\"}],\"max_tokens\":2000}"
# 调用API
response=$(curl -s -X POST "https://ark.cn-beijing.volces.com/api/v3/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DOUBAO_API_KEY" \
--data-binary "$json_data")
# 解析响应
content=$(echo "$response" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['choices'][0]['message']['content'] if d.get('choices') else '')" 2>/dev/null)
if [ -n "$content" ]; then
# 清理可能的 markdown 标记
content=$(echo "$content" | sed 's/^```markdown//' | sed 's/^```//' | sed 's/```$//')
# 生成文件名(使用主题名,替换空格为下划线)
safe_topic=$(echo "$topic" | tr ' ' '_')
output_file="$ASSETS_DIR/${safe_topic}_活动文案.md"
echo "$content" > "$output_file"
echo ""
echo "✅ 活动文案已生成: $output_file"
echo "--------------------------------------"
head -n 10 "$output_file"
echo "..."
echo "--------------------------------------"
else
echo "❌ 文案生成失败"
echo "$response"
fi
}
if [ $# -lt 1 ]; then
echo "用法: $0 <活动主题> [时间] [地点] [其他信息]"
echo "示例: $0 '春节游园会' '2月12日' '市中心广场' '包含灯谜和美食'"
exit 1
fi
generate_content "$1" "$2" "$3" "$4"