feat: refactor model manager
* chore: mv model icon * fix: model icon * fix: model icon * feat: refactor model manager * fix: model icon * fix: model icon * feat: refactor model manager See merge request: !905
This commit is contained in:
@@ -1,198 +1,11 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package modelmgr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"gorm.io/gorm"
|
||||
|
||||
crossmodelmgr "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/modelmgr/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/modelmgr/service"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/storage"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/impl/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/impl/storage"
|
||||
)
|
||||
|
||||
func InitService(db *gorm.DB, idgen idgen.IDGenerator, oss storage.Storage) (*ModelmgrApplicationService, error) {
|
||||
svc := service.NewModelManager(db, idgen, oss)
|
||||
if err := loadStaticModelConfig(svc, oss); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ModelmgrApplicationSVC.DomainSVC = svc
|
||||
|
||||
return ModelmgrApplicationSVC, nil
|
||||
}
|
||||
|
||||
func loadStaticModelConfig(svc modelmgr.Manager, oss storage.Storage) error {
|
||||
ctx := context.Background()
|
||||
|
||||
id2Meta := make(map[int64]*entity.ModelMeta)
|
||||
var cursor *string
|
||||
for {
|
||||
req := &modelmgr.ListModelMetaRequest{
|
||||
Status: []entity.ModelMetaStatus{
|
||||
crossmodelmgr.StatusInUse,
|
||||
crossmodelmgr.StatusPending,
|
||||
crossmodelmgr.StatusDeleted,
|
||||
},
|
||||
Limit: 100,
|
||||
Cursor: cursor,
|
||||
}
|
||||
listMetaResp, err := svc.ListModelMeta(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, item := range listMetaResp.ModelMetaList {
|
||||
cpItem := item
|
||||
id2Meta[cpItem.ID] = cpItem
|
||||
}
|
||||
if !listMetaResp.HasMore {
|
||||
break
|
||||
}
|
||||
cursor = listMetaResp.NextCursor
|
||||
}
|
||||
|
||||
root, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
envModelMeta, envModelEntity, err := initModelByEnv(root, "resources/conf/model/template")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
filePath := filepath.Join(root, "resources/conf/model/meta")
|
||||
staticModelMeta, err := readDirYaml[crossmodelmgr.ModelMeta](filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
staticModelMeta = append(staticModelMeta, envModelMeta...)
|
||||
for _, modelMeta := range staticModelMeta {
|
||||
if _, found := id2Meta[modelMeta.ID]; !found {
|
||||
if modelMeta.IconURI == "" && modelMeta.IconURL == "" {
|
||||
return fmt.Errorf("missing icon URI or icon URL, id=%d", modelMeta.ID)
|
||||
} else if modelMeta.IconURL != "" {
|
||||
// do nothing
|
||||
} else if modelMeta.IconURI != "" {
|
||||
// try local path
|
||||
base := filepath.Base(modelMeta.IconURI)
|
||||
iconPath := filepath.Join("resources/conf/model/icon", base)
|
||||
if _, err = os.Stat(iconPath); err == nil {
|
||||
// try upload icon
|
||||
icon, err := os.ReadFile(iconPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
key := fmt.Sprintf("icon_%s_%d", base, time.Now().Second())
|
||||
if err := oss.PutObject(ctx, key, icon); err != nil {
|
||||
return err
|
||||
}
|
||||
modelMeta.IconURI = key
|
||||
} else if errors.Is(err, os.ErrNotExist) {
|
||||
// try to get object from uri
|
||||
if _, err := oss.GetObject(ctx, modelMeta.IconURI); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
newMeta, err := svc.CreateModelMeta(ctx, modelMeta)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrDuplicatedKey) {
|
||||
logs.Infof("[loadStaticModelConfig] model meta conflict for id=%d, skip", newMeta.ID)
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
logs.Infof("[loadStaticModelConfig] model meta create success, id=%d", newMeta.ID)
|
||||
}
|
||||
id2Meta[newMeta.ID] = newMeta
|
||||
} else {
|
||||
logs.Infof("[loadStaticModelConfig] model meta founded, skip create, id=%d", modelMeta.ID)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
filePath = filepath.Join(root, "resources/conf/model/entity")
|
||||
staticModel, err := readDirYaml[crossmodelmgr.Model](filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
staticModel = append(staticModel, envModelEntity...)
|
||||
for _, modelEntity := range staticModel {
|
||||
curModelEntities, err := svc.MGetModelByID(ctx, &modelmgr.MGetModelRequest{IDs: []int64{modelEntity.ID}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(curModelEntities) > 0 {
|
||||
logs.Infof("[loadStaticModelConfig] model entity founded, skip create, id=%d", modelEntity.ID)
|
||||
continue
|
||||
}
|
||||
meta, found := id2Meta[modelEntity.Meta.ID]
|
||||
if !found {
|
||||
return fmt.Errorf("model meta not found for id=%d, model_id=%d", modelEntity.Meta.ID, modelEntity.ID)
|
||||
}
|
||||
modelEntity.Meta = *meta
|
||||
if _, err = svc.CreateModel(ctx, &entity.Model{Model: modelEntity}); err != nil {
|
||||
if errors.Is(err, gorm.ErrDuplicatedKey) {
|
||||
logs.Infof("[loadStaticModelConfig] model entity conflict for id=%d, skip", modelEntity.ID)
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
logs.Infof("[loadStaticModelConfig] model entity create success, id=%d", modelEntity.ID)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func readDirYaml[T any](dir string) ([]*T, error) {
|
||||
des, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := make([]*T, 0, len(des))
|
||||
for _, file := range des {
|
||||
if file.IsDir() {
|
||||
continue
|
||||
}
|
||||
if strings.HasSuffix(file.Name(), ".yaml") || strings.HasSuffix(file.Name(), ".yml") {
|
||||
filePath := filepath.Join(dir, file.Name())
|
||||
data, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var content T
|
||||
if err := yaml.Unmarshal(data, &content); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp = append(resp, &content)
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
func InitService(mgr modelmgr.Manager, tosClient storage.Storage) *ModelmgrApplicationService {
|
||||
ModelmgrApplicationSVC = &ModelmgrApplicationService{mgr, tosClient}
|
||||
return ModelmgrApplicationSVC
|
||||
}
|
||||
|
||||
@@ -1,148 +0,0 @@
|
||||
package modelmgr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/chatmodel"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
)
|
||||
|
||||
func initModelByEnv(wd, templatePath string) (metaSlice []*modelmgr.ModelMeta, entitySlice []*modelmgr.Model, err error) {
|
||||
metaRoot := filepath.Join(wd, templatePath, "meta")
|
||||
entityRoot := filepath.Join(wd, templatePath, "entity")
|
||||
|
||||
for i := -1; i < 1000; i++ {
|
||||
rawProtocol := os.Getenv(concatEnvKey(modelProtocolPrefix, i))
|
||||
if rawProtocol == "" {
|
||||
if i < 0 {
|
||||
continue
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
protocol := chatmodel.Protocol(rawProtocol)
|
||||
info, valid := getModelEnv(i)
|
||||
if !valid {
|
||||
break
|
||||
}
|
||||
|
||||
mapping, found := modelMapping[protocol]
|
||||
if !found {
|
||||
return nil, nil, fmt.Errorf("[initModelByEnv] unsupport protocol: %s", rawProtocol)
|
||||
}
|
||||
|
||||
switch protocol {
|
||||
case chatmodel.ProtocolArk:
|
||||
fileSuffix, foundTemplate := mapping[info.modelName]
|
||||
if !foundTemplate {
|
||||
logs.Warnf("[initModelByEnv] unsupport model=%s, using default config", info.modelName)
|
||||
}
|
||||
modelMeta, err := readYaml[modelmgr.ModelMeta](filepath.Join(metaRoot, concatTemplateFileName("model_meta_template_ark", fileSuffix)))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
modelEntity, err := readYaml[modelmgr.Model](filepath.Join(entityRoot, concatTemplateFileName("model_entity_template_ark", fileSuffix)))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
id, err := strconv.ParseInt(info.id, 10, 64)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// meta 和 entity 用一个 id,有概率冲突
|
||||
modelMeta.ID = id
|
||||
modelMeta.ConnConfig.Model = info.modelID
|
||||
modelMeta.ConnConfig.APIKey = info.apiKey
|
||||
if info.baseURL != "" {
|
||||
modelMeta.ConnConfig.BaseURL = info.baseURL
|
||||
}
|
||||
modelEntity.ID = id
|
||||
modelEntity.Meta.ID = id
|
||||
if !foundTemplate {
|
||||
modelEntity.Name = info.modelName
|
||||
}
|
||||
|
||||
metaSlice = append(metaSlice, modelMeta)
|
||||
entitySlice = append(entitySlice, modelEntity)
|
||||
|
||||
default:
|
||||
return nil, nil, fmt.Errorf("[initModelByEnv] unsupport protocol: %s", rawProtocol)
|
||||
}
|
||||
}
|
||||
|
||||
return metaSlice, entitySlice, nil
|
||||
}
|
||||
|
||||
type envModelInfo struct {
|
||||
id, modelName, modelID, apiKey, baseURL string
|
||||
}
|
||||
|
||||
func getModelEnv(idx int) (info envModelInfo, valid bool) {
|
||||
info.id = os.Getenv(concatEnvKey(modelOpenCozeIDPrefix, idx))
|
||||
info.modelName = os.Getenv(concatEnvKey(modelNamePrefix, idx))
|
||||
info.modelID = os.Getenv(concatEnvKey(modelIDPrefix, idx))
|
||||
info.apiKey = os.Getenv(concatEnvKey(modelApiKeyPrefix, idx))
|
||||
info.baseURL = os.Getenv(concatEnvKey(modelBaseURLPrefix, idx))
|
||||
valid = info.modelName != "" && info.modelID != "" && info.apiKey != ""
|
||||
return
|
||||
}
|
||||
|
||||
func readYaml[T any](fPath string) (*T, error) {
|
||||
data, err := os.ReadFile(fPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var content T
|
||||
if err := yaml.Unmarshal(data, &content); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &content, nil
|
||||
}
|
||||
|
||||
func concatEnvKey(prefix string, idx int) string {
|
||||
if idx < 0 {
|
||||
return prefix
|
||||
}
|
||||
return fmt.Sprintf("%s_%d", prefix, idx)
|
||||
}
|
||||
|
||||
func concatTemplateFileName(prefix, suffix string) string {
|
||||
if suffix == "" {
|
||||
return prefix + ".yaml"
|
||||
}
|
||||
return prefix + "_" + suffix + ".yaml"
|
||||
}
|
||||
|
||||
const (
|
||||
modelProtocolPrefix = "MODEL_PROTOCOL" // model protocol
|
||||
modelOpenCozeIDPrefix = "MODEL_OPENCOZE_ID" // opencoze model id
|
||||
modelNamePrefix = "MODEL_NAME" // model name,
|
||||
modelIDPrefix = "MODEL_ID" // model in conn config
|
||||
modelApiKeyPrefix = "MODEL_API_KEY" // model api key
|
||||
modelBaseURLPrefix = "MODEL_BASE_URL" // model base url
|
||||
)
|
||||
|
||||
var modelMapping = map[chatmodel.Protocol]map[string]string{
|
||||
chatmodel.ProtocolArk: {
|
||||
"doubao-seed-1.6": "doubao-seed-1.6",
|
||||
"doubao-seed-1.6-flash": "doubao-seed-1.6-flash",
|
||||
"doubao-seed-1.6-thinking": "doubao-seed-1.6-thinking",
|
||||
"doubao-1.5-thinking-vision-pro": "doubao-1.5-thinking-vision-pro",
|
||||
"doubao-1.5-thinking-pro": "doubao-1.5-thinking-pro",
|
||||
"doubao-1.5-vision-pro": "doubao-1.5-vision-pro",
|
||||
"doubao-1.5-vision-lite": "doubao-1.5-vision-lite",
|
||||
"doubao-1.5-pro-32k": "doubao-1.5-pro-32k",
|
||||
"doubao-1.5-pro-256k": "doubao-1.5-pro-256k",
|
||||
"doubao-1.5-lite": "doubao-1.5-lite",
|
||||
"deepseek-r1": "volc_deepseek-r1",
|
||||
"deepseek-v3": "volc_deepseek-v3",
|
||||
},
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package modelmgr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/chatmodel"
|
||||
)
|
||||
|
||||
func TestInitByEnv(t *testing.T) {
|
||||
i := 0
|
||||
for k := range modelMapping[chatmodel.ProtocolArk] {
|
||||
_ = os.Setenv(concatEnvKey(modelProtocolPrefix, i), "ark")
|
||||
_ = os.Setenv(concatEnvKey(modelOpenCozeIDPrefix, i), fmt.Sprintf("%d", 45678+i))
|
||||
_ = os.Setenv(concatEnvKey(modelNamePrefix, i), k)
|
||||
_ = os.Setenv(concatEnvKey(modelIDPrefix, i), k)
|
||||
_ = os.Setenv(concatEnvKey(modelApiKeyPrefix, i), "mock_api_key")
|
||||
i++
|
||||
}
|
||||
|
||||
wd, err := os.Getwd()
|
||||
assert.NoError(t, err)
|
||||
|
||||
ms, es, err := initModelByEnv(wd, "../../conf/model/template")
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, ms, len(modelMapping[chatmodel.ProtocolArk]))
|
||||
assert.Len(t, es, len(modelMapping[chatmodel.ProtocolArk]))
|
||||
}
|
||||
@@ -19,10 +19,9 @@ package modelmgr
|
||||
import (
|
||||
"context"
|
||||
|
||||
modelmgrEntity "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/developer_api"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/modelmgr"
|
||||
modelEntity "github.com/coze-dev/coze-studio/backend/domain/modelmgr/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/impl/storage"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/i18n"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/sets"
|
||||
@@ -31,18 +30,19 @@ import (
|
||||
)
|
||||
|
||||
type ModelmgrApplicationService struct {
|
||||
DomainSVC modelmgr.Manager
|
||||
Mgr modelmgr.Manager
|
||||
TosClient storage.Storage
|
||||
}
|
||||
|
||||
var ModelmgrApplicationSVC = &ModelmgrApplicationService{}
|
||||
|
||||
func (m *ModelmgrApplicationService) GetModelList(ctx context.Context, req *developer_api.GetTypeListRequest) (
|
||||
func (m *ModelmgrApplicationService) GetModelList(ctx context.Context, _ *developer_api.GetTypeListRequest) (
|
||||
resp *developer_api.GetTypeListResponse, err error,
|
||||
) {
|
||||
// 一般不太可能同时配置这么多模型
|
||||
const modelMaxLimit = 300
|
||||
|
||||
modelResp, err := m.DomainSVC.ListModel(ctx, &modelmgr.ListModelRequest{
|
||||
modelResp, err := m.Mgr.ListModel(ctx, &modelmgr.ListModelRequest{
|
||||
Limit: modelMaxLimit,
|
||||
Cursor: nil,
|
||||
})
|
||||
@@ -51,9 +51,15 @@ func (m *ModelmgrApplicationService) GetModelList(ctx context.Context, req *deve
|
||||
}
|
||||
|
||||
locale := i18n.GetLocale(ctx)
|
||||
modelList, err := slices.TransformWithErrorCheck(modelResp.ModelList, func(m *modelEntity.Model) (*developer_api.Model, error) {
|
||||
logs.CtxInfof(ctx, "ChatModel DefaultParameters: %v", m.DefaultParameters)
|
||||
return modelDo2To(m, locale)
|
||||
modelList, err := slices.TransformWithErrorCheck(modelResp.ModelList, func(mm *modelmgr.Model) (*developer_api.Model, error) {
|
||||
logs.CtxInfof(ctx, "ChatModel DefaultParameters: %v", mm.DefaultParameters)
|
||||
if mm.IconURI != "" {
|
||||
iconUrl, err := m.TosClient.GetObjectUrl(ctx, mm.IconURI)
|
||||
if err == nil {
|
||||
mm.IconURL = iconUrl
|
||||
}
|
||||
}
|
||||
return modelDo2To(mm, locale)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -68,11 +74,11 @@ func (m *ModelmgrApplicationService) GetModelList(ctx context.Context, req *deve
|
||||
}, nil
|
||||
}
|
||||
|
||||
func modelDo2To(model *modelEntity.Model, locale i18n.Locale) (*developer_api.Model, error) {
|
||||
func modelDo2To(model *modelmgr.Model, locale i18n.Locale) (*developer_api.Model, error) {
|
||||
mm := model.Meta
|
||||
|
||||
mps := slices.Transform(model.DefaultParameters,
|
||||
func(param *modelmgrEntity.Parameter) *developer_api.ModelParameter {
|
||||
func(param *modelmgr.Parameter) *developer_api.ModelParameter {
|
||||
return parameterDo2To(param, locale)
|
||||
},
|
||||
)
|
||||
@@ -83,7 +89,7 @@ func modelDo2To(model *modelEntity.Model, locale i18n.Locale) (*developer_api.Mo
|
||||
Name: model.Name,
|
||||
ModelType: model.ID,
|
||||
ModelClass: mm.Protocol.TOModelClass(),
|
||||
ModelIcon: mm.IconURL,
|
||||
ModelIcon: model.IconURL,
|
||||
ModelInputPrice: 0,
|
||||
ModelOutputPrice: 0,
|
||||
ModelQuota: &developer_api.ModelQuota{
|
||||
@@ -102,19 +108,19 @@ func modelDo2To(model *modelEntity.Model, locale i18n.Locale) (*developer_api.Mo
|
||||
},
|
||||
ModelName: mm.Name,
|
||||
ModelClassName: mm.Protocol.TOModelClass().String(),
|
||||
IsOffline: mm.Status != modelmgrEntity.StatusInUse,
|
||||
IsOffline: mm.Status != modelmgr.StatusInUse,
|
||||
ModelParams: mps,
|
||||
ModelDesc: []*developer_api.ModelDescGroup{
|
||||
{
|
||||
GroupName: "Description",
|
||||
Desc: []string{model.Description},
|
||||
Desc: []string{model.Description.Read(locale)},
|
||||
},
|
||||
},
|
||||
FuncConfig: nil,
|
||||
EndpointName: nil,
|
||||
ModelTagList: nil,
|
||||
IsUpRequired: nil,
|
||||
ModelBriefDesc: mm.Description.Read(locale),
|
||||
ModelBriefDesc: model.Description.Read(locale),
|
||||
ModelSeries: &developer_api.ModelSeriesInfo{ // TODO: 替换为真实配置
|
||||
SeriesName: "热门模型",
|
||||
},
|
||||
@@ -122,16 +128,16 @@ func modelDo2To(model *modelEntity.Model, locale i18n.Locale) (*developer_api.Mo
|
||||
ModelAbility: &developer_api.ModelAbility{
|
||||
CotDisplay: ptr.Of(mm.Capability.Reasoning),
|
||||
FunctionCall: ptr.Of(mm.Capability.FunctionCall),
|
||||
ImageUnderstanding: ptr.Of(modalSet.Contains(modelmgrEntity.ModalImage)),
|
||||
VideoUnderstanding: ptr.Of(modalSet.Contains(modelmgrEntity.ModalVideo)),
|
||||
AudioUnderstanding: ptr.Of(modalSet.Contains(modelmgrEntity.ModalAudio)),
|
||||
ImageUnderstanding: ptr.Of(modalSet.Contains(modelmgr.ModalImage)),
|
||||
VideoUnderstanding: ptr.Of(modalSet.Contains(modelmgr.ModalVideo)),
|
||||
AudioUnderstanding: ptr.Of(modalSet.Contains(modelmgr.ModalAudio)),
|
||||
SupportMultiModal: ptr.Of(len(modalSet) > 1),
|
||||
PrefillResp: ptr.Of(mm.Capability.PrefillResponse),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func parameterDo2To(param *modelmgrEntity.Parameter, locale i18n.Locale) *developer_api.ModelParameter {
|
||||
func parameterDo2To(param *modelmgr.Parameter, locale i18n.Locale) *developer_api.ModelParameter {
|
||||
if param == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -146,19 +152,19 @@ func parameterDo2To(param *modelmgrEntity.Parameter, locale i18n.Locale) *develo
|
||||
|
||||
var custom string
|
||||
var creative, balance, precise *string
|
||||
if val, ok := param.DefaultVal[modelmgrEntity.DefaultTypeDefault]; ok {
|
||||
if val, ok := param.DefaultVal[modelmgr.DefaultTypeDefault]; ok {
|
||||
custom = val
|
||||
}
|
||||
|
||||
if val, ok := param.DefaultVal[modelmgrEntity.DefaultTypeCreative]; ok {
|
||||
if val, ok := param.DefaultVal[modelmgr.DefaultTypeCreative]; ok {
|
||||
creative = ptr.Of(val)
|
||||
}
|
||||
|
||||
if val, ok := param.DefaultVal[modelmgrEntity.DefaultTypeBalance]; ok {
|
||||
if val, ok := param.DefaultVal[modelmgr.DefaultTypeBalance]; ok {
|
||||
balance = ptr.Of(val)
|
||||
}
|
||||
|
||||
if val, ok := param.DefaultVal[modelmgrEntity.DefaultTypePrecise]; ok {
|
||||
if val, ok := param.DefaultVal[modelmgr.DefaultTypePrecise]; ok {
|
||||
precise = ptr.Of(val)
|
||||
}
|
||||
|
||||
@@ -168,11 +174,11 @@ func parameterDo2To(param *modelmgrEntity.Parameter, locale i18n.Locale) *develo
|
||||
Desc: param.Desc.Read(locale),
|
||||
Type: func() developer_api.ModelParamType {
|
||||
switch param.Type {
|
||||
case modelmgrEntity.ValueTypeBoolean:
|
||||
case modelmgr.ValueTypeBoolean:
|
||||
return developer_api.ModelParamType_Boolean
|
||||
case modelmgrEntity.ValueTypeInt:
|
||||
case modelmgr.ValueTypeInt:
|
||||
return developer_api.ModelParamType_Int
|
||||
case modelmgrEntity.ValueTypeFloat:
|
||||
case modelmgr.ValueTypeFloat:
|
||||
return developer_api.ModelParamType_Float
|
||||
default:
|
||||
return developer_api.ModelParamType_String
|
||||
@@ -191,9 +197,9 @@ func parameterDo2To(param *modelmgrEntity.Parameter, locale i18n.Locale) *develo
|
||||
ParamClass: &developer_api.ModelParamClass{
|
||||
ClassID: func() int32 {
|
||||
switch param.Style.Widget {
|
||||
case modelmgrEntity.WidgetSlider:
|
||||
case modelmgr.WidgetSlider:
|
||||
return 1
|
||||
case modelmgrEntity.WidgetRadioButtons:
|
||||
case modelmgr.WidgetRadioButtons:
|
||||
return 2
|
||||
default:
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user