42 lines
1.7 KiB
Python
42 lines
1.7 KiB
Python
from datetime import datetime
|
|
import json
|
|
from task.manager_task import execute_task
|
|
from config.database import SessionLocal
|
|
from models import SourceContent, Article
|
|
from utils import logger
|
|
from llm import LLMThinkingEngine
|
|
|
|
|
|
def story_edit_task():
|
|
with SessionLocal() as db:
|
|
# 获取今天的所有帖子信息
|
|
today_contents = db.query(SourceContent).filter(
|
|
SourceContent.create_time >= datetime.today().replace(hour=0, minute=0, second=0, microsecond=0)
|
|
).limit(10).all()
|
|
if len(today_contents) == 0:
|
|
logger.info("story_edit_task finish, content size 0")
|
|
return
|
|
logger.info(f"story_edit_task get {len(today_contents)} contents")
|
|
|
|
llm_engine = LLMThinkingEngine(system_prompt_file="real_estate_story_system_prompt.txt")
|
|
for content in today_contents:
|
|
logger.info(f"story_edit_task content id: {content.id}, title: {content.link}, platform: {content.platform}")
|
|
story = llm_engine.think(f"故事素材:{content.content}")
|
|
logger.info(f"story_edit_task content id: {content.id} story: {story}")
|
|
# 将生成的故事写入Article表
|
|
json_story = json.loads(story)
|
|
title = json_story.get("title", "无标题")
|
|
paragraphs = json_story.get("body", ["无内容"])
|
|
article_content = "\n".join(paragraphs)
|
|
article = Article(
|
|
title=title,
|
|
keywords=None,
|
|
content=article_content,
|
|
used=False
|
|
)
|
|
db.add(article)
|
|
db.commit()
|
|
# break # 目前先处理一条内容,后续再改成批量处理
|
|
|
|
if __name__ == "__main__":
|
|
execute_task(story_edit_task) |