import edward
All checks were successful
Gitea Actions Demo / deploy (push) Successful in 15s

This commit is contained in:
konjacpotato
2025-11-12 21:19:26 +08:00
commit 5267db8a0d
48 changed files with 1848 additions and 0 deletions

View File

@ -0,0 +1,67 @@
from database.database import get_session
from database.thotcontent.crud import get_hot_content_by_topic_id
from database.thottopic.crud import get_latest_hot_topic, update_hot_topic, get_hot_topic_by_id
from llm.local.ollama import Ollama
from log.log_manager import log
if __name__ == '__main__':
with get_session() as db:
# 1. 获取热点话题
latest_hot_topic = get_hot_topic_by_id(db, 265) # 根据话题ID获取特定的热点话题
# latest_hot_topic = get_latest_hot_topic(db) # 获取最新的热点话题
topic = latest_hot_topic.topic
print(latest_hot_topic)
# 2. 获取话题内容
hot_contents = get_hot_content_by_topic_id(db, latest_hot_topic.id)
for hot_content in hot_contents:
print(hot_content)
# 统计hot_content.content的字数
print(len(hot_content.content))
topic_content = [hot_content.content for hot_content in hot_contents]
print(topic_content)
print(topic_content[0])
print('----------------------------------------------------')
print(topic_content[1])
print('----------------------------------------------------')
print(topic_content[2])
print('----------------------------------------------------')
input_message = (
"""
你是一个专业的编辑。你的任务是根据提供的话题和素材,生成一片口述稿。
要求如下:
1 字数控制在200到1000字之间。
话题如下:
"""
+
topic
+
"""
素材是三位网友的见解:
"""
+
"""
第一位网友说:
"""
+
topic_content[0]
+
"""
第二位网友说:
"""
+
topic_content[1]
+
"""
第三位网友说:
"""
+
topic_content[2]
)
ollama = Ollama()
if not ollama.is_service_running():
log("ai_summary_task finish, ollama service not running")
else:
result = ollama.generate_text(input_message)
log(result)
latest_hot_topic.ai_script = result
update_hot_topic(db, latest_hot_topic)

View File

@ -0,0 +1,73 @@
import json
from json import JSONDecodeError
from database.database import get_session
from database.tvideoscript.video_script import get_today_video_script, update_video_script
from llm.local.ollama import Ollama
from log.log_manager import log
from task.manager_task import execute_task
def ai_script_task():
with get_session() as db:
# 1. 获取今日的热点话题列表
video_scripts = get_today_video_script(db)
if len(video_scripts) == 0:
log("ai_script_task finish, task size 0")
return
log(f"ai script task size {len(video_scripts)}")
ollama = Ollama()
if not ollama.is_service_running():
log("ai_script_task finish, ollama service not running")
return
for video_script in video_scripts:
topic = video_script.title
log(f'generate script for topic: {topic}')
# 2. 获取话题内容
content = video_script.content
input_message = (
"""
## 角色
- 你是一个资深编辑。
## 目标
- 从输入的素材中选取有用的信息。
## 任务描述
- 从contents中选取最能吸引人的段落或句子使读者产生兴趣和共鸣。请确保这些内容具有情感张力、戏剧性、趣味性或引发思考的价值。选取两部分内容分别使用键“content_one”和“content_two”。每部分不少于100个汉字。两部分内容字数之和不多于600个汉字。
## 要求
- 严格遵守字数要求。
- 直接输出内容。
- 内容为JSON格式。
## 素材如下
""" + content
)
# log(input_message)
# 3. 调用ollama生成话题脚本
llm_result = ollama.generate_text(input_message)
log(llm_result)
try:
llm_result = json.loads(llm_result)
except JSONDecodeError as e:
log(f"ai_script_task error: {e}. skip topic: {topic}")
continue
video_script.script = (
f"""{video_script.title}
{video_script.description}
一位网友说:
{llm_result["content_one"]}
另一位网友说:
{llm_result["content_two"]}
关于这个问题大家有什么看法呢?
欢迎评论区留言
"""
)
# 4. 保存话题脚本
update_video_script(db, video_script)
if __name__ == "__main__":
execute_task(ai_script_task)