LPC/test_api.py

61 lines
2.4 KiB
Python
Raw Normal View History

2026-01-08 22:23:16 +08:00
import logging
from services.deepseek_service import deepseek_service
# 设置日志
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
def test_feedback_generation():
logger.info("开始测试反馈生成功能")
# 准备测试数据
conversation_history = [
{"role": "assistant", "content": "你好!我是面试官,现在开始针对前端开发岗位的面试。请做一下自我介绍。"},
{"role": "user", "content": "你好我叫张三有3年前端开发经验熟悉React、Vue等框架。"},
{"role": "assistant", "content": "请介绍一下你最印象深刻的项目。"},
{"role": "user", "content": "我在之前的公司负责开发了一个电商网站使用React框架优化了页面加载速度提升了用户体验。"}
]
system_prompt = """作为一位专业的面试评估专家,请对整场面试进行全面评估。
请提供
1. 整体表现评分0-100和评级优秀/良好/一般/需改进
2. 各轮回答的详细分析针对每个问题和回答给出具体评价
3. strengths优势- 列出至少3点
4. areas_for_improvement需要改进的方面- 列出至少3点
5. 具体的准备建议针对改进点给出可操作的建议
请用中文回复格式清晰结构化避免过于笼统的描述"""
user_prompt = f"请分析以下针对前端开发岗位的面试对话并给出综合反馈:\n\n" + "\n\n".join([
f"{'面试官' if msg['role'] == 'assistant' else '候选人'}{msg['content']}"
for msg in conversation_history
])
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt}
]
try:
logger.info("准备调用DeepSeek API")
response = deepseek_service._call_api(messages)
logger.info("API调用成功")
logger.debug(f"API响应{response}")
feedback = response["choices"][0]["message"]["content"]
logger.info("生成的反馈内容:")
logger.info(feedback)
return True
except Exception as e:
logger.error(f"API调用失败{str(e)}", exc_info=True)
return False
if __name__ == "__main__":
success = test_feedback_generation()
if success:
logger.info("测试成功")
else:
logger.info("测试失败")