feat(backend): Enable chat history in intent_detector, knowledge_retrieve and llm node

This commit is contained in:
lvxinyu.1117
2025-07-31 15:08:09 +08:00
committed by zhuangjie.1125
parent 6ca8d53345
commit 25ded3eb27
4 changed files with 1276 additions and 10 deletions

View File

@ -440,6 +440,10 @@ func toIntentDetectorSchema(n *vo.Node, _ ...OptionFn) (*compose.NodeSchema, err
ns.SetConfigKV("IsFastMode", true)
}
if n.Data.Inputs.ChatHistorySetting != nil {
ns.SetConfigKV("ChatHistorySetting", n.Data.Inputs.ChatHistorySetting)
}
if err = SetInputsForNodeSchema(n, ns); err != nil {
return nil, err
}
@ -837,6 +841,10 @@ func toKnowledgeRetrieverSchema(n *vo.Node, _ ...OptionFn) (*compose.NodeSchema,
}
ns.SetConfigKV("KnowledgeIDs", knowledgeIDs)
if n.Data.Inputs.ChatHistorySetting != nil {
ns.SetConfigKV("ChatHistorySetting", n.Data.Inputs.ChatHistorySetting)
}
retrievalStrategy := &knowledge.RetrievalStrategy{}
var getDesignatedParamContent = func(name string) (any, bool) {

File diff suppressed because it is too large Load Diff

View File

@ -138,7 +138,11 @@ func (s *NodeSchema) New(ctx context.Context, inner compose.Runnable[map[string]
return nil, err
}
return invokableStreamableNodeWO(s, l.Chat, l.ChatStream, withCallbackOutputConverter(l.ToCallbackOutput)), nil
initFn := func(ctx context.Context) (context.Context, error) {
return ctxcache.Init(ctx), nil
}
return invokableStreamableNodeWO(s, l.Chat, l.ChatStream, withCallbackInputConverter(l.ToCallbackInput), withCallbackOutputConverter(l.ToCallbackOutput), withInit(initFn)), nil
case entity.NodeTypeSelector:
conf := s.ToSelectorConfig()
@ -389,7 +393,10 @@ func (s *NodeSchema) New(ctx context.Context, inner compose.Runnable[map[string]
if err != nil {
return nil, err
}
return invokableNode(s, r.Retrieve), nil
initFn := func(ctx context.Context) (context.Context, error) {
return ctxcache.Init(ctx), nil
}
return invokableNode(s, r.Retrieve, withCallbackInputConverter(r.ToCallbackInput), withInit(initFn)), nil
case entity.NodeTypeKnowledgeDeleter:
conf, err := s.ToKnowledgeDeleterConfig()
if err != nil {
@ -527,8 +534,10 @@ func (s *NodeSchema) New(ctx context.Context, inner compose.Runnable[map[string]
if err != nil {
return nil, err
}
return invokableNode(s, r.Invoke), nil
initFn := func(ctx context.Context) (context.Context, error) {
return ctxcache.Init(ctx), nil
}
return invokableNode(s, r.Invoke, withCallbackInputConverter(r.ToCallbackInput), withInit(initFn)), nil
case entity.NodeTypeSubWorkflow:
conf, err := s.ToSubWorkflowConfig(ctx, sc.requireCheckPoint)
if err != nil {
@ -603,6 +612,9 @@ func (s *NodeSchema) IsEnableChatHistory() bool {
case entity.NodeTypeIntentDetector:
llmParam := mustGetKey[*model.LLMParams]("LLMParams", s.Configs)
return llmParam.EnableChatHistory
case entity.NodeTypeKnowledgeRetriever:
chatHistorySetting := getKeyOrZero[*vo.ChatHistorySetting]("ChatHistorySetting", s.Configs)
return chatHistorySetting != nil && chatHistorySetting.EnableChatHistory
default:
return false
}

View File

@ -97,6 +97,13 @@ func (s *NodeSchema) ToLLMConfig(ctx context.Context) (*llm.Config, error) {
modelWithInfo llm.ModelWithInfo
)
if llmParams.EnableChatHistory {
llmConf.ChatHistorySetting = &vo.ChatHistorySetting{
EnableChatHistory: llmParams.EnableChatHistory,
ChatHistoryRound: llmParams.ChatHistoryRound,
}
}
chatModel, info, err = model.GetManager().GetModel(ctx, llmParams)
if err != nil {
return nil, err
@ -557,9 +564,10 @@ func (s *NodeSchema) ToKnowledgeIndexerConfig() (*knowledge.IndexerConfig, error
func (s *NodeSchema) ToKnowledgeRetrieveConfig() (*knowledge.RetrieveConfig, error) {
return &knowledge.RetrieveConfig{
KnowledgeIDs: mustGetKey[[]int64]("KnowledgeIDs", s.Configs),
RetrievalStrategy: mustGetKey[*crossknowledge.RetrievalStrategy]("RetrievalStrategy", s.Configs),
Retriever: crossknowledge.GetKnowledgeOperator(),
KnowledgeIDs: mustGetKey[[]int64]("KnowledgeIDs", s.Configs),
RetrievalStrategy: mustGetKey[*crossknowledge.RetrievalStrategy]("RetrievalStrategy", s.Configs),
Retriever: crossknowledge.GetKnowledgeOperator(),
ChatHistorySetting: getKeyOrZero[*vo.ChatHistorySetting]("ChatHistorySetting", s.Configs),
}, nil
}
@ -632,9 +640,10 @@ func (s *NodeSchema) ToConversationHistoryConfig() (*conversation.ConversationHi
func (s *NodeSchema) ToIntentDetectorConfig(ctx context.Context) (*intentdetector.Config, error) {
cfg := &intentdetector.Config{
Intents: mustGetKey[[]string]("Intents", s.Configs),
SystemPrompt: getKeyOrZero[string]("SystemPrompt", s.Configs),
IsFastMode: getKeyOrZero[bool]("IsFastMode", s.Configs),
Intents: mustGetKey[[]string]("Intents", s.Configs),
SystemPrompt: getKeyOrZero[string]("SystemPrompt", s.Configs),
IsFastMode: getKeyOrZero[bool]("IsFastMode", s.Configs),
ChatHistorySetting: getKeyOrZero[*vo.ChatHistorySetting]("ChatHistorySetting", s.Configs),
}
llmParams := mustGetKey[*model.LLMParams]("LLMParams", s.Configs)