feat: 新增业务字段路径读写工具
新增 TakeBusinessFields、WriteBusinessFields、SetByPath 与 GetByPath 等工具,支持按映射路径写入请求体与解析响应,并更新相关依赖。
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
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 // OpenAI
|
||||
SupplierAzure = 7 // 微软 Azure
|
||||
SupplierAWS = 8 // 亚马逊 AWS
|
||||
SupplierGoogle = 9 // Google
|
||||
SupplierDeepSeek = 10 // DeepSeek
|
||||
SupplierMoonshot = 11 // Moonshot(月之暗面)
|
||||
SupplierZhipu = 12 // 智谱AI
|
||||
SupplierBaichuan = 13 // 百川智能
|
||||
SupplierMinimax = 14 // MiniMax
|
||||
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",
|
||||
SupplierAWS: "亚马逊 AWS",
|
||||
SupplierGoogle: "Google",
|
||||
SupplierDeepSeek: "DeepSeek",
|
||||
SupplierMoonshot: "Moonshot(月之暗面)",
|
||||
SupplierZhipu: "智谱AI",
|
||||
SupplierBaichuan: "百川智能",
|
||||
SupplierMinimax: "MiniMax",
|
||||
SupplierXunfei: "科大讯飞",
|
||||
SupplierOthers: "其他",
|
||||
}
|
||||
|
||||
// 供应商展示顺序
|
||||
var supplierOrder = []int{
|
||||
// 国内云厂商
|
||||
SupplierAliyun, SupplierVolcengine, SupplierTencent, SupplierHuawei, SupplierBaidu,
|
||||
// 海外头部
|
||||
SupplierOpenAI, SupplierGoogle, SupplierAWS, SupplierAzure,
|
||||
// 国内AI厂商
|
||||
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,224 @@
|
||||
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 // 视频模型
|
||||
TypeCode = 700 // 代码模型
|
||||
|
||||
//// 推理子类型
|
||||
//InferenceSubChat = 101 // 对话/补全
|
||||
//InferenceSubReason = 102 // 思维链/深度推理
|
||||
//InferenceSubFunction = 103 // 函数调用
|
||||
//
|
||||
//// 图片子类型
|
||||
//ImageSubTextToImage = 201 // 文生图
|
||||
//ImageSubImageToImage = 202 // 图生图
|
||||
//ImageSubImageEdit = 203 // 图片编辑
|
||||
//ImageSubImageVariation = 204 // 图片变体
|
||||
//ImageSubImageTextToImage = 205 // 图文生图
|
||||
//
|
||||
//// 音频子类型
|
||||
//AudioSubTextToSpeech = 301 // 文生音
|
||||
//AudioSubSpeechToText = 302 // 音生文
|
||||
//AudioSubSpeechToSpeech = 303 // 音生音
|
||||
//AudioSubVoiceClone = 304 // 声音克隆
|
||||
//
|
||||
//// 向量子类型
|
||||
//VectorSubEmbedding = 401 // 文本嵌入
|
||||
//VectorSubRerank = 402 // 重排序
|
||||
//
|
||||
//// 多模态子类型
|
||||
//OmniSubTextImageAudio = 501 // 文图音理解
|
||||
//OmniSubVision = 502 // 视觉理解
|
||||
//OmniSubVideoUnderstand = 503 // 视频理解
|
||||
//
|
||||
//// 视频子类型
|
||||
//VideoSubTextToVideo = 601 // 文生视频
|
||||
//VideoSubImageToVideo = 602 // 图生视频
|
||||
//VideoSubImageTextToVideo = 603 // 图文生视频
|
||||
//VideoSubVideoToVideo = 604 // 视频生视频
|
||||
//
|
||||
//// 代码子类型
|
||||
//CodeSubGeneration = 701 // 代码生成
|
||||
//CodeSubCompletion = 702 // 代码补全
|
||||
//CodeSubReview = 703 // 代码审查
|
||||
)
|
||||
|
||||
// ModelType 编码类型
|
||||
type ModelType *int
|
||||
|
||||
// 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: "视频模型",
|
||||
TypeCode: "代码模型",
|
||||
|
||||
//InferenceSubChat: "对话/补全",
|
||||
//InferenceSubReason: "思维链/深度推理",
|
||||
//InferenceSubFunction: "函数调用",
|
||||
//
|
||||
//ImageSubTextToImage: "文生图",
|
||||
//ImageSubImageToImage: "图生图",
|
||||
//ImageSubImageEdit: "图片编辑",
|
||||
//ImageSubImageVariation: "图片变体",
|
||||
//ImageSubImageTextToImage: "图文生图",
|
||||
//
|
||||
//AudioSubTextToSpeech: "文生音",
|
||||
//AudioSubSpeechToText: "音生文",
|
||||
//AudioSubSpeechToSpeech: "音生音",
|
||||
//AudioSubVoiceClone: "声音克隆",
|
||||
//
|
||||
//VectorSubEmbedding: "文本嵌入",
|
||||
//VectorSubRerank: "重排序",
|
||||
//
|
||||
//OmniSubTextImageAudio: "文图音理解",
|
||||
//OmniSubVision: "视觉理解",
|
||||
//OmniSubVideoUnderstand: "视频理解",
|
||||
//
|
||||
//VideoSubTextToVideo: "文生视频",
|
||||
//VideoSubImageToVideo: "图生视频",
|
||||
//VideoSubImageTextToVideo: "图文生视频",
|
||||
//VideoSubVideoToVideo: "视频生视频",
|
||||
//
|
||||
//CodeSubGeneration: "代码生成",
|
||||
//CodeSubCompletion: "代码补全",
|
||||
//CodeSubReview: "代码审查",
|
||||
}
|
||||
|
||||
// 父子级映射(仅存有子项的分类)
|
||||
var parentChildMap = map[int][]int{
|
||||
//TypeInference: {InferenceSubChat, InferenceSubReason, InferenceSubFunction},
|
||||
//TypeImage: {ImageSubTextToImage, ImageSubImageToImage, ImageSubImageEdit, ImageSubImageVariation, ImageSubImageTextToImage},
|
||||
//TypeAudio: {AudioSubTextToSpeech, AudioSubSpeechToText, AudioSubSpeechToSpeech, AudioSubVoiceClone},
|
||||
//TypeVector: {VectorSubEmbedding, VectorSubRerank},
|
||||
//TypeOmni: {OmniSubTextImageAudio, OmniSubVision, OmniSubVideoUnderstand},
|
||||
//TypeVideo: {VideoSubTextToVideo, VideoSubImageToVideo, VideoSubImageTextToVideo, VideoSubVideoToVideo},
|
||||
//TypeCode: {CodeSubGeneration, CodeSubCompletion, CodeSubReview},
|
||||
}
|
||||
|
||||
// 一级分类展示顺序
|
||||
var parentTypeOrder = []int{
|
||||
TypeInference, TypeImage, TypeAudio, TypeVector, TypeOmni, TypeVideo, TypeCode,
|
||||
}
|
||||
|
||||
// 全局实例:一级 + 全部二级子类型,统一通过 newItem 构造,文案仅维护在 typeNameMap
|
||||
var (
|
||||
// 一级类型
|
||||
ModelTypeInference = newItem(gconv.PtrInt(TypeInference))
|
||||
ModelTypeImage = newItem(gconv.PtrInt(TypeImage))
|
||||
ModelTypeAudio = newItem(gconv.PtrInt(TypeAudio))
|
||||
ModelTypeVector = newItem(gconv.PtrInt(TypeVector))
|
||||
ModelTypeOmni = newItem(gconv.PtrInt(TypeOmni))
|
||||
ModelTypeVideo = newItem(gconv.PtrInt(TypeVideo))
|
||||
ModelTypeCode = newItem(gconv.PtrInt(TypeCode))
|
||||
|
||||
//// 推理二级子类型
|
||||
//ModelInferenceSubChat = newItem(gconv.PtrInt(InferenceSubChat))
|
||||
//ModelInferenceSubReason = newItem(gconv.PtrInt(InferenceSubReason))
|
||||
//ModelInferenceSubFunction = newItem(gconv.PtrInt(InferenceSubFunction))
|
||||
//
|
||||
//// 图片二级子类型
|
||||
//ModelImageSubTextToImage = newItem(gconv.PtrInt(ImageSubTextToImage))
|
||||
//ModelImageSubImageToImage = newItem(gconv.PtrInt(ImageSubImageToImage))
|
||||
//ModelImageSubImageEdit = newItem(gconv.PtrInt(ImageSubImageEdit))
|
||||
//ModelImageSubImageVariation = newItem(gconv.PtrInt(ImageSubImageVariation))
|
||||
//ModelImageSubImageTextToImage = newItem(gconv.PtrInt(ImageSubImageTextToImage))
|
||||
//
|
||||
//// 音频二级子类型
|
||||
//ModelAudioSubTextToSpeech = newItem(gconv.PtrInt(AudioSubTextToSpeech))
|
||||
//ModelAudioSubSpeechToText = newItem(gconv.PtrInt(AudioSubSpeechToText))
|
||||
//ModelAudioSubSpeechToSpeech = newItem(gconv.PtrInt(AudioSubSpeechToSpeech))
|
||||
//ModelAudioSubVoiceClone = newItem(gconv.PtrInt(AudioSubVoiceClone))
|
||||
//
|
||||
//// 向量二级子类型
|
||||
//ModelVectorSubEmbedding = newItem(gconv.PtrInt(VectorSubEmbedding))
|
||||
//ModelVectorSubRerank = newItem(gconv.PtrInt(VectorSubRerank))
|
||||
//
|
||||
//// 多模态二级子类型
|
||||
//ModelOmniSubTextImageAudio = newItem(gconv.PtrInt(OmniSubTextImageAudio))
|
||||
//ModelOmniSubVision = newItem(gconv.PtrInt(OmniSubVision))
|
||||
//ModelOmniSubVideoUnderstand = newItem(gconv.PtrInt(OmniSubVideoUnderstand))
|
||||
//
|
||||
//// 视频二级子类型
|
||||
//ModelVideoSubTextToVideo = newItem(gconv.PtrInt(VideoSubTextToVideo))
|
||||
//ModelVideoSubImageToVideo = newItem(gconv.PtrInt(VideoSubImageToVideo))
|
||||
//ModelVideoSubImageTextToVideo = newItem(gconv.PtrInt(VideoSubImageTextToVideo))
|
||||
//ModelVideoSubVideoToVideo = newItem(gconv.PtrInt(VideoSubVideoToVideo))
|
||||
//
|
||||
//// 代码二级子类型
|
||||
//ModelCodeSubGeneration = newItem(gconv.PtrInt(CodeSubGeneration))
|
||||
//ModelCodeSubCompletion = newItem(gconv.PtrInt(CodeSubCompletion))
|
||||
//ModelCodeSubReview = newItem(gconv.PtrInt(CodeSubReview))
|
||||
)
|
||||
|
||||
// newItem 构造方法:自动从 typeNameMap 读取描述
|
||||
func newItem(code ModelType) ModelTypeItem {
|
||||
return ModelTypeItem{
|
||||
Code: code,
|
||||
Desc: typeNameMap[*code],
|
||||
}
|
||||
}
|
||||
|
||||
// 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