20261028 #16

Merged
zzh merged 3 commits from test into master 2026-10-28 11:26:50 +08:00
3 changed files with 25 additions and 1 deletions
Showing only changes of commit efbb18c7c3 - Show all commits

View File

@ -16,6 +16,9 @@ public class AiProviderOutput
public string? ApiKey { get; set; }
/// <summary>
/// 默认模型名(历史字段名 ApiSecret,实际不当密钥脱敏)。
/// </summary>
public string? ApiSecret { get; set; }
public bool IsDefault { get; set; }
@ -39,6 +42,9 @@ public class AiProviderSaveInput
public string? ApiKey { get; set; }
/// <summary>
/// 默认文字模型 ID;空表示保持原值。
/// </summary>
public string? ApiSecret { get; set; }
public bool IsDefault { get; set; }

View File

@ -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
};

View File

@ -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];
}
/// <summary>
/// 未配置 ApiSecret(模型名)时按提供商类型回落默认模型。
/// </summary>
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