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:
@@ -20,15 +20,14 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
modelmgrEntity "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/singleagent"
|
||||
intelligence "github.com/coze-dev/coze-studio/backend/api/model/intelligence/common"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/bot_common"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/developer_api"
|
||||
"github.com/coze-dev/coze-studio/backend/application/base/ctxutil"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/modelmgr"
|
||||
searchEntity "github.com/coze-dev/coze-studio/backend/domain/search/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
@@ -95,7 +94,7 @@ func (s *SingleAgentApplicationService) newDefaultSingleAgent(ctx context.Contex
|
||||
Plugin: []*bot_common.PluginInfo{},
|
||||
Knowledge: &bot_common.Knowledge{
|
||||
TopK: ptr.Of(int64(1)),
|
||||
MinScore: ptr.Of(float64(0.01)),
|
||||
MinScore: ptr.Of(0.01),
|
||||
SearchStrategy: ptr.Of(bot_common.SearchStrategy_SemanticSearch),
|
||||
RecallStrategy: &bot_common.RecallStrategy{
|
||||
UseNl2sql: ptr.Of(true),
|
||||
@@ -115,8 +114,8 @@ func (s *SingleAgentApplicationService) newDefaultSingleAgent(ctx context.Contex
|
||||
}
|
||||
|
||||
func (s *SingleAgentApplicationService) defaultModelInfo(ctx context.Context) (*bot_common.ModelInfo, error) {
|
||||
modelResp, err := s.appContext.ModelMgrDomainSVC.ListModel(ctx, &modelmgr.ListModelRequest{
|
||||
Status: []modelmgrEntity.ModelEntityStatus{modelmgrEntity.ModelEntityStatusDefault, modelmgrEntity.ModelEntityStatusInUse},
|
||||
modelResp, err := s.appContext.ModelMgr.ListModel(ctx, &modelmgr.ListModelRequest{
|
||||
Status: []modelmgr.ModelStatus{modelmgr.StatusInUse},
|
||||
Limit: 1,
|
||||
Cursor: nil,
|
||||
})
|
||||
@@ -131,8 +130,8 @@ func (s *SingleAgentApplicationService) defaultModelInfo(ctx context.Context) (*
|
||||
dm := modelResp.ModelList[0]
|
||||
|
||||
var temperature *float64
|
||||
if tp, ok := dm.FindParameter(modelmgrEntity.Temperature); ok {
|
||||
t, err := tp.GetFloat(modelmgrEntity.DefaultTypeBalance)
|
||||
if tp, ok := dm.FindParameter(modelmgr.Temperature); ok {
|
||||
t, err := tp.GetFloat(modelmgr.DefaultTypeBalance)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -141,8 +140,8 @@ func (s *SingleAgentApplicationService) defaultModelInfo(ctx context.Context) (*
|
||||
}
|
||||
|
||||
var maxTokens *int32
|
||||
if tp, ok := dm.FindParameter(modelmgrEntity.MaxTokens); ok {
|
||||
t, err := tp.GetInt(modelmgrEntity.DefaultTypeBalance)
|
||||
if tp, ok := dm.FindParameter(modelmgr.MaxTokens); ok {
|
||||
t, err := tp.GetInt(modelmgr.DefaultTypeBalance)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -152,8 +151,8 @@ func (s *SingleAgentApplicationService) defaultModelInfo(ctx context.Context) (*
|
||||
}
|
||||
|
||||
var topP *float64
|
||||
if tp, ok := dm.FindParameter(modelmgrEntity.TopP); ok {
|
||||
t, err := tp.GetFloat(modelmgrEntity.DefaultTypeBalance)
|
||||
if tp, ok := dm.FindParameter(modelmgr.TopP); ok {
|
||||
t, err := tp.GetFloat(modelmgr.DefaultTypeBalance)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -161,8 +160,8 @@ func (s *SingleAgentApplicationService) defaultModelInfo(ctx context.Context) (*
|
||||
}
|
||||
|
||||
var topK *int32
|
||||
if tp, ok := dm.FindParameter(modelmgrEntity.TopK); ok {
|
||||
t, err := tp.GetInt(modelmgrEntity.DefaultTypeBalance)
|
||||
if tp, ok := dm.FindParameter(modelmgr.TopK); ok {
|
||||
t, err := tp.GetInt(modelmgr.DefaultTypeBalance)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -170,8 +169,8 @@ func (s *SingleAgentApplicationService) defaultModelInfo(ctx context.Context) (*
|
||||
}
|
||||
|
||||
var frequencyPenalty *float64
|
||||
if tp, ok := dm.FindParameter(modelmgrEntity.FrequencyPenalty); ok {
|
||||
t, err := tp.GetFloat(modelmgrEntity.DefaultTypeBalance)
|
||||
if tp, ok := dm.FindParameter(modelmgr.FrequencyPenalty); ok {
|
||||
t, err := tp.GetFloat(modelmgr.DefaultTypeBalance)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -179,8 +178,8 @@ func (s *SingleAgentApplicationService) defaultModelInfo(ctx context.Context) (*
|
||||
}
|
||||
|
||||
var presencePenalty *float64
|
||||
if tp, ok := dm.FindParameter(modelmgrEntity.PresencePenalty); ok {
|
||||
t, err := tp.GetFloat(modelmgrEntity.DefaultTypeBalance)
|
||||
if tp, ok := dm.FindParameter(modelmgr.PresencePenalty); ok {
|
||||
t, err := tp.GetFloat(modelmgr.DefaultTypeBalance)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -30,13 +30,12 @@ import (
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/plugin_develop_common"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/entity"
|
||||
knowledge "github.com/coze-dev/coze-studio/backend/domain/knowledge/service"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/modelmgr"
|
||||
modelEntity "github.com/coze-dev/coze-studio/backend/domain/modelmgr/entity"
|
||||
pluginEntity "github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/service"
|
||||
shortcutCMDEntity "github.com/coze-dev/coze-studio/backend/domain/shortcutcmd/entity"
|
||||
workflowEntity "github.com/coze-dev/coze-studio/backend/domain/workflow/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/conv"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
@@ -159,13 +158,13 @@ func (s *SingleAgentApplicationService) shortcutCMDDo2Vo(cmdDOs []*shortcutCMDEn
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SingleAgentApplicationService) fetchModelDetails(ctx context.Context, agentInfo *entity.SingleAgent) ([]*modelEntity.Model, error) {
|
||||
func (s *SingleAgentApplicationService) fetchModelDetails(ctx context.Context, agentInfo *entity.SingleAgent) ([]*modelmgr.Model, error) {
|
||||
if agentInfo.ModelInfo.ModelId == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
modelID := agentInfo.ModelInfo.GetModelId()
|
||||
modelInfos, err := s.appContext.ModelMgrDomainSVC.MGetModelByID(ctx, &modelmgr.MGetModelRequest{
|
||||
modelInfos, err := s.appContext.ModelMgr.MGetModelByID(ctx, &modelmgr.MGetModelRequest{
|
||||
IDs: []int64{modelID},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -249,13 +248,13 @@ func (s *SingleAgentApplicationService) fetchWorkflowDetails(ctx context.Context
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func modelInfoDo2Vo(modelInfos []*modelEntity.Model) map[int64]*playground.ModelDetail {
|
||||
return slices.ToMap(modelInfos, func(e *modelEntity.Model) (int64, *playground.ModelDetail) {
|
||||
func modelInfoDo2Vo(modelInfos []*modelmgr.Model) map[int64]*playground.ModelDetail {
|
||||
return slices.ToMap(modelInfos, func(e *modelmgr.Model) (int64, *playground.ModelDetail) {
|
||||
return e.ID, toModelDetail(e)
|
||||
})
|
||||
}
|
||||
|
||||
func toModelDetail(m *modelEntity.Model) *playground.ModelDetail {
|
||||
func toModelDetail(m *modelmgr.Model) *playground.ModelDetail {
|
||||
mm := m.Meta
|
||||
|
||||
return &playground.ModelDetail{
|
||||
@@ -263,7 +262,7 @@ func toModelDetail(m *modelEntity.Model) *playground.ModelDetail {
|
||||
ModelName: ptr.Of(m.Meta.Name),
|
||||
ModelID: ptr.Of(m.ID),
|
||||
ModelFamily: ptr.Of(int64(mm.Protocol.TOModelClass())),
|
||||
ModelIconURL: ptr.Of(mm.IconURL),
|
||||
ModelIconURL: ptr.Of(m.IconURL),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ import (
|
||||
knowledge "github.com/coze-dev/coze-studio/backend/domain/knowledge/service"
|
||||
database "github.com/coze-dev/coze-studio/backend/domain/memory/database/service"
|
||||
variables "github.com/coze-dev/coze-studio/backend/domain/memory/variables/service"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/service"
|
||||
search "github.com/coze-dev/coze-studio/backend/domain/search/service"
|
||||
shortcutCmd "github.com/coze-dev/coze-studio/backend/domain/shortcutcmd/service"
|
||||
@@ -36,6 +35,7 @@ import (
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/imagex"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/storage"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/impl/chatmodel"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/jsoncache"
|
||||
@@ -55,9 +55,9 @@ type ServiceComponents struct {
|
||||
ImageX imagex.ImageX
|
||||
EventBus search.ProjectEventBus
|
||||
CounterRepo repository.CounterRepository
|
||||
ModelMgr modelmgr.Manager
|
||||
|
||||
KnowledgeDomainSVC knowledge.Knowledge
|
||||
ModelMgrDomainSVC modelmgr.Manager
|
||||
PluginDomainSVC service.PluginService
|
||||
WorkflowDomainSVC workflow.Service
|
||||
UserDomainSVC user.User
|
||||
@@ -76,6 +76,7 @@ func InitService(c *ServiceComponents) (*SingleAgentApplicationService, error) {
|
||||
CounterRepo: repository.NewCounterRepo(c.Cache),
|
||||
CPStore: c.CPStore,
|
||||
ModelFactory: chatmodel.NewDefaultFactory(),
|
||||
ModelMgr: c.ModelMgr,
|
||||
}
|
||||
|
||||
singleAgentDomainSVC := singleagent.NewService(domainComponents)
|
||||
|
||||
Reference in New Issue
Block a user