From 761e74ff82b69c0219582de56c0cb26db5009e41 Mon Sep 17 00:00:00 2001 From: z3st Date: Tue, 21 Jul 2026 20:31:23 +0800 Subject: [PATCH] feat: auto-run connectivity test on startup, print results to logs --- main.py | 93 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 78 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index 7a13b90..b1bd8c9 100644 --- a/main.py +++ b/main.py @@ -653,22 +653,85 @@ def main(): log(f"STRATEGY_ID: {STRATEGY_ID}") log(f"GPU: {', '.join(GPU_CONFIGS.keys())}") - # 启动后自动执行一次提交流程(暂时禁用,用于测试连通性) - # def _auto_run(): - # time.sleep(3) - # 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 + # 启动后自动运行连通性测试 + def _startup_test(): + time.sleep(2) + log("=" * 50) + log("连通性测试开始") + log("=" * 50) - # threading.Thread(target=_auto_run, daemon=True).start() + # 1. ModelScope 搜索 + try: + resp = requests.get( + 'https://modelscope.cn/openapi/v1/models', + params={'search': 'qwen', 'page_size': 2, 'sort': 'downloads'}, + timeout=10, headers={'User-Agent': 'Mozilla/5.0'} + ) + if resp.status_code == 200: + data = resp.json() + models = data.get('data', {}).get('models', []) + log(f"[ModelScope搜索] ✅ status={resp.status_code} models={len(models)}") + for m in models[:2]: + log(f" {m.get('id')} downloads={m.get('downloads')}") + else: + log(f"[ModelScope搜索] ❌ status={resp.status_code} body={resp.text[:100]}") + except Exception as e: + log(f"[ModelScope搜索] ❌ error={e}") + + # 2. ModelScope config.json + try: + resp = requests.get( + 'https://modelscope.cn/api/v1/models/Qwen/Qwen3-8B/repo?Revision=master&FilePath=config.json', + timeout=10 + ) + if resp.status_code == 200: + cfg = resp.json() + log(f"[ModelScope配置] ✅ arch={cfg.get('architectures')} type={cfg.get('model_type')}") + else: + log(f"[ModelScope配置] ❌ status={resp.status_code}") + except Exception as e: + log(f"[ModelScope配置] ❌ error={e}") + + # 3. ModelHub 查询 + try: + token = list(ACCOUNTS.values())[0] + resp = requests.get( + 'https://modelhub.org.cn/api/adapt/task/page', + headers={'Xc-Token': token, 'Accept': 'application/json'}, + params={'current': 1, 'pageSize': 1, 'onlyMine': 'true'}, + timeout=10 + ) + data = resp.json() + if data.get('code') == 0: + log(f"[ModelHub查询] ✅ total={data['data'].get('total')}") + else: + log(f"[ModelHub查询] ❌ code={data.get('code')} msg={data.get('message','')[:80]}") + except Exception as e: + log(f"[ModelHub查询] ❌ error={e}") + + # 4. ModelHub 提交 + try: + token = list(ACCOUNTS.values())[0] + resp = requests.post( + 'https://modelhub.org.cn/api/adapt/task/add', + headers={'Xc-Token': token, 'Accept': 'application/json', 'Content-Type': 'application/json'}, + json={ + 'modelAddress': 'https://www.modelscope.cn/models/Qwen/Qwen3-8B', + 'taskType': 'text-generation', 'targetGpu': 'Kunlunxin_p-800', + 'framework': 'vllm', 'strategyId': STRATEGY_ID, + 'configParams': 'framework: vllm\n', + }, timeout=10 + ) + data = resp.json() + log(f"[ModelHub提交] code={data.get('code')} msg={data.get('message','')[:80]}") + except Exception as e: + log(f"[ModelHub提交] ❌ error={e}") + + log("=" * 50) + log("连通性测试完成,请查看上方结果") + log("=" * 50) + + threading.Thread(target=_startup_test, daemon=True).start() while not shutdown_requested: server.handle_request()