fix: correct ModelScope API endpoint and field names
This commit is contained in:
24
main.py
24
main.py
@@ -123,20 +123,22 @@ def init_db():
|
|||||||
|
|
||||||
def search_models(keyword: str, limit: int = 100) -> list:
|
def search_models(keyword: str, limit: int = 100) -> list:
|
||||||
"""从 ModelScope 搜索模型"""
|
"""从 ModelScope 搜索模型"""
|
||||||
url = f"{MODELSCOPE_API}/models"
|
url = "https://modelscope.cn/openapi/v1/models"
|
||||||
params = {
|
params = {
|
||||||
'Query': keyword,
|
'search': keyword,
|
||||||
'PageSize': limit,
|
'page_size': limit,
|
||||||
'SortBy': 'GITHUB_SCORE',
|
'page_number': 1,
|
||||||
|
'sort': 'downloads',
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
resp = requests.get(url, params=params, timeout=15)
|
resp = requests.get(url, params=params, timeout=20,
|
||||||
|
headers={'User-Agent': 'Mozilla/5.0'})
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
models = data.get('Data', {}).get('Models', [])
|
if data.get('success'):
|
||||||
return models
|
return data.get('data', {}).get('models', [])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log(f" 搜索失败 [{keyword}]: {e}")
|
log(f" 搜索失败 [{keyword}]: {e}")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def check_architecture(model_id: str) -> tuple:
|
def check_architecture(model_id: str) -> tuple:
|
||||||
@@ -367,16 +369,16 @@ def run_pipeline(gpus: list = None, submit_limit: int = 30):
|
|||||||
for kw in SEARCH_KEYWORDS:
|
for kw in SEARCH_KEYWORDS:
|
||||||
models = search_models(kw, limit=100)
|
models = search_models(kw, limit=100)
|
||||||
for m in models:
|
for m in models:
|
||||||
mid = m.get('ModelId', m.get('Name', ''))
|
mid = m.get('id', '')
|
||||||
if mid and mid not in seen:
|
if mid and mid not in seen:
|
||||||
seen.add(mid)
|
seen.add(mid)
|
||||||
downloads = m.get('Downloads', 0)
|
downloads = m.get('downloads', 0)
|
||||||
if downloads >= 50:
|
if downloads >= 50:
|
||||||
all_models.append({
|
all_models.append({
|
||||||
'model_id': mid,
|
'model_id': mid,
|
||||||
'url': f"https://modelscope.cn/{mid}",
|
'url': f"https://modelscope.cn/{mid}",
|
||||||
'downloads': downloads,
|
'downloads': downloads,
|
||||||
'params': m.get('Parameters', ''),
|
'params': m.get('params', ''),
|
||||||
'category': 'quantized' if 'GGUF' in mid.upper() else 'standard',
|
'category': 'quantized' if 'GGUF' in mid.upper() else 'standard',
|
||||||
})
|
})
|
||||||
time.sleep(0.3)
|
time.sleep(0.3)
|
||||||
|
|||||||
Reference in New Issue
Block a user