feat: 支持多租户多模型对话及文档去重优化
This commit is contained in:
66
consts/model/type.go
Normal file
66
consts/model/type.go
Normal file
@@ -0,0 +1,66 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user