#!/usr/bin/env python3 # -*- coding: utf-8 -*- """专题一 · 步骤 5:验证 vLLM 可达且 Dify LLM 列表中 qwen active。""" from __future__ import annotations import json import sys import _bootstrap # noqa: F401 import _config as C from dify_api import Dify, pp def main() -> int: d = Dify(C.DIFY_EMAIL, C.DIFY_PASSWORD) try: print("=== 1/2 从 207 curl vLLM /v1/models ===") out, err = d.sh( "curl -s -m 10 -H 'Authorization: Bearer %s' %s/models" % (C.VLLM_KEY, C.VLLM_BASE) ) print(out or err) try: data = json.loads(out) ids = [m.get("id") for m in data.get("data", [])] print("model ids:", ids) if C.QWEN_MODEL not in ids: print("[WARN] vLLM 列表无", C.QWEN_MODEL) except Exception: pass print("\n=== 2/2 Dify model-types/llm ===") d.login() r = d.get("/workspaces/current/models/model-types/llm") pp("llm list", r) found = False for p in (r.get("json") or {}).get("data") or []: if p.get("provider") != C.OPENAI_PROVIDER: continue for m in p.get("models") or []: if m.get("model") == C.QWEN_MODEL: found = True print("qwen status:", m.get("status"), "props:", m.get("model_properties")) if not found: print("[WARN] Dify LLM 列表未找到", C.QWEN_MODEL) return 1 return 0 finally: d.close() if __name__ == "__main__": sys.exit(main())