feat: 新增模型管理模块功能
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"model-gateway/consts/public"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
// 供应商编码常量
|
||||
const (
|
||||
SupplierAliyun = 1
|
||||
SupplierVolcengine = 2
|
||||
SupplierTencent = 3
|
||||
SupplierHuawei = 4
|
||||
SupplierBaidu = 5
|
||||
SupplierOpenAI = 6
|
||||
SupplierAzure = 7
|
||||
SupplierAWS = 8
|
||||
SupplierGoogle = 9
|
||||
SupplierDeepSeek = 10
|
||||
SupplierMoonshot = 11
|
||||
SupplierZhipu = 12
|
||||
SupplierBaichuan = 13
|
||||
SupplierMinimax = 14
|
||||
SupplierXunfei = 15
|
||||
SupplierOthers = 16
|
||||
)
|
||||
|
||||
// SupplierType 供应商编码类型
|
||||
type SupplierType *int8
|
||||
|
||||
// SupplierItem 供应商项
|
||||
type SupplierItem struct {
|
||||
Code SupplierType `json:"code"`
|
||||
Desc string `json:"desc"`
|
||||
}
|
||||
|
||||
// 名称映射【唯一文案维护】
|
||||
var supplierNameMap = map[int]string{
|
||||
SupplierAliyun: "阿里云百炼",
|
||||
SupplierVolcengine: "火山引擎",
|
||||
SupplierTencent: "腾讯云",
|
||||
SupplierHuawei: "华为云",
|
||||
SupplierBaidu: "百度智能云",
|
||||
SupplierOpenAI: "OpenAI",
|
||||
SupplierAzure: "Azure OpenAI",
|
||||
SupplierAWS: "AWS Bedrock",
|
||||
SupplierGoogle: "Google Cloud",
|
||||
SupplierDeepSeek: "DeepSeek",
|
||||
SupplierMoonshot: "Moonshot",
|
||||
SupplierZhipu: "智谱AI",
|
||||
SupplierBaichuan: "百川智能",
|
||||
SupplierMinimax: "MiniMax",
|
||||
SupplierXunfei: "科大讯飞",
|
||||
SupplierOthers: "其他",
|
||||
}
|
||||
|
||||
// 供应商展示顺序
|
||||
var supplierOrder = []int{
|
||||
SupplierAliyun, SupplierVolcengine, SupplierTencent, SupplierHuawei, SupplierBaidu,
|
||||
SupplierOpenAI, SupplierAzure, SupplierAWS, SupplierGoogle, SupplierDeepSeek,
|
||||
SupplierMoonshot, SupplierZhipu, SupplierBaichuan, SupplierMinimax, SupplierXunfei, SupplierOthers,
|
||||
}
|
||||
|
||||
// 全局供应商实例
|
||||
var (
|
||||
SupplierItemAliyun = newSupplierItem(gconv.PtrInt8(SupplierAliyun))
|
||||
SupplierItemVolcengine = newSupplierItem(gconv.PtrInt8(SupplierVolcengine))
|
||||
SupplierItemTencent = newSupplierItem(gconv.PtrInt8(SupplierTencent))
|
||||
SupplierItemHuawei = newSupplierItem(gconv.PtrInt8(SupplierHuawei))
|
||||
SupplierItemBaidu = newSupplierItem(gconv.PtrInt8(SupplierBaidu))
|
||||
SupplierItemOpenAI = newSupplierItem(gconv.PtrInt8(SupplierOpenAI))
|
||||
SupplierItemAzure = newSupplierItem(gconv.PtrInt8(SupplierAzure))
|
||||
SupplierItemAWS = newSupplierItem(gconv.PtrInt8(SupplierAWS))
|
||||
SupplierItemGoogle = newSupplierItem(gconv.PtrInt8(SupplierGoogle))
|
||||
SupplierItemDeepSeek = newSupplierItem(gconv.PtrInt8(SupplierDeepSeek))
|
||||
SupplierItemMoonshot = newSupplierItem(gconv.PtrInt8(SupplierMoonshot))
|
||||
SupplierItemZhipu = newSupplierItem(gconv.PtrInt8(SupplierZhipu))
|
||||
SupplierItemBaichuan = newSupplierItem(gconv.PtrInt8(SupplierBaichuan))
|
||||
SupplierItemMinimax = newSupplierItem(gconv.PtrInt8(SupplierMinimax))
|
||||
SupplierItemXunfei = newSupplierItem(gconv.PtrInt8(SupplierXunfei))
|
||||
SupplierItemOthers = newSupplierItem(gconv.PtrInt8(SupplierOthers))
|
||||
)
|
||||
|
||||
func newSupplierItem(code SupplierType) SupplierItem {
|
||||
val := int(*code)
|
||||
return SupplierItem{
|
||||
Code: code,
|
||||
Desc: supplierNameMap[val],
|
||||
}
|
||||
}
|
||||
|
||||
// GetSupplierDescByCode 根据编码获取供应商名称
|
||||
func GetSupplierDescByCode(code int) string {
|
||||
return supplierNameMap[code]
|
||||
}
|
||||
|
||||
// GetSupplierOptionList 获取供应商下拉列表
|
||||
func GetSupplierOptionList() []*public.Option {
|
||||
var list []*public.Option
|
||||
for _, code := range supplierOrder {
|
||||
list = append(list, &public.Option{
|
||||
Value: code,
|
||||
Label: supplierNameMap[code],
|
||||
})
|
||||
}
|
||||
return list
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"model-gateway/consts/public"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
// 模型类型编码常量
|
||||
const (
|
||||
TypeInference = 100 // 推理模型
|
||||
TypeImage = 200 // 图片模型
|
||||
TypeAudio = 300 // 音频模型
|
||||
TypeVector = 400 // 向量化模型
|
||||
TypeOmni = 500 // 全模态模型
|
||||
TypeVideo = 600 // 视频模型
|
||||
|
||||
// 图片子类型
|
||||
ImageSubTextToImage = 201
|
||||
ImageSubImageToImage = 202
|
||||
ImageSubImageEdit = 203
|
||||
ImageSubImageVariation = 204
|
||||
ImageSubImageTextToImage = 205
|
||||
|
||||
// 音频子类型
|
||||
AudioSubTextToSpeech = 301
|
||||
AudioSubSpeechToText = 302
|
||||
AudioSubSpeechToSpeech = 303
|
||||
|
||||
// 向量化子类型
|
||||
VectorSubEmbedding = 401
|
||||
VectorSubRerank = 402
|
||||
|
||||
// 全模态子类型
|
||||
OmniSubTextImageAudio = 501
|
||||
OmniSubVision = 502
|
||||
|
||||
// 视频子类型
|
||||
VideoSubTextToVideo = 601
|
||||
VideoSubImageToVideo = 602
|
||||
VideoSubImageTextToVideo = 603
|
||||
VideoSubVideoToVideo = 604
|
||||
)
|
||||
|
||||
// ModelType 编码类型
|
||||
type ModelType *int8
|
||||
|
||||
// ModelTypeItem 模型类型项
|
||||
type ModelTypeItem struct {
|
||||
Code ModelType `json:"code"`
|
||||
Desc string `json:"desc"`
|
||||
}
|
||||
|
||||
// TypeTree 树形结构
|
||||
type TypeTree struct {
|
||||
Value int `json:"value"`
|
||||
Label string `json:"label"`
|
||||
Children []*public.Option `json:"children"`
|
||||
}
|
||||
|
||||
// 名称映射表【唯一文案维护入口】
|
||||
var typeNameMap = map[int]string{
|
||||
TypeInference: "推理模型",
|
||||
TypeImage: "图片模型",
|
||||
TypeAudio: "音频模型",
|
||||
TypeVector: "向量化模型",
|
||||
TypeOmni: "全模态模型",
|
||||
TypeVideo: "视频模型",
|
||||
|
||||
ImageSubTextToImage: "文生图",
|
||||
ImageSubImageToImage: "图生图",
|
||||
ImageSubImageEdit: "图片编辑",
|
||||
ImageSubImageVariation: "图片变体",
|
||||
ImageSubImageTextToImage: "图文生图",
|
||||
|
||||
AudioSubTextToSpeech: "文生音",
|
||||
AudioSubSpeechToText: "音生文",
|
||||
AudioSubSpeechToSpeech: "音生音",
|
||||
|
||||
VectorSubEmbedding: "文本嵌入",
|
||||
VectorSubRerank: "重排序",
|
||||
|
||||
OmniSubTextImageAudio: "文图音",
|
||||
OmniSubVision: "视觉理解",
|
||||
|
||||
VideoSubTextToVideo: "文生视频",
|
||||
VideoSubImageToVideo: "图生视频",
|
||||
VideoSubImageTextToVideo: "图文生视频",
|
||||
VideoSubVideoToVideo: "视频生视频",
|
||||
}
|
||||
|
||||
// 父子级映射(仅存有子项的分类)
|
||||
var parentChildMap = map[int][]int{
|
||||
TypeImage: {ImageSubTextToImage, ImageSubImageToImage, ImageSubImageEdit, ImageSubImageVariation, ImageSubImageTextToImage},
|
||||
TypeAudio: {AudioSubTextToSpeech, AudioSubSpeechToText, AudioSubSpeechToSpeech},
|
||||
TypeVector: {VectorSubEmbedding, VectorSubRerank},
|
||||
TypeOmni: {OmniSubTextImageAudio, OmniSubVision},
|
||||
TypeVideo: {VideoSubTextToVideo, VideoSubImageToVideo, VideoSubImageTextToVideo, VideoSubVideoToVideo},
|
||||
}
|
||||
|
||||
// 一级分类展示顺序
|
||||
var parentTypeOrder = []int{
|
||||
TypeInference, TypeImage, TypeAudio, TypeVector, TypeOmni, TypeVideo,
|
||||
}
|
||||
|
||||
// 全局实例:一级 + 全部二级子类型,统一通过 newItem 构造,文案仅维护在 typeNameMap
|
||||
var (
|
||||
// 一级类型
|
||||
ModelTypeInference = newItem(gconv.PtrInt8(TypeInference))
|
||||
ModelTypeImage = newItem(gconv.PtrInt8(TypeImage))
|
||||
ModelTypeAudio = newItem(gconv.PtrInt8(TypeAudio))
|
||||
ModelTypeVector = newItem(gconv.PtrInt8(TypeVector))
|
||||
ModelTypeOmni = newItem(gconv.PtrInt8(TypeOmni))
|
||||
ModelTypeVideo = newItem(gconv.PtrInt8(TypeVideo))
|
||||
|
||||
// 图片二级子类型
|
||||
ModelImageSubTextToImage = newItem(gconv.PtrInt8(ImageSubTextToImage))
|
||||
ModelImageSubImageToImage = newItem(gconv.PtrInt8(ImageSubImageToImage))
|
||||
ModelImageSubImageEdit = newItem(gconv.PtrInt8(ImageSubImageEdit))
|
||||
ModelImageSubImageVariation = newItem(gconv.PtrInt8(ImageSubImageVariation))
|
||||
ModelImageSubImageTextToImage = newItem(gconv.PtrInt8(ImageSubImageTextToImage))
|
||||
|
||||
// 音频二级子类型
|
||||
ModelAudioSubTextToSpeech = newItem(gconv.PtrInt8(AudioSubTextToSpeech))
|
||||
ModelAudioSubSpeechToText = newItem(gconv.PtrInt8(AudioSubSpeechToText))
|
||||
ModelAudioSubSpeechToSpeech = newItem(gconv.PtrInt8(AudioSubSpeechToSpeech))
|
||||
|
||||
// 向量化二级子类型
|
||||
ModelVectorSubEmbedding = newItem(gconv.PtrInt8(VectorSubEmbedding))
|
||||
ModelVectorSubRerank = newItem(gconv.PtrInt8(VectorSubRerank))
|
||||
|
||||
// 全模态二级子类型
|
||||
ModelOmniSubTextImageAudio = newItem(gconv.PtrInt8(OmniSubTextImageAudio))
|
||||
ModelOmniSubVision = newItem(gconv.PtrInt8(OmniSubVision))
|
||||
|
||||
// 视频二级子类型
|
||||
ModelVideoSubTextToVideo = newItem(gconv.PtrInt8(VideoSubTextToVideo))
|
||||
ModelVideoSubImageToVideo = newItem(gconv.PtrInt8(VideoSubImageToVideo))
|
||||
ModelVideoSubImageTextToVideo = newItem(gconv.PtrInt8(VideoSubImageTextToVideo))
|
||||
ModelVideoSubVideoToVideo = newItem(gconv.PtrInt8(VideoSubVideoToVideo))
|
||||
)
|
||||
|
||||
// newItem 构造方法:自动从 typeNameMap 读取描述
|
||||
func newItem(code ModelType) ModelTypeItem {
|
||||
val := int(*code)
|
||||
return ModelTypeItem{
|
||||
Code: code,
|
||||
Desc: typeNameMap[val],
|
||||
}
|
||||
}
|
||||
|
||||
// GetDescByCode 根据编码获取名称
|
||||
func GetDescByCode(code int) string {
|
||||
return typeNameMap[code]
|
||||
}
|
||||
|
||||
// GetTypeTreeList 生成树形数据
|
||||
func GetTypeTreeList() []*TypeTree {
|
||||
var list []*TypeTree
|
||||
for _, parentCode := range parentTypeOrder {
|
||||
tree := &TypeTree{
|
||||
Value: parentCode,
|
||||
Label: typeNameMap[parentCode],
|
||||
Children: make([]*public.Option, 0),
|
||||
}
|
||||
if childCodes, ok := parentChildMap[parentCode]; ok {
|
||||
for _, c := range childCodes {
|
||||
tree.Children = append(tree.Children, &public.Option{
|
||||
Value: c,
|
||||
Label: typeNameMap[c],
|
||||
})
|
||||
}
|
||||
}
|
||||
list = append(list, tree)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// GetAllTypeOption 全量平铺选项
|
||||
func GetAllTypeOption() []*public.Option {
|
||||
var list []*public.Option
|
||||
for code, label := range typeNameMap {
|
||||
list = append(list, &public.Option{Value: code, Label: label})
|
||||
}
|
||||
return list
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package model
|
||||
|
||||
import "github.com/gogf/gf/v2/util/gconv"
|
||||
|
||||
var (
|
||||
ResponseTypeSync = newResponseType(gconv.PtrInt8(1), "sync") // 同步
|
||||
ResponseTypeAsync = newResponseType(gconv.PtrInt8(2), "async") // 异步
|
||||
ResponseTypeStream = newResponseType(gconv.PtrInt8(3), "stream") // 流
|
||||
)
|
||||
|
||||
type ResponseType *int8
|
||||
|
||||
type responseType struct {
|
||||
code ResponseType
|
||||
desc string
|
||||
}
|
||||
|
||||
func (s responseType) Code() ResponseType {
|
||||
return s.code
|
||||
}
|
||||
func (s responseType) Desc() string {
|
||||
return s.desc
|
||||
}
|
||||
|
||||
func newResponseType(code ResponseType, desc string) responseType {
|
||||
return responseType{code: code, desc: desc}
|
||||
}
|
||||
Reference in New Issue
Block a user