增加了选题api的调度,选题api的调度存在问题

This commit is contained in:
jinye_huang 2025-07-11 16:23:32 +08:00
parent db1319eb11
commit b6910ee15b
8 changed files with 25 additions and 8 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
API模型模块 API模型模块
""" """

View File

@ -47,7 +47,6 @@ class ContentWithPromptRequest(BaseModel):
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
router = APIRouter( router = APIRouter(
prefix="/tweet",
tags=["tweet"], tags=["tweet"],
responses={404: {"description": "Not found"}}, responses={404: {"description": "Not found"}},
) )

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
API服务模块 API服务模块
""" """

View File

@ -17,6 +17,8 @@ from utils.file_io import OutputManager
from tweet.topic_generator import TopicGenerator from tweet.topic_generator import TopicGenerator
from tweet.content_generator import ContentGenerator from tweet.content_generator import ContentGenerator
from tweet.content_judger import ContentJudger from tweet.content_judger import ContentJudger
from api.services.prompt_builder import PromptBuilderService
from api.services.prompt_service import PromptService
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -42,6 +44,10 @@ class TweetService:
self.content_generator = ContentGenerator(ai_agent, config_manager, output_manager) self.content_generator = ContentGenerator(ai_agent, config_manager, output_manager)
self.content_judger = ContentJudger(ai_agent, config_manager, output_manager) self.content_judger = ContentJudger(ai_agent, config_manager, output_manager)
# 初始化提示词服务和构建器
self.prompt_service = PromptService(config_manager)
self.prompt_builder = PromptBuilderService(config_manager, self.prompt_service)
async def generate_topics(self, date: str, num_topics: int = 5, async def generate_topics(self, date: str, num_topics: int = 5,
style: Optional[str] = None, style: Optional[str] = None,
target_audience: Optional[str] = None) -> Tuple[str, List[Dict[str, Any]]]: target_audience: Optional[str] = None) -> Tuple[str, List[Dict[str, Any]]]:
@ -64,8 +70,14 @@ class TweetService:
topic_config.topic.date = date topic_config.topic.date = date
topic_config.topic.num = num_topics topic_config.topic.num = num_topics
# 生成选题 # 使用PromptBuilderService构建提示词
topics = await self.topic_generator.generate_topics() system_prompt, user_prompt = self.prompt_builder.build_topic_prompt(
num_topics=num_topics,
month=date
)
# 使用预构建的提示词生成选题
topics = await self.topic_generator.generate_topics_with_prompt(system_prompt, user_prompt)
if not topics: if not topics:
logger.error("未能生成任何选题") logger.error("未能生成任何选题")
return str(uuid.uuid4()), [] return str(uuid.uuid4()), []
@ -89,8 +101,11 @@ class TweetService:
topic_index = topic.get('index', 'unknown') topic_index = topic.get('index', 'unknown')
logger.info(f"开始为选题 {topic_index} 生成内容") logger.info(f"开始为选题 {topic_index} 生成内容")
# 生成内容 # 使用PromptBuilderService构建提示词
content = await self.content_generator.generate_content_for_topic(topic) system_prompt, user_prompt = self.prompt_builder.build_content_prompt(topic, "content")
# 使用预构建的提示词生成内容
content = await self.content_generator.generate_content_with_prompt(topic, system_prompt, user_prompt)
# 生成请求ID # 生成请求ID
request_id = f"content_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{str(uuid.uuid4())[:8]}" request_id = f"content_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{str(uuid.uuid4())[:8]}"
@ -136,6 +151,9 @@ class TweetService:
topic_index = topic.get('index', 'unknown') topic_index = topic.get('index', 'unknown')
logger.info(f"开始审核选题 {topic_index} 的内容") logger.info(f"开始审核选题 {topic_index} 的内容")
# 使用PromptBuilderService构建提示词
system_prompt, user_prompt = self.prompt_builder.build_judge_prompt(topic, content)
# 审核内容 # 审核内容
judged_data = await self.content_judger.judge_content(content, topic) judged_data = await self.content_judger.judge_content(content, topic)
judge_success = judged_data.get('judge_success', False) judge_success = judged_data.get('judge_success', False)
@ -178,7 +196,7 @@ class TweetService:
contents = {} contents = {}
for topic in topics: for topic in topics:
topic_index = topic.get('index', 'unknown') topic_index = topic.get('index', 'unknown')
content = await self.content_generator.generate_content_for_topic(topic) _, _, content = await self.generate_content(topic)
contents[topic_index] = content contents[topic_index] = content
# 如果跳过审核,直接返回结果 # 如果跳过审核,直接返回结果