File size: 1,942 Bytes
1766992 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | package models
import "strings"
// ThinkingModelSuffix 是自动派生的公开思维模型后缀
const ThinkingModelSuffix = "-thinking"
// ModelCapability 描述公开模型的能力视图
type ModelCapability struct {
RequestedModel string
BaseModel string
ThinkingEnabled bool
ToolCapable bool
}
// ResolveModelCapability 解析公开模型名到内部基础模型与能力开关
func ResolveModelCapability(modelID string) ModelCapability {
return ModelCapability{
RequestedModel: modelID,
BaseModel: TrimThinkingModel(modelID),
ThinkingEnabled: IsThinkingModel(modelID),
ToolCapable: true,
}
}
// ExpandModelList 将基础模型列表扩展为公开模型目录
func ExpandModelList(baseModels []string) []string {
seen := make(map[string]struct{}, len(baseModels)*2)
result := make([]string, 0, len(baseModels)*2)
add := func(model string) {
if model == "" {
return
}
if _, exists := seen[model]; exists {
return
}
seen[model] = struct{}{}
result = append(result, model)
}
for _, model := range baseModels {
model = strings.TrimSpace(model)
if model == "" {
continue
}
add(model)
if !IsThinkingModel(model) {
add(ThinkingModelID(model))
}
}
return result
}
// IsThinkingModel 判断是否为公开 thinking 模型
func IsThinkingModel(modelID string) bool {
return strings.HasSuffix(strings.TrimSpace(modelID), ThinkingModelSuffix)
}
// TrimThinkingModel 去除公开 thinking 模型后缀
func TrimThinkingModel(modelID string) string {
modelID = strings.TrimSpace(modelID)
if IsThinkingModel(modelID) {
return strings.TrimSuffix(modelID, ThinkingModelSuffix)
}
return modelID
}
// ThinkingModelID 生成公开 thinking 模型名
func ThinkingModelID(baseModel string) string {
baseModel = strings.TrimSpace(baseModel)
if baseModel == "" || IsThinkingModel(baseModel) {
return baseModel
}
return baseModel + ThinkingModelSuffix
}
|