#!/usr/bin/env python3 # -*- coding: utf-8 -*- """专题九 · 步骤 2 · 修改后:对齐 qwen3.6-27b 凭据 context_size=64000(不写 max_tokens)。""" from __future__ import annotations import sys import time import _bootstrap # noqa: F401 import _config as C from dify_api import Dify def main() -> int: d = Dify(C.DIFY_EMAIL, C.DIFY_PASSWORD) try: ok, _, _ = d.login() print("LOGIN ok=%s" % ok) if not ok: return 1 r = d.get( "/workspaces/current/model-providers/%s/models/credentials?model_type=llm&model=%s" % (C.OPENAI_PROVIDER, C.LLM_MODEL) ) js = r.get("json") or {} print("GET cred HTTP", r.get("code")) cur_cred = js.get("credentials") or {} cid = js.get("current_credential_id") print("current_credential_id:", cid) print("existing model_properties:", cur_cred.get("model_properties")) cred = dict(cur_cred) cred["model_properties"] = {"context_size": C.VLLM_MAX_CTX} name = js.get("current_credential_name") or "Qwen3.6-27b" r2 = d.req( "PUT", "/workspaces/current/model-providers/%s/models/credentials" % C.OPENAI_PROVIDER, body={ "model": C.LLM_MODEL, "model_type": "llm", "credential_id": cid, "credentials": cred, "name": name, }, ) print("PUT cred HTTP", r2.get("code"), (r2.get("text") or "")[:200]) time.sleep(2) r3 = d.get("/workspaces/current/models/model-types/llm") js3 = r3.get("json") or {} for p in js3.get("data", []): if p.get("provider") == C.OPENAI_PROVIDER: for m in p.get("models", []): if m.get("model") == C.LLM_MODEL: mp = m.get("model_properties") or {} print( "VERIFY model=%s status=%s context_size=%s" % (m.get("model"), m.get("status"), mp.get("context_size")) ) print("ALIGN_DONE") return 0 if r2.get("code") == "200" else 1 finally: d.close() if __name__ == "__main__": sys.exit(main())