59 lines
2.5 KiB
Python
59 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
详细测试模型API返回的数据
|
|
"""
|
|
import urllib.request
|
|
import json
|
|
|
|
def test_models_detailed():
|
|
try:
|
|
print("=== 测试 /api/models 端点 ===")
|
|
with urllib.request.urlopen('http://localhost:5000/api/models') as response:
|
|
data = response.read().decode('utf-8')
|
|
result = json.loads(data)
|
|
|
|
print(f"状态码: {response.status}")
|
|
print(f"总模型数: {result.get('total', 0)}")
|
|
|
|
models = result.get('data', [])
|
|
for i, model in enumerate(models, 1):
|
|
print(f"\n--- 模型 {i} ---")
|
|
print(f"model_id: '{model.get('model_id', 'EMPTY')}'")
|
|
print(f"product_id: '{model.get('product_id', 'EMPTY')}'")
|
|
print(f"model_type: '{model.get('model_type', 'EMPTY')}'")
|
|
print(f"version: '{model.get('version', 'EMPTY')}'")
|
|
|
|
# 检查关键问题字段
|
|
metrics = model.get('metrics', {})
|
|
print(f"metrics keys: {list(metrics.keys()) if metrics else 'EMPTY DICT'}")
|
|
|
|
filename = model.get('filename', '')
|
|
print(f"filename: '{filename}'")
|
|
|
|
# 模型ID是否为空
|
|
if not model.get('model_id'):
|
|
print("ERROR: model_id为空 - 这会导致详情和删除按钮无响应!")
|
|
else:
|
|
print("OK: model_id正常")
|
|
|
|
# 测试单个模型详情API (如果有model_id)
|
|
if models and models[0].get('model_id'):
|
|
model_id = models[0]['model_id']
|
|
print(f"\n=== 测试单个模型详情: {model_id} ===")
|
|
|
|
try:
|
|
detail_url = f'http://localhost:5000/api/models/{model_id}'
|
|
with urllib.request.urlopen(detail_url) as response:
|
|
detail_data = response.read().decode('utf-8')
|
|
detail_result = json.loads(detail_data)
|
|
print(f"详情API状态码: {response.status}")
|
|
print(f"详情API返回: {json.dumps(detail_result, indent=2, ensure_ascii=False)}")
|
|
except Exception as e:
|
|
print(f"详情API测试失败: {e}")
|
|
|
|
except Exception as e:
|
|
print(f"API测试失败: {e}")
|
|
print("请确保API服务器正在运行: uv run ./server/api.py")
|
|
|
|
if __name__ == "__main__":
|
|
test_models_detailed() |