feat: Revamp conversation configuration management and enhance localization
- Removed outdated DEVELOPMENT.md, consolidating development instructions into relevant documentation. - Updated conversation configuration to include new parameters such as max rounds, embedding thresholds, and rewrite prompts. - Enhanced UI components to support new conversation settings, including AgentSettings.vue and related views. - Improved localization in English, Russian, and Chinese for new conversation configuration fields and UI elements. - Implemented logic to apply tenant-specific conversation settings, ensuring defaults are respected.
This commit is contained in:
@@ -444,7 +444,7 @@ func (h *AgentStreamHandler) handleComplete(ctx context.Context, evt event.Event
|
||||
"total_duration_ms": data.TotalDurationMs,
|
||||
},
|
||||
}); err != nil {
|
||||
logger.GetLogger(h.ctx).Error("Append complete event to stream failed", "error", err)
|
||||
logger.GetLogger(h.ctx).Errorf("Append complete event to stream failed: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/config"
|
||||
@@ -103,18 +104,8 @@ func (h *Handler) CreateSession(c *gin.Context) {
|
||||
|
||||
logger.Debug(ctx, "Custom session strategy set")
|
||||
} else {
|
||||
// Use default configuration from global config
|
||||
createdSession.MaxRounds = h.config.Conversation.MaxRounds
|
||||
createdSession.EnableRewrite = h.config.Conversation.EnableRewrite
|
||||
createdSession.FallbackStrategy = types.FallbackStrategy(h.config.Conversation.FallbackStrategy)
|
||||
createdSession.FallbackResponse = h.config.Conversation.FallbackResponse
|
||||
createdSession.EmbeddingTopK = h.config.Conversation.EmbeddingTopK
|
||||
createdSession.KeywordThreshold = h.config.Conversation.KeywordThreshold
|
||||
createdSession.VectorThreshold = h.config.Conversation.VectorThreshold
|
||||
createdSession.RerankThreshold = h.config.Conversation.RerankThreshold
|
||||
createdSession.RerankTopK = h.config.Conversation.RerankTopK
|
||||
createdSession.SummaryParameters = h.createDefaultSummaryConfig(ctx)
|
||||
|
||||
tenantInfo, _ := ctx.Value(types.TenantInfoContextKey).(*types.Tenant)
|
||||
h.applyConversationDefaults(ctx, createdSession, tenantInfo)
|
||||
logger.Debug(ctx, "Using default session strategy")
|
||||
}
|
||||
|
||||
@@ -159,6 +150,45 @@ func (h *Handler) CreateSession(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) applyConversationDefaults(ctx context.Context, session *types.Session, tenant *types.Tenant) {
|
||||
session.MaxRounds = h.config.Conversation.MaxRounds
|
||||
session.EnableRewrite = h.config.Conversation.EnableRewrite
|
||||
session.FallbackStrategy = types.FallbackStrategy(h.config.Conversation.FallbackStrategy)
|
||||
session.FallbackResponse = h.config.Conversation.FallbackResponse
|
||||
session.EmbeddingTopK = h.config.Conversation.EmbeddingTopK
|
||||
session.KeywordThreshold = h.config.Conversation.KeywordThreshold
|
||||
session.VectorThreshold = h.config.Conversation.VectorThreshold
|
||||
session.RerankThreshold = h.config.Conversation.RerankThreshold
|
||||
session.RerankTopK = h.config.Conversation.RerankTopK
|
||||
session.RerankModelID = ""
|
||||
session.SummaryModelID = ""
|
||||
|
||||
if tenant != nil && tenant.ConversationConfig != nil {
|
||||
tc := tenant.ConversationConfig
|
||||
session.MaxRounds = tc.MaxRounds
|
||||
session.EnableRewrite = tc.EnableRewrite
|
||||
if tc.FallbackStrategy != "" {
|
||||
session.FallbackStrategy = types.FallbackStrategy(tc.FallbackStrategy)
|
||||
}
|
||||
if tc.FallbackResponse != "" {
|
||||
session.FallbackResponse = tc.FallbackResponse
|
||||
}
|
||||
session.EmbeddingTopK = tc.EmbeddingTopK
|
||||
session.KeywordThreshold = tc.KeywordThreshold
|
||||
session.VectorThreshold = tc.VectorThreshold
|
||||
session.RerankThreshold = tc.RerankThreshold
|
||||
session.RerankTopK = tc.RerankTopK
|
||||
if tc.RerankModelID != "" {
|
||||
session.RerankModelID = tc.RerankModelID
|
||||
}
|
||||
if tc.SummaryModelID != "" {
|
||||
session.SummaryModelID = tc.SummaryModelID
|
||||
}
|
||||
}
|
||||
|
||||
session.SummaryParameters = h.createDefaultSummaryConfig(ctx)
|
||||
}
|
||||
|
||||
// GetSession retrieves a session by its ID
|
||||
func (h *Handler) GetSession(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
|
||||
@@ -185,10 +185,20 @@ func (h *Handler) createDefaultSummaryConfig(ctx context.Context) *types.Summary
|
||||
|
||||
// Override with tenant-level conversation config if available
|
||||
if tenant != nil && tenant.ConversationConfig != nil {
|
||||
if tenant.ConversationConfig.Prompt != "" {
|
||||
useSystemPrompt := tenant.ConversationConfig.UseCustomSystemPrompt
|
||||
if !useSystemPrompt && tenant.ConversationConfig.Prompt != "" {
|
||||
// Backward compatibility: treat legacy configs without flag as custom
|
||||
useSystemPrompt = true
|
||||
}
|
||||
if useSystemPrompt && tenant.ConversationConfig.Prompt != "" {
|
||||
cfg.Prompt = tenant.ConversationConfig.Prompt
|
||||
}
|
||||
if tenant.ConversationConfig.ContextTemplate != "" {
|
||||
|
||||
useContextTemplate := tenant.ConversationConfig.UseCustomContextTemplate
|
||||
if !useContextTemplate && tenant.ConversationConfig.ContextTemplate != "" {
|
||||
useContextTemplate = true
|
||||
}
|
||||
if useContextTemplate && tenant.ConversationConfig.ContextTemplate != "" {
|
||||
cfg.ContextTemplate = tenant.ConversationConfig.ContextTemplate
|
||||
}
|
||||
if tenant.ConversationConfig.Temperature > 0 {
|
||||
@@ -214,9 +224,15 @@ func (h *Handler) fillSummaryConfigDefaults(ctx context.Context, config *types.S
|
||||
var defaultMaxTokens int
|
||||
|
||||
if tenant != nil && tenant.ConversationConfig != nil {
|
||||
// Use tenant-level config as defaults
|
||||
defaultPrompt = tenant.ConversationConfig.Prompt
|
||||
defaultContextTemplate = tenant.ConversationConfig.ContextTemplate
|
||||
useSystemPrompt := tenant.ConversationConfig.UseCustomSystemPrompt
|
||||
if useSystemPrompt && tenant.ConversationConfig.Prompt != "" {
|
||||
defaultPrompt = tenant.ConversationConfig.Prompt
|
||||
}
|
||||
|
||||
useContextTemplate := tenant.ConversationConfig.UseCustomContextTemplate
|
||||
if useContextTemplate && tenant.ConversationConfig.ContextTemplate != "" {
|
||||
defaultContextTemplate = tenant.ConversationConfig.ContextTemplate
|
||||
}
|
||||
defaultTemperature = tenant.ConversationConfig.Temperature
|
||||
defaultMaxTokens = tenant.ConversationConfig.MaxTokens
|
||||
}
|
||||
|
||||
@@ -443,6 +443,16 @@ func (h *Handler) handleKnowledgeQARequest(
|
||||
if data.Done {
|
||||
logger.Infof(asyncCtx, "Knowledge QA service completed for session: %s", sessionID)
|
||||
h.completeAssistantMessage(asyncCtx, assistantMessage)
|
||||
// Emit completion event when stream finishes
|
||||
if err := eventBus.Emit(asyncCtx, event.Event{
|
||||
Type: event.EventAgentComplete,
|
||||
SessionID: sessionID,
|
||||
Data: event.AgentCompleteData{
|
||||
FinalAnswer: assistantMessage.Content,
|
||||
},
|
||||
}); err != nil {
|
||||
logger.Errorf(asyncCtx, "Failed to emit completion event: %v", err)
|
||||
}
|
||||
cancel() // Clean up context
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user