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,8 +20,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/eino/components/model"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/crossdomain/contract/crossmodelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/modelmgr"
|
||||
)
|
||||
|
||||
type LLMParams struct {
|
||||
@@ -59,5 +58,5 @@ func SetManager(m Manager) {
|
||||
|
||||
//go:generate mockgen -destination modelmock/model_mock.go --package mockmodel -source model.go
|
||||
type Manager interface {
|
||||
GetModel(ctx context.Context, params *LLMParams) (model.BaseChatModel, *crossmodelmgr.Model, error)
|
||||
GetModel(ctx context.Context, params *LLMParams) (model.BaseChatModel, *modelmgr.Model, error)
|
||||
}
|
||||
|
||||
@@ -1,19 +1,3 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: model.go
|
||||
//
|
||||
@@ -29,9 +13,9 @@ import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
crossmodelmgr "github.com/coze-dev/coze-studio/backend/crossdomain/contract/crossmodelmgr"
|
||||
model "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/model"
|
||||
model0 "github.com/cloudwego/eino/components/model"
|
||||
model "github.com/cloudwego/eino/components/model"
|
||||
model0 "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/model"
|
||||
modelmgr "github.com/coze-dev/coze-studio/backend/infra/contract/modelmgr"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
@@ -39,7 +23,6 @@ import (
|
||||
type MockManager struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockManagerMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockManagerMockRecorder is the mock recorder for MockManager.
|
||||
@@ -60,11 +43,11 @@ func (m *MockManager) EXPECT() *MockManagerMockRecorder {
|
||||
}
|
||||
|
||||
// GetModel mocks base method.
|
||||
func (m *MockManager) GetModel(ctx context.Context, params *model.LLMParams) (model0.BaseChatModel, *crossmodelmgr.Model, error) {
|
||||
func (m *MockManager) GetModel(ctx context.Context, params *model0.LLMParams) (model.BaseChatModel, *modelmgr.Model, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetModel", ctx, params)
|
||||
ret0, _ := ret[0].(model0.BaseChatModel)
|
||||
ret1, _ := ret[1].(*crossmodelmgr.Model)
|
||||
ret0, _ := ret[0].(model.BaseChatModel)
|
||||
ret1, _ := ret[1].(*modelmgr.Model)
|
||||
ret2, _ := ret[2].(error)
|
||||
return ret0, ret1, ret2
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ import (
|
||||
model2 "github.com/cloudwego/eino/components/model"
|
||||
"github.com/cloudwego/eino/compose"
|
||||
"github.com/cloudwego/eino/schema"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/modelmgr"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/mock/gomock"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/model"
|
||||
mockmodel "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/model/modelmock"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity"
|
||||
|
||||
@@ -28,8 +28,8 @@ import (
|
||||
"github.com/cloudwego/eino/components/tool"
|
||||
"github.com/cloudwego/eino/compose"
|
||||
"github.com/cloudwego/eino/schema"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/modelmgr"
|
||||
|
||||
crossmodelmgr "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/modelmgr"
|
||||
workflow3 "github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/workflow"
|
||||
workflow2 "github.com/coze-dev/coze-studio/backend/domain/workflow"
|
||||
crosscode "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/code"
|
||||
@@ -91,7 +91,7 @@ func (s *NodeSchema) ToLLMConfig(ctx context.Context) (*llm.Config, error) {
|
||||
var (
|
||||
err error
|
||||
chatModel, fallbackM einomodel.BaseChatModel
|
||||
info, fallbackI *crossmodelmgr.Model
|
||||
info, fallbackI *modelmgr.Model
|
||||
modelWithInfo llm.ModelWithInfo
|
||||
)
|
||||
|
||||
|
||||
@@ -24,28 +24,27 @@ import (
|
||||
"github.com/cloudwego/eino/components"
|
||||
"github.com/cloudwego/eino/components/model"
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
crossmodelmgr "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/execute"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/modelmgr"
|
||||
)
|
||||
|
||||
type ModelWithInfo interface {
|
||||
model.BaseChatModel
|
||||
Info(ctx context.Context) *crossmodelmgr.Model
|
||||
Info(ctx context.Context) *modelmgr.Model
|
||||
}
|
||||
|
||||
type ModelForLLM struct {
|
||||
Model model.BaseChatModel
|
||||
MInfo *crossmodelmgr.Model
|
||||
MInfo *modelmgr.Model
|
||||
FallbackModel model.BaseChatModel
|
||||
FallbackInfo *crossmodelmgr.Model
|
||||
FallbackInfo *modelmgr.Model
|
||||
UseFallback func(ctx context.Context) bool
|
||||
|
||||
modelEnableCallback bool
|
||||
fallbackEnableCallback bool
|
||||
}
|
||||
|
||||
func NewModel(m model.BaseChatModel, info *crossmodelmgr.Model) *ModelForLLM {
|
||||
func NewModel(m model.BaseChatModel, info *modelmgr.Model) *ModelForLLM {
|
||||
return &ModelForLLM{
|
||||
Model: m,
|
||||
MInfo: info,
|
||||
@@ -57,7 +56,7 @@ func NewModel(m model.BaseChatModel, info *crossmodelmgr.Model) *ModelForLLM {
|
||||
}
|
||||
}
|
||||
|
||||
func NewModelWithFallback(m, f model.BaseChatModel, info, fInfo *crossmodelmgr.Model) *ModelForLLM {
|
||||
func NewModelWithFallback(m, f model.BaseChatModel, info, fInfo *modelmgr.Model) *ModelForLLM {
|
||||
return &ModelForLLM{
|
||||
Model: m,
|
||||
MInfo: info,
|
||||
@@ -175,7 +174,7 @@ func (m *ModelForLLM) IsCallbacksEnabled() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *ModelForLLM) Info(ctx context.Context) *crossmodelmgr.Model {
|
||||
func (m *ModelForLLM) Info(ctx context.Context) *modelmgr.Model {
|
||||
if m.UseFallback(ctx) {
|
||||
return m.FallbackInfo
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ import (
|
||||
|
||||
"github.com/cloudwego/eino/components/prompt"
|
||||
"github.com/cloudwego/eino/schema"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/modelmgr"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/execute"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/nodes"
|
||||
|
||||
Reference in New Issue
Block a user