v4.1: 修 models schema (baseUrl 不是 baseURL, models 为对象数组含 id/name/api/cost/contextWindow)

This commit is contained in:
2026-08-10 08:16:18 +00:00
parent a244a5a425
commit a946725bc7
+38 -5
View File
@@ -768,17 +768,30 @@ if provider == "openai-compat" and (baseurl or apikey or model):
print("WARN: models.providers.openai-compat unexpected type; skipped") print("WARN: models.providers.openai-compat unexpected type; skipped")
else: else:
if baseurl: if baseurl:
p["baseURL"] = baseurl p["baseUrl"] = baseurl
changed.append("models.providers.openai-compat.baseURL") p.pop("baseURL", None)
changed.append("models.providers.openai-compat.baseUrl")
if apikey: if apikey:
p["apiKey"] = apikey p["apiKey"] = apikey
changed.append("models.providers.openai-compat.apiKey") changed.append("models.providers.openai-compat.apiKey")
p.setdefault("api", "openai-completions")
p.setdefault("timeoutSeconds", 300)
if model: if model:
models = p.get("models") models = p.get("models")
if not isinstance(models, list): if not isinstance(models, list):
models = [] models = []
if model not in models: models = [m for m in models if isinstance(m, dict)]
models.append(model) if not any(m.get("id") == model for m in models):
models.append({
"id": model,
"name": model,
"api": "openai-completions",
"reasoning": False,
"input": ["text"],
"cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0},
"contextWindow": 128000,
"maxTokens": 8192,
})
p["models"] = models p["models"] = models
changed.append("models.providers.openai-compat.models") changed.append("models.providers.openai-compat.models")
agents_root = node(cfg, "agents") agents_root = node(cfg, "agents")
@@ -796,6 +809,26 @@ elif provider == "anthropic" and (apikey or model):
if apikey: if apikey:
p["apiKey"] = apikey p["apiKey"] = apikey
changed.append("models.providers.anthropic.apiKey") changed.append("models.providers.anthropic.apiKey")
p.setdefault("api", "anthropic-messages")
p.setdefault("timeoutSeconds", 300)
if model:
ams = p.get("models")
if not isinstance(ams, list):
ams = []
ams = [m for m in ams if isinstance(m, dict)]
if not any(m.get("id") == model for m in ams):
ams.append({
"id": model,
"name": model,
"api": "anthropic-messages",
"reasoning": True,
"input": ["text", "image"],
"cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0},
"contextWindow": 200000,
"maxTokens": 8192,
})
p["models"] = ams
changed.append("models.providers.anthropic.models")
if model: if model:
agents_root = node(cfg, "agents") agents_root = node(cfg, "agents")
adef = node(agents_root, "defaults") if agents_root is not None else None adef = node(agents_root, "defaults") if agents_root is not None else None
@@ -1058,7 +1091,7 @@ if provs:
print(" 模型 Provider") print(" 模型 Provider")
for name,p in provs.items(): for name,p in provs.items():
if not isinstance(p,dict): continue if not isinstance(p,dict): continue
print(f" [{name}] baseURL={p.get('baseURL','(默认)')} key={mask(p.get('apiKey',''))}") print(f" [{name}] baseUrl={p.get('baseUrl',p.get('baseURL','(默认)'))} key={mask(p.get('apiKey',''))}")
ms=p.get("models") ms=p.get("models")
if isinstance(ms,list) and ms: print(f" models={', '.join(map(str,ms[:5]))}") if isinstance(ms,list) and ms: print(f" models={', '.join(map(str,ms[:5]))}")
else: else: