refactor(workflow): Move the knowledge component in the Workflow package into the common crossdomain package (#708)
This commit is contained in:
@@ -34,10 +34,12 @@ import (
|
||||
callbacks2 "github.com/cloudwego/eino/utils/callbacks"
|
||||
"golang.org/x/exp/maps"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/knowledge"
|
||||
crossmodel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/modelmgr"
|
||||
workflow3 "github.com/coze-dev/coze-studio/backend/api/model/workflow"
|
||||
crossknowledge "github.com/coze-dev/coze-studio/backend/crossdomain/contract/knowledge"
|
||||
crossmodelmgr "github.com/coze-dev/coze-studio/backend/crossdomain/contract/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/knowledge"
|
||||
crossmodel "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/plugin"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
|
||||
@@ -157,7 +159,6 @@ type RetrievalStrategy struct {
|
||||
|
||||
type KnowledgeRecallConfig struct {
|
||||
ChatModel model.BaseChatModel
|
||||
Retriever knowledge.KnowledgeOperator
|
||||
RetrievalStrategy *RetrievalStrategy
|
||||
SelectedKnowledgeDetails []*knowledge.KnowledgeDetail
|
||||
}
|
||||
@@ -360,7 +361,7 @@ func (c *Config) Build(ctx context.Context, ns *schema2.NodeSchema, _ ...schema2
|
||||
knowledgeRecallConfig *KnowledgeRecallConfig
|
||||
)
|
||||
|
||||
chatModel, info, err = crossmodel.GetManager().GetModel(ctx, c.LLMParams)
|
||||
chatModel, info, err = crossmodelmgr.DefaultSVC().GetModel(ctx, c.LLMParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -369,7 +370,7 @@ func (c *Config) Build(ctx context.Context, ns *schema2.NodeSchema, _ ...schema2
|
||||
if exceptionConf != nil && exceptionConf.MaxRetry > 0 {
|
||||
backupModelParams := c.BackupLLMParams
|
||||
if backupModelParams != nil {
|
||||
fallbackM, fallbackI, err = crossmodel.GetManager().GetModel(ctx, backupModelParams)
|
||||
fallbackM, fallbackI, err = crossmodelmgr.DefaultSVC().GetModel(ctx, backupModelParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -491,11 +492,9 @@ func (c *Config) Build(ctx context.Context, ns *schema2.NodeSchema, _ ...schema2
|
||||
return nil, fmt.Errorf("workflow builtin chat model for knowledge recall not configured")
|
||||
}
|
||||
|
||||
knowledgeOperator := knowledge.GetKnowledgeOperator()
|
||||
setting := fcParams.KnowledgeFCParam.GlobalSetting
|
||||
knowledgeRecallConfig = &KnowledgeRecallConfig{
|
||||
ChatModel: kwChatModel,
|
||||
Retriever: knowledgeOperator,
|
||||
}
|
||||
searchType, err := toRetrievalSearchType(setting.SearchMode)
|
||||
if err != nil {
|
||||
@@ -523,7 +522,7 @@ func (c *Config) Build(ctx context.Context, ns *schema2.NodeSchema, _ ...schema2
|
||||
knowledgeIDs = append(knowledgeIDs, kid)
|
||||
}
|
||||
|
||||
detailResp, err := knowledgeOperator.ListKnowledgeDetail(ctx,
|
||||
detailResp, err := crossknowledge.DefaultSVC().ListKnowledgeDetail(ctx,
|
||||
&knowledge.ListKnowledgeDetailRequest{
|
||||
KnowledgeIDs: knowledgeIDs,
|
||||
})
|
||||
@@ -811,7 +810,7 @@ func toRetrievalSearchType(s int64) (knowledge.SearchType, error) {
|
||||
case 20:
|
||||
return knowledge.SearchTypeFullText, nil
|
||||
default:
|
||||
return "", fmt.Errorf("invalid retrieval search type %v", s)
|
||||
return 0, fmt.Errorf("invalid retrieval search type %v", s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1156,28 +1155,28 @@ func injectKnowledgeTool(_ context.Context, g *compose.Graph[map[string]any, map
|
||||
return make(map[string]any), nil
|
||||
}
|
||||
|
||||
docs, err := cfg.Retriever.Retrieve(ctx, &knowledge.RetrieveRequest{
|
||||
Query: userPrompt,
|
||||
KnowledgeIDs: recallKnowledgeIDs,
|
||||
RetrievalStrategy: cfg.RetrievalStrategy.RetrievalStrategy,
|
||||
docs, err := crossknowledge.DefaultSVC().Retrieve(ctx, &knowledge.RetrieveRequest{
|
||||
Query: userPrompt,
|
||||
KnowledgeIDs: recallKnowledgeIDs,
|
||||
Strategy: cfg.RetrievalStrategy.RetrievalStrategy,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(docs.Slices) == 0 && cfg.RetrievalStrategy.NoReCallReplyMode == NoReCallReplyModeOfDefault {
|
||||
if len(docs.RetrieveSlices) == 0 && cfg.RetrievalStrategy.NoReCallReplyMode == NoReCallReplyModeOfDefault {
|
||||
return make(map[string]any), nil
|
||||
}
|
||||
|
||||
sb := strings.Builder{}
|
||||
if len(docs.Slices) == 0 && cfg.RetrievalStrategy.NoReCallReplyMode == NoReCallReplyModeOfCustomize {
|
||||
if len(docs.RetrieveSlices) == 0 && cfg.RetrievalStrategy.NoReCallReplyMode == NoReCallReplyModeOfCustomize {
|
||||
sb.WriteString("recall slice 1: \n")
|
||||
sb.WriteString(cfg.RetrievalStrategy.NoReCallReplyCustomizePrompt + "\n")
|
||||
}
|
||||
|
||||
for idx, msg := range docs.Slices {
|
||||
for idx, msg := range docs.RetrieveSlices {
|
||||
sb.WriteString(fmt.Sprintf("recall slice %d:\n", idx+1))
|
||||
sb.WriteString(fmt.Sprintf("%s\n", msg.Output))
|
||||
sb.WriteString(fmt.Sprintf("%s\n", msg.Slice.GetSliceContent()))
|
||||
}
|
||||
|
||||
output = map[string]any{
|
||||
|
||||
Reference in New Issue
Block a user