From efbb18c7c379861b82287914bffcc7a8b6ca1156 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Wed, 28 Oct 2026 10:32:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20AI=20=E6=8F=90=E4=BE=9B=E5=95=86?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=98=8E=E6=96=87=E5=9B=9E=E4=BC=A0=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=A8=A1=E5=9E=8B=EF=BC=8C=E5=B9=B6=E6=8C=89=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=9B=9E=E8=90=BD=E6=A8=A1=E5=9E=8B=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ApiSecret 实际承载文字主模型,列表不再脱敏;未配置时 Chat 按厂商默认模型回落。 Co-authored-by: Cursor --- src/Oms.Application/Dtos/Ai/AiDtos.cs | 6 ++++++ src/Oms.Application/Services/Ai/AiService.cs | 3 ++- src/Oms.Application/Shared/AiLlmClient.cs | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Oms.Application/Dtos/Ai/AiDtos.cs b/src/Oms.Application/Dtos/Ai/AiDtos.cs index 7cb0f98..b217d5d 100644 --- a/src/Oms.Application/Dtos/Ai/AiDtos.cs +++ b/src/Oms.Application/Dtos/Ai/AiDtos.cs @@ -16,6 +16,9 @@ public class AiProviderOutput public string? ApiKey { get; set; } + /// + /// 默认模型名(历史字段名 ApiSecret,实际不当密钥脱敏)。 + /// public string? ApiSecret { get; set; } public bool IsDefault { get; set; } @@ -39,6 +42,9 @@ public class AiProviderSaveInput public string? ApiKey { get; set; } + /// + /// 默认文字模型 ID;空表示保持原值。 + /// public string? ApiSecret { get; set; } public bool IsDefault { get; set; } diff --git a/src/Oms.Application/Services/Ai/AiService.cs b/src/Oms.Application/Services/Ai/AiService.cs index cc9ecbd..d8f804a 100644 --- a/src/Oms.Application/Services/Ai/AiService.cs +++ b/src/Oms.Application/Services/Ai/AiService.cs @@ -127,7 +127,8 @@ public class AiService : ApplicationService DisplayName = entity.DisplayName, BaseUrl = entity.BaseUrl, ApiKey = maskSecret ? MaskSecret(entity.ApiKeyEnc) : entity.ApiKeyEnc, - ApiSecret = maskSecret ? MaskSecret(entity.ApiSecretEnc) : entity.ApiSecretEnc, + // ApiSecret 实际承载默认模型名,列表需明文回传以便卡片展示/编辑 + ApiSecret = entity.ApiSecretEnc, IsDefault = entity.IsDefault, Enabled = entity.Enabled }; diff --git a/src/Oms.Application/Shared/AiLlmClient.cs b/src/Oms.Application/Shared/AiLlmClient.cs index 6f9f825..0400994 100644 --- a/src/Oms.Application/Shared/AiLlmClient.cs +++ b/src/Oms.Application/Shared/AiLlmClient.cs @@ -82,6 +82,10 @@ public class AiLlmClient var model = modelOverride ?? provider.ApiSecretEnc; if (string.IsNullOrWhiteSpace(model)) + { + model = DefaultModelForProviderType(provider.ProviderType); + } + if (string.IsNullOrWhiteSpace(model)) { throw new BusinessException($"请先配置 {provider.DisplayName} 的模型名(ApiSecret 字段)或在请求中传入 model"); } @@ -256,6 +260,19 @@ public class AiLlmClient return body.Length <= 300 ? body : body[..300]; } + + /// + /// 未配置 ApiSecret(模型名)时按提供商类型回落默认模型。 + /// + private static string? DefaultModelForProviderType(string? providerType) => + (providerType ?? string.Empty).Trim().ToLowerInvariant() switch + { + "chatgpt" => "gpt-4o-mini", + "doubao" => "doubao-1-5-pro-32k-250115", + "deepseek" => "deepseek-chat", + "zhipu" => "glm-5.1", + _ => null + }; } public static class AiLlmServiceExtensions