68 lines
2.4 KiB
Python
68 lines
2.4 KiB
Python
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)
|