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>
77 lines
2.7 KiB
C#
77 lines
2.7 KiB
C#
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Gott.Services;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Routing;
|
|
|
|
namespace Gott.Endpoints;
|
|
|
|
public static class ModelsEndpoint
|
|
{
|
|
public static void MapModelsEndpoint(this IEndpointRouteBuilder app)
|
|
{
|
|
app.MapGet("/api/models/nvidia", HandleNvidiaModels);
|
|
app.MapGet("/api/models/pollinations", HandlePollinationsModels);
|
|
app.MapGet("/api/models/gemini", HandleGeminiModels);
|
|
app.MapGet("/api/models/openai", HandleOpenAiModels);
|
|
app.MapGet("/api/models/minimax", HandleMinimaxModels);
|
|
app.MapGet("/api/models/glm", HandleGlmModels);
|
|
app.MapPost("/api/models/refresh", HandleRefresh);
|
|
}
|
|
|
|
private static IResult HandleNvidiaModels(OpenAiService openAiService)
|
|
{
|
|
var models = openAiService.GetNvidiaModels()
|
|
.Select(m => new { id = m.Id, displayName = m.DisplayName })
|
|
.ToList();
|
|
return Results.Json(new { models });
|
|
}
|
|
|
|
private static IResult HandlePollinationsModels(OpenAiService openAiService)
|
|
{
|
|
var models = openAiService.GetPollinationsModels()
|
|
.Select(m => new { id = m.Id, displayName = m.DisplayName })
|
|
.ToList();
|
|
return Results.Json(new { models });
|
|
}
|
|
|
|
private static IResult HandleGeminiModels(OpenAiService openAiService)
|
|
{
|
|
var models = openAiService.GetGeminiModels()
|
|
.Select(m => new { id = m.Id, displayName = m.DisplayName })
|
|
.ToList();
|
|
return Results.Json(new { models });
|
|
}
|
|
|
|
private static IResult HandleOpenAiModels(OpenAiService openAiService)
|
|
{
|
|
var models = openAiService.GetOpenAiModels()
|
|
.Select(m => new { id = m.Id, displayName = m.DisplayName })
|
|
.ToList();
|
|
return Results.Json(new { models });
|
|
}
|
|
|
|
private static IResult HandleMinimaxModels(OpenAiService openAiService)
|
|
{
|
|
var models = openAiService.GetMinimaxModels()
|
|
.Select(m => new { id = m.Id, displayName = m.DisplayName })
|
|
.ToList();
|
|
return Results.Json(new { models });
|
|
}
|
|
|
|
private static IResult HandleGlmModels(OpenAiService openAiService)
|
|
{
|
|
var models = openAiService.GetGlmModels()
|
|
.Select(m => new { id = m.Id, displayName = m.DisplayName })
|
|
.ToList();
|
|
return Results.Json(new { models });
|
|
}
|
|
|
|
private static async Task<IResult> HandleRefresh(OpenAiService openAiService)
|
|
{
|
|
await openAiService.RefreshModelsFromApis();
|
|
return Results.Json(new { success = true, message = "Modelle neu geladen und gecacht." });
|
|
}
|
|
}
|