feat: AI 提供商列表明文回传默认模型,并按类型回落模型名
All checks were successful
Build and Deploy / deploy (push) Successful in 1m17s
All checks were successful
Build and Deploy / deploy (push) Successful in 1m17s
ApiSecret 实际承载文字主模型,列表不再脱敏;未配置时 Chat 按厂商默认模型回落。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
346f41c204
commit
efbb18c7c3
@ -16,6 +16,9 @@ public class AiProviderOutput
|
|||||||
|
|
||||||
public string? ApiKey { get; set; }
|
public string? ApiKey { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 默认模型名(历史字段名 ApiSecret,实际不当密钥脱敏)。
|
||||||
|
/// </summary>
|
||||||
public string? ApiSecret { get; set; }
|
public string? ApiSecret { get; set; }
|
||||||
|
|
||||||
public bool IsDefault { get; set; }
|
public bool IsDefault { get; set; }
|
||||||
@ -39,6 +42,9 @@ public class AiProviderSaveInput
|
|||||||
|
|
||||||
public string? ApiKey { get; set; }
|
public string? ApiKey { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 默认文字模型 ID;空表示保持原值。
|
||||||
|
/// </summary>
|
||||||
public string? ApiSecret { get; set; }
|
public string? ApiSecret { get; set; }
|
||||||
|
|
||||||
public bool IsDefault { get; set; }
|
public bool IsDefault { get; set; }
|
||||||
|
|||||||
@ -127,7 +127,8 @@ public class AiService : ApplicationService
|
|||||||
DisplayName = entity.DisplayName,
|
DisplayName = entity.DisplayName,
|
||||||
BaseUrl = entity.BaseUrl,
|
BaseUrl = entity.BaseUrl,
|
||||||
ApiKey = maskSecret ? MaskSecret(entity.ApiKeyEnc) : entity.ApiKeyEnc,
|
ApiKey = maskSecret ? MaskSecret(entity.ApiKeyEnc) : entity.ApiKeyEnc,
|
||||||
ApiSecret = maskSecret ? MaskSecret(entity.ApiSecretEnc) : entity.ApiSecretEnc,
|
// ApiSecret 实际承载默认模型名,列表需明文回传以便卡片展示/编辑
|
||||||
|
ApiSecret = entity.ApiSecretEnc,
|
||||||
IsDefault = entity.IsDefault,
|
IsDefault = entity.IsDefault,
|
||||||
Enabled = entity.Enabled
|
Enabled = entity.Enabled
|
||||||
};
|
};
|
||||||
|
|||||||
@ -82,6 +82,10 @@ public class AiLlmClient
|
|||||||
|
|
||||||
var model = modelOverride ?? provider.ApiSecretEnc;
|
var model = modelOverride ?? provider.ApiSecretEnc;
|
||||||
if (string.IsNullOrWhiteSpace(model))
|
if (string.IsNullOrWhiteSpace(model))
|
||||||
|
{
|
||||||
|
model = DefaultModelForProviderType(provider.ProviderType);
|
||||||
|
}
|
||||||
|
if (string.IsNullOrWhiteSpace(model))
|
||||||
{
|
{
|
||||||
throw new BusinessException($"请先配置 {provider.DisplayName} 的模型名(ApiSecret 字段)或在请求中传入 model");
|
throw new BusinessException($"请先配置 {provider.DisplayName} 的模型名(ApiSecret 字段)或在请求中传入 model");
|
||||||
}
|
}
|
||||||
@ -256,6 +260,19 @@ public class AiLlmClient
|
|||||||
|
|
||||||
return body.Length <= 300 ? body : body[..300];
|
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
|
public static class AiLlmServiceExtensions
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user