diff --git a/api/models/__init__.py b/api/models/__init__.py index bb7c2f6..28c2b2f 100644 --- a/api/models/__init__.py +++ b/api/models/__init__.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- - + """ API模型模块 """ \ No newline at end of file diff --git a/api/models/__pycache__/__init__.cpython-312.pyc b/api/models/__pycache__/__init__.cpython-312.pyc index 65a6986..f2a8207 100644 Binary files a/api/models/__pycache__/__init__.cpython-312.pyc and b/api/models/__pycache__/__init__.cpython-312.pyc differ diff --git a/api/routers/__pycache__/tweet.cpython-312.pyc b/api/routers/__pycache__/tweet.cpython-312.pyc index 6c1922d..2dfc3ca 100644 Binary files a/api/routers/__pycache__/tweet.cpython-312.pyc and b/api/routers/__pycache__/tweet.cpython-312.pyc differ diff --git a/api/routers/tweet.py b/api/routers/tweet.py index 958f8e0..2fe8913 100644 --- a/api/routers/tweet.py +++ b/api/routers/tweet.py @@ -47,7 +47,6 @@ class ContentWithPromptRequest(BaseModel): logger = logging.getLogger(__name__) router = APIRouter( - prefix="/tweet", tags=["tweet"], responses={404: {"description": "Not found"}}, ) diff --git a/api/services/__init__.py b/api/services/__init__.py index dee1c83..e38a495 100644 --- a/api/services/__init__.py +++ b/api/services/__init__.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- - + """ API服务模块 """ \ No newline at end of file diff --git a/api/services/__pycache__/__init__.cpython-312.pyc b/api/services/__pycache__/__init__.cpython-312.pyc index 0e6de6c..95178cb 100644 Binary files a/api/services/__pycache__/__init__.cpython-312.pyc and b/api/services/__pycache__/__init__.cpython-312.pyc differ diff --git a/api/services/__pycache__/tweet.cpython-312.pyc b/api/services/__pycache__/tweet.cpython-312.pyc index 1529e19..7838a58 100644 Binary files a/api/services/__pycache__/tweet.cpython-312.pyc and b/api/services/__pycache__/tweet.cpython-312.pyc differ diff --git a/api/services/tweet.py b/api/services/tweet.py index 1dd0e39..d7be025 100644 --- a/api/services/tweet.py +++ b/api/services/tweet.py @@ -17,6 +17,8 @@ from utils.file_io import OutputManager from tweet.topic_generator import TopicGenerator from tweet.content_generator import ContentGenerator from tweet.content_judger import ContentJudger +from api.services.prompt_builder import PromptBuilderService +from api.services.prompt_service import PromptService logger = logging.getLogger(__name__) @@ -42,6 +44,10 @@ class TweetService: self.content_generator = ContentGenerator(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, style: Optional[str] = None, 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.num = num_topics - # 生成选题 - topics = await self.topic_generator.generate_topics() + # 使用PromptBuilderService构建提示词 + 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: logger.error("未能生成任何选题") return str(uuid.uuid4()), [] @@ -89,8 +101,11 @@ class TweetService: topic_index = topic.get('index', 'unknown') logger.info(f"开始为选题 {topic_index} 生成内容") - # 生成内容 - content = await self.content_generator.generate_content_for_topic(topic) + # 使用PromptBuilderService构建提示词 + 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 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') 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) judge_success = judged_data.get('judge_success', False) @@ -178,7 +196,7 @@ class TweetService: contents = {} for topic in topics: 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 # 如果跳过审核,直接返回结果