fix(api): 补全模型能力继承与响应推导
- 合并 base model 默认能力与平台覆盖项 - 在模型响应中补齐 text_generate 的上下文与推理能力字段 - 为相关逻辑补充测试和迁移脚本
This commit is contained in:
@@ -30,6 +30,13 @@ func (s *Store) CreatePlatformModel(ctx context.Context, input CreatePlatformMod
|
||||
return s.createPlatformModel(ctx, s.pool, input)
|
||||
}
|
||||
|
||||
// EffectivePlatformModelCapabilities merges base defaults with platform overrides.
|
||||
// Nested capability objects are merged recursively so platform fields override
|
||||
// only the same nested keys while preserving other base capability defaults.
|
||||
func EffectivePlatformModelCapabilities(base map[string]any, override map[string]any) map[string]any {
|
||||
return mergeCapabilityObjects(base, override)
|
||||
}
|
||||
|
||||
func (s *Store) ReplacePlatformModels(ctx context.Context, platformID string, inputs []CreatePlatformModelInput) ([]PlatformModel, error) {
|
||||
tx, err := s.pool.Begin(ctx)
|
||||
if err != nil {
|
||||
@@ -107,7 +114,7 @@ func (s *Store) createPlatformModel(ctx context.Context, q platformModelQuerier,
|
||||
}
|
||||
capabilities := input.Capabilities
|
||||
if len(capabilities) == 0 {
|
||||
capabilities = mergeObjects(base.Capabilities, input.CapabilityOverride)
|
||||
capabilities = EffectivePlatformModelCapabilities(base.Capabilities, input.CapabilityOverride)
|
||||
}
|
||||
billingConfig := input.BillingConfig
|
||||
if len(billingConfig) == 0 {
|
||||
@@ -355,6 +362,48 @@ func mergeObjects(base map[string]any, override map[string]any) map[string]any {
|
||||
return out
|
||||
}
|
||||
|
||||
func mergeCapabilityObjects(base map[string]any, override map[string]any) map[string]any {
|
||||
out := cloneObject(base)
|
||||
for key, value := range override {
|
||||
baseChild, baseOK := out[key].(map[string]any)
|
||||
overrideChild, overrideOK := value.(map[string]any)
|
||||
if baseOK && overrideOK {
|
||||
out[key] = mergeCapabilityObjects(baseChild, overrideChild)
|
||||
continue
|
||||
}
|
||||
out[key] = cloneObjectValue(value)
|
||||
}
|
||||
if len(out) == 0 {
|
||||
return nil
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func cloneObject(values map[string]any) map[string]any {
|
||||
out := make(map[string]any, len(values))
|
||||
for key, value := range values {
|
||||
out[key] = cloneObjectValue(value)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func cloneObjectValue(value any) any {
|
||||
switch typed := value.(type) {
|
||||
case map[string]any:
|
||||
return cloneObject(typed)
|
||||
case []any:
|
||||
out := make([]any, 0, len(typed))
|
||||
for _, item := range typed {
|
||||
out = append(out, cloneObjectValue(item))
|
||||
}
|
||||
return out
|
||||
case []string:
|
||||
return append([]string(nil), typed...)
|
||||
default:
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
func emptyObjectIfNil(value map[string]any) map[string]any {
|
||||
if value == nil {
|
||||
return map[string]any{}
|
||||
|
||||
Reference in New Issue
Block a user