#!/usr/bin/env python3 """记录已经完成的模型注册。知识库向量走 Xinference,对话走 New-API 的 dify-gateway。 重复执行会碰到「模型已存在」。看到 Can't add same credential 可以停。 不要再创建第二把名为 dify-gateway 的令牌。 """ import json import os import urllib.request DIFY = os.environ.get("DIFY", "http://127.0.0.1:8088") XINFERENCE = "http://172.17.0.1:9997" NEW_API = "http://172.17.0.1:3000/v1" GATEWAY_KEY = os.environ["DIFY_GATEWAY_KEY"] def post(url, body, headers): request = urllib.request.Request(url, data=json.dumps(body).encode(), method="POST") request.add_header("Content-Type", "application/json") for key, value in headers.items(): request.add_header(key, value) with urllib.request.urlopen(request, timeout=60) as resp: return resp.status llm = { "model": "qwen3.6-27b", "model_type": "llm", "credentials": { "mode": "chat", "context_size": "65536", "max_tokens_to_sample": "8192", "function_calling_type": "tool_call", "stream_function_calling": "supported", "display_name": "qwen3.6-27b", "endpoint_url": NEW_API, "api_key": GATEWAY_KEY, }, } embedding = { "model": "bge-m3", "model_type": "text-embedding", "credentials": { "server_url": XINFERENCE, "model_uid": "bge-m3", }, } print("llm payload model", llm["model"], "endpoint", NEW_API) print("embedding payload model", embedding["model"], "server", XINFERENCE) print("status example", "credentials are saved with POST /console/api/workspaces/current/model-providers//models/credentials")