feat: Introduce conversation configuration management and localization updates

- Added new ConversationConfig interface and API endpoints for retrieving and updating conversation settings.
- Enhanced AgentSettings.vue to include UI for configuring conversation parameters such as prompt, context template, temperature, and max tokens.
- Updated localization files in English and Chinese to include new strings for conversation settings.
- Implemented logic to load and save conversation configuration for tenants, ensuring defaults are applied when no specific configuration exists.
This commit is contained in:
wizardchen
2025-11-17 15:33:43 +08:00
parent a886106917
commit 1f5e445eaa
14 changed files with 913 additions and 175 deletions
+3 -3
View File
@@ -97,9 +97,9 @@ func (h *Handler) CreateSession(c *gin.Context) {
if request.SessionStrategy.SummaryParameters != nil {
createdSession.SummaryParameters = request.SessionStrategy.SummaryParameters
} else {
createdSession.SummaryParameters = h.createDefaultSummaryConfig()
createdSession.SummaryParameters = h.createDefaultSummaryConfig(ctx)
}
h.fillSummaryConfigDefaults(createdSession.SummaryParameters)
h.fillSummaryConfigDefaults(ctx, createdSession.SummaryParameters)
logger.Debug(ctx, "Custom session strategy set")
} else {
@@ -113,7 +113,7 @@ func (h *Handler) CreateSession(c *gin.Context) {
createdSession.VectorThreshold = h.config.Conversation.VectorThreshold
createdSession.RerankThreshold = h.config.Conversation.RerankThreshold
createdSession.RerankTopK = h.config.Conversation.RerankTopK
createdSession.SummaryParameters = h.createDefaultSummaryConfig()
createdSession.SummaryParameters = h.createDefaultSummaryConfig(ctx)
logger.Debug(ctx, "Using default session strategy")
}
+68 -6
View File
@@ -162,8 +162,13 @@ func getFloat64(m map[string]interface{}, key string) float64 {
}
// createDefaultSummaryConfig creates a default summary configuration from config
func (h *Handler) createDefaultSummaryConfig() *types.SummaryConfig {
return &types.SummaryConfig{
// It prioritizes tenant-level ConversationConfig, then falls back to config.yaml defaults
func (h *Handler) createDefaultSummaryConfig(ctx context.Context) *types.SummaryConfig {
// Try to get tenant from context
tenant, _ := ctx.Value(types.TenantInfoContextKey).(*types.Tenant)
// Initialize with config.yaml defaults
cfg := &types.SummaryConfig{
MaxTokens: h.config.Conversation.Summary.MaxTokens,
TopP: h.config.Conversation.Summary.TopP,
TopK: h.config.Conversation.Summary.TopK,
@@ -177,17 +182,74 @@ func (h *Handler) createDefaultSummaryConfig() *types.SummaryConfig {
Seed: h.config.Conversation.Summary.Seed,
MaxCompletionTokens: h.config.Conversation.Summary.MaxCompletionTokens,
}
// Override with tenant-level conversation config if available
if tenant != nil && tenant.ConversationConfig != nil {
if tenant.ConversationConfig.Prompt != "" {
cfg.Prompt = tenant.ConversationConfig.Prompt
}
if tenant.ConversationConfig.ContextTemplate != "" {
cfg.ContextTemplate = tenant.ConversationConfig.ContextTemplate
}
if tenant.ConversationConfig.Temperature > 0 {
cfg.Temperature = tenant.ConversationConfig.Temperature
}
if tenant.ConversationConfig.MaxTokens > 0 {
cfg.MaxTokens = tenant.ConversationConfig.MaxTokens
}
}
return cfg
}
// fillSummaryConfigDefaults fills missing fields in summary config with defaults
func (h *Handler) fillSummaryConfigDefaults(config *types.SummaryConfig) {
// It prioritizes tenant-level ConversationConfig, then falls back to config.yaml defaults
func (h *Handler) fillSummaryConfigDefaults(ctx context.Context, config *types.SummaryConfig) {
// Try to get tenant from context
tenant, _ := ctx.Value(types.TenantInfoContextKey).(*types.Tenant)
// Determine default values: tenant config first, then config.yaml
var defaultPrompt, defaultContextTemplate, defaultNoMatchPrefix string
var defaultTemperature float64
var defaultMaxTokens int
if tenant != nil && tenant.ConversationConfig != nil {
// Use tenant-level config as defaults
defaultPrompt = tenant.ConversationConfig.Prompt
defaultContextTemplate = tenant.ConversationConfig.ContextTemplate
defaultTemperature = tenant.ConversationConfig.Temperature
defaultMaxTokens = tenant.ConversationConfig.MaxTokens
}
// Fall back to config.yaml if tenant config is empty
if defaultPrompt == "" {
defaultPrompt = h.config.Conversation.Summary.Prompt
}
if defaultContextTemplate == "" {
defaultContextTemplate = h.config.Conversation.Summary.ContextTemplate
}
if defaultTemperature == 0 {
defaultTemperature = h.config.Conversation.Summary.Temperature
}
if defaultMaxTokens == 0 {
defaultMaxTokens = h.config.Conversation.Summary.MaxTokens
}
defaultNoMatchPrefix = h.config.Conversation.Summary.NoMatchPrefix
// Fill missing fields
if config.Prompt == "" {
config.Prompt = h.config.Conversation.Summary.Prompt
config.Prompt = defaultPrompt
}
if config.ContextTemplate == "" {
config.ContextTemplate = h.config.Conversation.Summary.ContextTemplate
config.ContextTemplate = defaultContextTemplate
}
if config.Temperature == 0 {
config.Temperature = defaultTemperature
}
if config.MaxTokens == 0 {
config.MaxTokens = defaultMaxTokens
}
if config.NoMatchPrefix == "" {
config.NoMatchPrefix = h.config.Conversation.Summary.NoMatchPrefix
config.NoMatchPrefix = defaultNoMatchPrefix
}
}