feat: implement streaming support for chat and enhance safety review process
- Updated .env.example to include API key placeholder and configuration instructions. - Refactored main.py to support streaming responses from the LLM, improving user experience during chat interactions. - Enhanced LLMClient to include methods for streaming chat and collecting responses. - Modified safety review process to pass static analysis warnings to the LLM for better code safety evaluation. - Improved UI components in chat_view.py to handle streaming messages effectively.
This commit is contained in:
@@ -155,17 +155,26 @@ CODE_GENERATION_USER = """执行计划:
|
||||
# 安全审查 Prompt
|
||||
# ========================================
|
||||
|
||||
SAFETY_REVIEW_SYSTEM = """你是一个代码安全审查员。检查代码是否符合安全规范。
|
||||
SAFETY_REVIEW_SYSTEM = """你是一个代码安全审查员。你的任务是判断代码是否安全可执行。
|
||||
|
||||
检查项:
|
||||
1. 是否只操作 workspace/input 和 workspace/output 目录
|
||||
2. 是否有网络请求代码(requests, socket, urllib)
|
||||
3. 是否有危险的文件删除操作(os.remove, shutil.rmtree)
|
||||
4. 是否有执行外部命令的代码(subprocess, os.system)
|
||||
5. 代码逻辑是否与用户需求一致
|
||||
【核心原则】
|
||||
- 代码只应操作 workspace/input(读取)和 workspace/output(写入)
|
||||
- 不应有网络请求、执行系统命令等危险操作
|
||||
- 代码逻辑应与用户需求一致
|
||||
|
||||
【审查要点】
|
||||
1. 路径安全:是否只访问 workspace 目录?是否有路径遍历风险?
|
||||
2. 网络安全:是否有网络请求?(如果用户明确要求下载等网络操作,需拒绝)
|
||||
3. 文件安全:删除操作是否合理?(如果是清理临时文件可以接受,删除用户文件需拒绝)
|
||||
4. 逻辑一致:代码是否实现了用户的需求?
|
||||
|
||||
【判断标准】
|
||||
- 如果代码安全且符合需求 → pass: true
|
||||
- 如果有安全风险或不符合需求 → pass: false
|
||||
- 对于边界情况,倾向于通过(用户已确认执行)
|
||||
|
||||
输出JSON格式:
|
||||
{"pass": true或false, "reason": "中文审查结论,一句话"}"""
|
||||
{"pass": true或false, "reason": "中文审查结论,简洁说明"}"""
|
||||
|
||||
SAFETY_REVIEW_USER = """用户需求:{user_input}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user