Add z.ai/GLM provider via per-process Claude CLI env injection
Route glm:-prefixed models through the CLI/Anthropic path: ResolveModelId strips the glm: prefix, and CreateCliStartInfo activates the z.ai Anthropic-compatible endpoint (ANTHROPIC_BASE_URL/AUTH_TOKEN) only for that process when IsZaiModel matches, leaving every other request's OAuth login untouched. GLM model list is loaded through the existing model cache and exposed via /api/models/glm with a "GLM (z.ai)" optgroup in the agent form. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
e6770bb5f8
commit
0f3d658fd3
8 files changed
+83
-9
No files matched your search
@@ -71,6 +71,7 @@ public class OpenAiService
|
||||
private List<ProviderModel> _geminiModels = new List<ProviderModel>();
|
||||
private List<ProviderModel> _openaiModels = new List<ProviderModel>();
|
||||
private List<ProviderModel> _minimaxModels = new List<ProviderModel>();
|
||||
private List<ProviderModel> _glmModels = new List<ProviderModel>();
|
||||
|
||||
// Fallback-Modell-Liste für MiniMax (falls /v1/models nichts liefert).
|
||||
// Quelle: https://platform.minimax.io/docs/api-reference/api-overview
|
||||
@@ -126,6 +127,7 @@ public class OpenAiService
|
||||
_geminiModels = cache.ContainsKey("gemini") ? cache["gemini"] : new List<ProviderModel>();
|
||||
_openaiModels = cache.ContainsKey("openai") ? cache["openai"] : new List<ProviderModel>();
|
||||
_minimaxModels = cache.ContainsKey("minimax") ? cache["minimax"] : new List<ProviderModel>();
|
||||
_glmModels = cache.ContainsKey("glm") ? cache["glm"] : new List<ProviderModel>();
|
||||
// Falls der Cache älter als die MiniMax-Integration ist oder leer ist:
|
||||
// statische Fallback-Liste verwenden, damit das Dropdown nicht leer bleibt.
|
||||
if (_minimaxModels.Count == 0)
|
||||
@@ -195,6 +197,13 @@ public class OpenAiService
|
||||
Console.WriteLine($"[OpenAiService] MinimaxApiKey nicht konfiguriert – nutze Fallback-Liste ({_minimaxModels.Count} Modelle).");
|
||||
}
|
||||
|
||||
// z.ai / GLM: Key aus Settings (ZaiApiKey). OpenAI-kompatibler /models-Endpoint von z.ai.
|
||||
var zaiKey = _settings.Get("ZaiApiKey");
|
||||
if (!string.IsNullOrEmpty(zaiKey))
|
||||
_glmModels = await FetchModels("https://api.z.ai/api/paas/v4/models", "GLM (z.ai)", zaiKey);
|
||||
else
|
||||
Console.WriteLine("[OpenAiService] ZaiApiKey nicht konfiguriert – GLM-Modelle nicht geladen.");
|
||||
|
||||
// Cache speichern
|
||||
try
|
||||
{
|
||||
@@ -204,7 +213,8 @@ public class OpenAiService
|
||||
["pollinations"] = _pollinationsModels,
|
||||
["gemini"] = _geminiModels,
|
||||
["openai"] = _openaiModels,
|
||||
["minimax"] = _minimaxModels
|
||||
["minimax"] = _minimaxModels,
|
||||
["glm"] = _glmModels
|
||||
};
|
||||
var json = JsonSerializer.Serialize(cache, new JsonSerializerOptions { WriteIndented = true });
|
||||
await File.WriteAllTextAsync(_cacheFile, json);
|
||||
@@ -264,6 +274,7 @@ public class OpenAiService
|
||||
public List<ProviderModel> GetGeminiModels() => _geminiModels;
|
||||
public List<ProviderModel> GetOpenAiModels() => _openaiModels;
|
||||
public List<ProviderModel> GetMinimaxModels() => _minimaxModels;
|
||||
public List<ProviderModel> GetGlmModels() => _glmModels;
|
||||
|
||||
/// <summary>
|
||||
/// Gibt den Provider und das eigentliche Modell-ID aus einem kombinierten Model-String zurück.
|
||||
|
||||
Reference in new issue
Block a user