33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
|
|
import requests
|
|||
|
|
import json
|
|||
|
|
|
|||
|
|
# API测试脚本
|
|||
|
|
BASE_URL = 'http://127.0.0.1:5000'
|
|||
|
|
TEST_HEADER_URL = 'http://127.0.0.1:5001'
|
|||
|
|
API_KEY = 'sk-0944c102849e45d9ab3f24d5169de289'
|
|||
|
|
|
|||
|
|
# 设置请求头
|
|||
|
|
headers = {
|
|||
|
|
'Content-Type': 'application/json',
|
|||
|
|
'X-API-Key': API_KEY
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try:
|
|||
|
|
print("=== 测试Header调试端点 ===")
|
|||
|
|
response = requests.get(f'{TEST_HEADER_URL}/test_headers', headers=headers)
|
|||
|
|
print(f"状态码: {response.status_code}")
|
|||
|
|
print(f"响应内容: {json.dumps(response.json(), ensure_ascii=False, indent=2)}")
|
|||
|
|
|
|||
|
|
# 测试分析回答API
|
|||
|
|
print("\n=== 测试分析回答API ===")
|
|||
|
|
analyze_data = {
|
|||
|
|
'question_id': 1,
|
|||
|
|
'answer': '我是一名有5年经验的软件工程师,主要从事Python开发工作。'
|
|||
|
|
}
|
|||
|
|
response = requests.post(f'{BASE_URL}/analyze_answer', headers=headers, json=analyze_data)
|
|||
|
|
print(f"状态码: {response.status_code}")
|
|||
|
|
print(f"响应内容: {json.dumps(response.json(), ensure_ascii=False, indent=2)}")
|
|||
|
|
|
|||
|
|
except Exception as e:
|
|||
|
|
print(f"测试失败: {str(e)}")
|