This commit is contained in:
@ -23,6 +23,18 @@ def story_edit_task():
|
||||
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}")
|
||||
# llm生成的结果有时不是json结构,会在前后增加一些文本,需要提取出json部分进行解析
|
||||
try:
|
||||
json_start = story.find("{")
|
||||
json_end = story.rfind("}") + 1
|
||||
if json_start != -1 and json_end != -1:
|
||||
story = story[json_start:json_end]
|
||||
else:
|
||||
logger.warning(f"story_edit_task content id: {content.id} llm生成的结果不是有效的json格式,无法提取故事内容")
|
||||
continue
|
||||
except json.JSONDecodeError:
|
||||
logger.warning(f"story_edit_task content id: {content.id} llm生成的结果不是有效的json格式,无法解析故事内容")
|
||||
continue
|
||||
# 将生成的故事写入Article表
|
||||
json_story = json.loads(story)
|
||||
title = json_story.get("title", "无标题")
|
||||
|
||||
Reference in New Issue
Block a user