From 09d4e2f1a1bc206c80d8d3287d070c70ec7fd63d Mon Sep 17 00:00:00 2001
From: chunhualin1 <chunhualin1@lenovo.com>
Date: 星期五, 14 八月 2026 20:00:52 +0800
Subject: [PATCH] Merge branch 'master' of http://git.linmoli.cn/r/Moli.Desktop
---
src/Moli.Desktop/Llm/LlmOpenAiUrls.cs | 90 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 90 insertions(+), 0 deletions(-)
diff --git a/src/Moli.Desktop/Llm/LlmOpenAiUrls.cs b/src/Moli.Desktop/Llm/LlmOpenAiUrls.cs
new file mode 100644
index 0000000..ec4ea38
--- /dev/null
+++ b/src/Moli.Desktop/Llm/LlmOpenAiUrls.cs
@@ -0,0 +1,90 @@
+namespace Moli.Desktop.Llm;
+
+public static class LlmOpenAiUrls
+{
+ public const string ChatCompletionsPath = "/chat/completions";
+ public const string ModelsPath = "/models";
+
+ public static string? ResolveBaseUrl(string? baseUrl, string? endpoint)
+ {
+ var raw = FirstNonEmpty(baseUrl, endpoint);
+ if (raw is null)
+ {
+ return null;
+ }
+
+ raw = raw.Trim().TrimEnd('/');
+ if (raw.EndsWith(ChatCompletionsPath, StringComparison.OrdinalIgnoreCase))
+ {
+ raw = raw[..^ChatCompletionsPath.Length].TrimEnd('/');
+ }
+
+ return string.IsNullOrWhiteSpace(raw) ? null : raw;
+ }
+
+ public static string? ToChatCompletionsUrl(string? baseUrl, string? endpoint)
+ {
+ var resolved = ResolveBaseUrl(baseUrl, endpoint);
+ return resolved is null ? null : resolved + ChatCompletionsPath;
+ }
+
+ public static string? ToModelsUrl(string? baseUrl, string? endpoint = null)
+ {
+ var resolved = ResolveBaseUrl(baseUrl, endpoint);
+ return resolved is null ? null : resolved + ModelsPath;
+ }
+
+ public static bool IsAbsoluteHttpUrl(string? url)
+ => Uri.TryCreate(url, UriKind.Absolute, out var uri) &&
+ uri.Scheme is "http" or "https";
+
+ public static string Host(string? url)
+ => Uri.TryCreate(url, UriKind.Absolute, out var uri) ? uri.Host : "";
+
+ private static string? FirstNonEmpty(string? primary, string? fallback)
+ {
+ if (!string.IsNullOrWhiteSpace(primary))
+ {
+ return primary;
+ }
+
+ return string.IsNullOrWhiteSpace(fallback) ? null : fallback;
+ }
+}
+
+public static class LlmProviderModelIds
+{
+ public const string Prefix = "provider:";
+
+ public static string Create(string providerId, string apiModel)
+ => $"{Prefix}{providerId}:{apiModel}";
+
+ public static bool TryParse(string? modelId, out string providerId, out string apiModel)
+ {
+ providerId = "";
+ apiModel = "";
+ if (string.IsNullOrWhiteSpace(modelId) ||
+ !modelId.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase))
+ {
+ return false;
+ }
+
+ var rest = modelId[Prefix.Length..];
+ var separator = rest.IndexOf(':');
+ if (separator <= 0 || separator >= rest.Length - 1)
+ {
+ return false;
+ }
+
+ providerId = rest[..separator];
+ apiModel = rest[(separator + 1)..];
+ return !string.IsNullOrWhiteSpace(providerId) && !string.IsNullOrWhiteSpace(apiModel);
+ }
+}
+
+public static class AiChatProjectStatuses
+{
+ public const string NotConfigured = "not-configured";
+ public const string NotConnected = "not-connected";
+ public const string Ready = "ready";
+}
--
Gitblit v1.9.1