2 Commits

Author SHA1 Message Date
z3st
3975a3370a fix: correct ModelScope API endpoint and field names 2026-07-21 19:31:35 +08:00
z3st
7313f8da67 feat: auto-run pipeline on startup 2026-07-21 19:09:41 +08:00

41
main.py
View File

@@ -123,20 +123,22 @@ def init_db():
def search_models(keyword: str, limit: int = 100) -> list:
"""从 ModelScope 搜索模型"""
url = f"{MODELSCOPE_API}/models"
url = "https://modelscope.cn/openapi/v1/models"
params = {
'Query': keyword,
'PageSize': limit,
'SortBy': 'GITHUB_SCORE',
'search': keyword,
'page_size': limit,
'page_number': 1,
'sort': 'downloads',
}
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()
models = data.get('Data', {}).get('Models', [])
return models
if data.get('success'):
return data.get('data', {}).get('models', [])
except Exception as e:
log(f" 搜索失败 [{keyword}]: {e}")
return []
return []
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:
models = search_models(kw, limit=100)
for m in models:
mid = m.get('ModelId', m.get('Name', ''))
mid = m.get('id', '')
if mid and mid not in seen:
seen.add(mid)
downloads = m.get('Downloads', 0)
downloads = m.get('downloads', 0)
if downloads >= 50:
all_models.append({
'model_id': mid,
'url': f"https://modelscope.cn/{mid}",
'downloads': downloads,
'params': m.get('Parameters', ''),
'params': m.get('params', ''),
'category': 'quantized' if 'GGUF' in mid.upper() else 'standard',
})
time.sleep(0.3)
@@ -570,6 +572,23 @@ def main():
log(f"STRATEGY_ID: {STRATEGY_ID}")
log(f"GPU: {', '.join(GPU_CONFIGS.keys())}")
# 启动后自动执行一次提交流程
def _auto_run():
time.sleep(3) # 等 HTTP 服务就绪
log("自动触发提交流程...")
try:
state['running'] = True
state['last_run'] = datetime.now().isoformat()
count = run_pipeline(submit_limit=30)
state['last_result'] = {'submitted': count, 'success': True}
except Exception as e:
log(f"流程异常: {traceback.format_exc()}")
state['last_result'] = {'error': str(e), 'success': False}
finally:
state['running'] = False
threading.Thread(target=_auto_run, daemon=True).start()
while not shutdown_requested:
server.handle_request()