2 Commits

Author SHA1 Message Date
z3st
d6e9f2e7a0 fix: page_size limit 50 for ModelScope API 2026-07-22 01:13:26 +08:00
z3st
821edbc8f5 debug: add logging to search function 2026-07-22 01:08:03 +08:00

10
main.py
View File

@@ -121,12 +121,12 @@ def init_db():
# ModelScope 搜索
# ============================================================
def search_models(keyword: str, limit: int = 100) -> list:
def search_models(keyword: str, limit: int = 50) -> list:
"""从 ModelScope 搜索模型"""
url = "https://modelscope.cn/openapi/v1/models"
params = {
'search': keyword,
'page_size': limit,
'page_size': min(limit, 50), # API 上限 50
'page_number': 1,
'sort': 'downloads',
}
@@ -135,7 +135,11 @@ def search_models(keyword: str, limit: int = 100) -> list:
headers={'User-Agent': 'Mozilla/5.0'})
data = resp.json()
if data.get('success'):
return data.get('data', {}).get('models', [])
models = data.get('data', {}).get('models', [])
log(f" 搜索 [{keyword}]: status={resp.status_code} models={len(models)}")
return models
else:
log(f" 搜索 [{keyword}]: success=false, data={str(data)[:200]}")
except Exception as e:
log(f" 搜索失败 [{keyword}]: {e}")
return []