feat(pipeline): inject QuotedContext at LLM prompt stage
This commit is contained in:
@@ -193,6 +193,12 @@ func buildIMQARequest(
|
||||
// frontend toggle; for IM channels the user has no per-message toggle,
|
||||
// so we derive it from the agent config (the single source of truth).
|
||||
webSearchEnabled := customAgent != nil && customAgent.Config.WebSearchEnabled
|
||||
quotedContext := formatQuotedContext(quote)
|
||||
if quotedContext != "" {
|
||||
// Note: using context.Background() because buildIMQARequest is a pure function without ctx.
|
||||
// This debug log won't carry trace/span IDs — acceptable for a debug-level log.
|
||||
logger.Debugf(context.Background(), "[IM] QuotedContext set: length=%d", len(quotedContext))
|
||||
}
|
||||
return &types.QARequest{
|
||||
Session: session,
|
||||
Query: query,
|
||||
@@ -201,7 +207,7 @@ func buildIMQARequest(
|
||||
KnowledgeBaseIDs: kbIDs,
|
||||
UserMessageID: userMessageID,
|
||||
WebSearchEnabled: webSearchEnabled,
|
||||
QuotedContext: formatQuotedContext(quote),
|
||||
QuotedContext: quotedContext,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package im
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
)
|
||||
|
||||
func TestFormatQuotedContext(t *testing.T) {
|
||||
@@ -52,3 +54,38 @@ func TestFormatQuotedContext(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildIMQARequest_QuotedContext(t *testing.T) {
|
||||
session := &types.Session{ID: "s1"}
|
||||
|
||||
t.Run("nil quote produces empty QuotedContext", func(t *testing.T) {
|
||||
req := buildIMQARequest(session, "hello", "a1", "u1", nil, nil, nil)
|
||||
if req.QuotedContext != "" {
|
||||
t.Errorf("QuotedContext = %q, want empty", req.QuotedContext)
|
||||
}
|
||||
if req.Query != "hello" {
|
||||
t.Errorf("Query = %q, want %q", req.Query, "hello")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("bot quote sets QuotedContext with bot label", func(t *testing.T) {
|
||||
quote := &QuotedMessage{Content: "bot reply", IsBotMessage: true}
|
||||
req := buildIMQARequest(session, "follow up", "a1", "u1", nil, nil, quote)
|
||||
if req.Query != "follow up" {
|
||||
t.Errorf("Query = %q, want %q", req.Query, "follow up")
|
||||
}
|
||||
want := "[引用的机器人回复]\nbot reply"
|
||||
if req.QuotedContext != want {
|
||||
t.Errorf("QuotedContext = %q, want %q", req.QuotedContext, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("user quote sets QuotedContext with user label", func(t *testing.T) {
|
||||
quote := &QuotedMessage{Content: "user msg", IsBotMessage: false}
|
||||
req := buildIMQARequest(session, "question", "a1", "u1", nil, nil, quote)
|
||||
want := "[被引用的消息]\nuser msg"
|
||||
if req.QuotedContext != want {
|
||||
t.Errorf("QuotedContext = %q, want %q", req.QuotedContext, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user