ShopTRAINING/test/verify_api_fix.py
2025-07-02 11:05:23 +08:00

65 lines
2.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
验证API修复是否生效
"""
import urllib.request
import json
import time
def verify_api_fix():
try:
print("=== 验证API修复效果 ===")
print("注意需要重启API服务器才能看到修复效果")
print()
url = 'http://localhost:5000/api/models'
with urllib.request.urlopen(url) as response:
data = response.read().decode('utf-8')
result = json.loads(data)
print(f"API响应状态: {response.status}")
models = result.get('data', [])
print(f"模型数量: {len(models)}")
if models:
model = models[0]
filename = model.get('filename', 'MISSING')
model_id = model.get('model_id', 'MISSING')
metrics = model.get('metrics', {})
print(f"\n第一个模型检查:")
print(f" filename: '{filename}'")
print(f" model_id: '{model_id}'")
print(f" metrics: {metrics}")
# 检查修复状态
fixes_applied = []
if filename != 'MISSING' and filename:
fixes_applied.append("filename字段已返回")
if model_id != 'MISSING' and model_id:
fixes_applied.append("model_id字段已生成")
if fixes_applied:
print(f"\n✓ 修复成功:")
for fix in fixes_applied:
print(f" - {fix}")
print("\n前端应该能正常:")
print(" - 显示模型详情按钮")
print(" - 响应删除操作")
print(" - 显示评估指标 (如果模型有metrics)")
return True
else:
print(f"\n✗ 修复未生效请重启API服务器:")
print(" uv run ./server/api.py")
return False
else:
print("✗ 没有找到模型")
return False
except Exception as e:
print(f"验证失败: {e}")
print("请确保API服务器正在运行")
return False
if __name__ == "__main__":
verify_api_fix()