67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
package model
|
|
|
|
import "github.com/gogf/gf/v2/util/gconv"
|
|
|
|
var (
|
|
ModelTypeVector = newModelType(gconv.PtrString("vector"), "向量")
|
|
ModelTypeChat = newModelType(gconv.PtrString("chat"), "对话")
|
|
)
|
|
|
|
type ModelType *string
|
|
|
|
type modelType struct {
|
|
code ModelType
|
|
desc string
|
|
}
|
|
|
|
func (s modelType) Code() ModelType {
|
|
return s.code
|
|
}
|
|
func (s modelType) Desc() string {
|
|
return s.desc
|
|
}
|
|
|
|
func newModelType(code ModelType, desc string) modelType {
|
|
return modelType{code: code, desc: desc}
|
|
}
|
|
|
|
func GetModelTypeDescByCode(code ModelType) string {
|
|
switch *code {
|
|
case *ModelTypeVector.Code():
|
|
return ModelTypeVector.Desc()
|
|
case *ModelTypeChat.Code():
|
|
return ModelTypeChat.Desc()
|
|
}
|
|
return "未知类型"
|
|
}
|
|
|
|
type GetModelTypeEnumRes struct {
|
|
Options []TypeKeyValue `json:"options"`
|
|
}
|
|
|
|
type TypeKeyValue struct {
|
|
Key interface{} `json:"key"` // 对应原有常量值
|
|
Value interface{} `json:"value"` // 对应描述信息
|
|
}
|
|
|
|
func GetAllModelTypeEnums() *GetModelTypeEnumRes {
|
|
// 枚举列表
|
|
list := []modelType{
|
|
//ModelTypeVector,
|
|
ModelTypeChat,
|
|
}
|
|
|
|
// 组装返回格式
|
|
options := make([]TypeKeyValue, 0, len(list))
|
|
for _, item := range list {
|
|
options = append(options, TypeKeyValue{
|
|
Key: *item.Code(),
|
|
Value: item.Desc(),
|
|
})
|
|
}
|
|
|
|
return &GetModelTypeEnumRes{
|
|
Options: options,
|
|
}
|
|
}
|