fix: 修复AI任务生成和配置文件缺失问题

问题1:GET /api/tasks返回404错误
- 原因:缺少config.json配置文件
- 解决方案:从config.json.example复制创建config.json

问题2:'NoneType' object has no attribute 'strip'错误
- 原因:src/prompt_utils.py中AI返回的content可能为None,直接调用.strip()导致错误
- 解决方案:添加None值检查,提供更清晰的错误信息

修复内容:
- 添加config.json配置文件以支持任务管理
- 在prompt_utils.py中添加AI响应内容的空值检查
- 当AI返回空内容时提供更有意义的错误提示

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
triotea
2025-08-20 17:35:33 +08:00
parent 8f4de72b3f
commit 8e3709f209
2 changed files with 46 additions and 0 deletions

41
config.json Normal file
View File

@@ -0,0 +1,41 @@
[
{
"task_name": "MacBook Air M1",
"enabled": true,
"keyword": "macbook air m1",
"max_pages": 5,
"personal_only": true,
"min_price": "3000",
"max_price": "5000",
"cron": "3 12 * * *",
"ai_prompt_base_file": "prompts/base_prompt.txt",
"ai_prompt_criteria_file": "prompts/macbook_criteria.txt",
"is_running": false
},
{
"task_name": "DJI Mini 3 Pro",
"enabled": true,
"keyword": "mini 3 pro",
"max_pages": 3,
"personal_only": true,
"ai_prompt_base_file": "prompts/base_prompt.txt",
"ai_prompt_criteria_file": "prompts/dji_mini3_criteria.txt",
"min_price": "3500",
"max_price": "4500",
"cron": "",
"is_running": false
},
{
"task_name": "婴儿车",
"enabled": false,
"keyword": "babycare 婴儿车",
"max_pages": 3,
"personal_only": true,
"min_price": "500",
"max_price": "1000",
"cron": "",
"ai_prompt_base_file": "prompts/base_prompt.txt",
"ai_prompt_criteria_file": "prompts/babycare_婴儿车_criteria.txt",
"is_running": false
}
]

View File

@@ -65,6 +65,11 @@ async def generate_criteria(user_description: str, reference_file_path: str) ->
)
generated_text = response.choices[0].message.content
print("AI已成功生成内容。")
# 处理content可能为None的情况
if generated_text is None:
raise RuntimeError("AI返回的内容为空请检查模型配置或重试。")
return generated_text.strip()
except Exception as e:
print(f"调用 OpenAI API 时出错: {e}")