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

52 lines
1.4 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 python
"""
简单的模型测试
"""
import sys
import os
import json
# 设置路径
current_dir = os.path.dirname(os.path.abspath(__file__))
server_dir = os.path.join(current_dir, 'server')
os.chdir(server_dir)
sys.path.insert(0, server_dir)
print(f"工作目录: {os.getcwd()}")
try:
# 导入模型管理器
from utils.model_manager import model_manager
print(f"模型目录: {model_manager.model_dir}")
# 获取模型
models = model_manager.list_models()
print(f"原始模型数量: {len(models)}")
if models:
model = models[0]
print("第一个模型原始数据:")
for key, value in model.items():
print(f" {key}: {value} ({type(value)})")
# 测试JSON序列化
try:
json_str = json.dumps(model, ensure_ascii=False, default=str)
print("JSON序列化成功")
except Exception as e:
print(f"JSON序列化失败: {e}")
# 找出有问题的字段
for key, value in model.items():
try:
json.dumps({key: value}, default=str)
except Exception as field_error:
print(f" 问题字段 {key}: {field_error}")
print("\n=== 成功模型管理器在API环境下工作正常 ===")
except Exception as e:
print(f"错误: {e}")
import traceback
traceback.print_exc()