refactor: 统一模型前缀处理并规范网关层逻辑

- 抽取并统一使用 ModelConst 处理模型前缀,移除重复的 yi- 前缀判断代码
- 网关层模型 ID 规范化逻辑集中,提升可维护性
- 修复常量文件缺失换行问题
- 前端版本号调整为 3.7.1
This commit is contained in:
ccnetcore
2026-02-13 18:35:36 +08:00
parent 3df4060b20
commit bd5cf30349
4 changed files with 66 additions and 62 deletions

View File

@@ -0,0 +1,47 @@
namespace Yi.Framework.AiHub.Domain.Shared.Consts;
public class ModelConst
{
/// <summary>
/// 需要移除的模型前缀列表
/// </summary>
private static readonly List<string> ModelPrefixesToRemove =
[
"yi-",
"ma-"
];
/// <summary>
/// 获取模型ID的前缀如果存在
/// </summary>
private static string? GetModelPrefix(string? modelId)
{
if (string.IsNullOrEmpty(modelId)) return null;
return ModelPrefixesToRemove.FirstOrDefault(prefix =>
modelId!.StartsWith(prefix, StringComparison.OrdinalIgnoreCase));
}
/// <summary>
/// 移除模型ID的前缀返回标准模型ID
/// </summary>
public static string RemoveModelPrefix(string? modelId)
{
if (string.IsNullOrEmpty(modelId)) return string.Empty;
var prefix = GetModelPrefix(modelId);
if (prefix != null)
{
return modelId[prefix.Length..];
}
return modelId;
}
/// <summary>
/// 处理模型ID如有前缀则移除并返回新字符串
/// </summary>
public static string ProcessModelId(string? modelId)
{
return RemoveModelPrefix(modelId);
}
}