实现统一模型 ID 格式 (provider_id/model_name),支持跨协议模型标识和 Smart Passthrough。 核心变更: - 新增 pkg/modelid 包:解析、格式化、校验统一模型 ID - 数据库迁移:models 表使用 UUID 主键 + UNIQUE(provider_id, model_name) 约束 - Repository 层:FindByProviderAndModelName、ListEnabled 方法 - Service 层:联合唯一校验、provider ID 字符集校验 - Conversion 层:ExtractModelName、RewriteRequestModelName/RewriteResponseModelName 方法 - Handler 层:统一模型 ID 路由、Smart Passthrough、Models API 本地聚合 - 新增 error-responses、unified-model-id 规范 测试覆盖: - 单元测试:modelid、conversion、handler、service、repository - 集成测试:统一模型 ID 路由、Smart Passthrough 保真性、跨协议转换 - 迁移测试:UUID 主键、UNIQUE 约束、级联删除 OpenSpec: - 归档 unified-model-id 变更到 archive/2026-04-21-unified-model-id - 同步 11 个 delta specs 到 main specs - 新增 error-responses、unified-model-id 规范文件
22 lines
530 B
Go
22 lines
530 B
Go
package domain
|
||
|
||
import (
|
||
"time"
|
||
|
||
"nex/backend/pkg/modelid"
|
||
)
|
||
|
||
// Model 模型领域模型(id 为 UUID 自动生成)
|
||
type Model struct {
|
||
ID string `json:"id"`
|
||
ProviderID string `json:"provider_id"`
|
||
ModelName string `json:"model_name"`
|
||
Enabled bool `json:"enabled"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
}
|
||
|
||
// UnifiedModelID 返回统一模型 ID(格式:provider_id/model_name)
|
||
func (m *Model) UnifiedModelID() string {
|
||
return modelid.FormatUnifiedModelID(m.ProviderID, m.ModelName)
|
||
}
|