feat: Enhance agent configuration and localization for web search prompts
- Updated agent configuration to support separate system prompts for web search enabled and disabled states. - Removed deprecated agent configuration parameters to streamline settings management. - Enhanced UI components in AgentSettings.vue to allow configuration of custom prompts based on web search status. - Improved localization in English, Russian, and Chinese for new prompt settings and UI elements. - Refactored related API and service logic to accommodate changes in agent configuration structure.
This commit is contained in:
@@ -204,8 +204,8 @@ func (h *Handler) createDefaultSummaryConfig(ctx context.Context) *types.Summary
|
||||
if tenant.ConversationConfig.Temperature > 0 {
|
||||
cfg.Temperature = tenant.ConversationConfig.Temperature
|
||||
}
|
||||
if tenant.ConversationConfig.MaxTokens > 0 {
|
||||
cfg.MaxTokens = tenant.ConversationConfig.MaxTokens
|
||||
if tenant.ConversationConfig.MaxCompletionTokens > 0 {
|
||||
cfg.MaxCompletionTokens = tenant.ConversationConfig.MaxCompletionTokens
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ func (h *Handler) fillSummaryConfigDefaults(ctx context.Context, config *types.S
|
||||
// Determine default values: tenant config first, then config.yaml
|
||||
var defaultPrompt, defaultContextTemplate, defaultNoMatchPrefix string
|
||||
var defaultTemperature float64
|
||||
var defaultMaxTokens int
|
||||
var defaultMaxCompletionTokens int
|
||||
|
||||
if tenant != nil && tenant.ConversationConfig != nil {
|
||||
useSystemPrompt := tenant.ConversationConfig.UseCustomSystemPrompt
|
||||
@@ -234,7 +234,7 @@ func (h *Handler) fillSummaryConfigDefaults(ctx context.Context, config *types.S
|
||||
defaultContextTemplate = tenant.ConversationConfig.ContextTemplate
|
||||
}
|
||||
defaultTemperature = tenant.ConversationConfig.Temperature
|
||||
defaultMaxTokens = tenant.ConversationConfig.MaxTokens
|
||||
defaultMaxCompletionTokens = tenant.ConversationConfig.MaxCompletionTokens
|
||||
}
|
||||
|
||||
// Fall back to config.yaml if tenant config is empty
|
||||
@@ -247,8 +247,8 @@ func (h *Handler) fillSummaryConfigDefaults(ctx context.Context, config *types.S
|
||||
if defaultTemperature == 0 {
|
||||
defaultTemperature = h.config.Conversation.Summary.Temperature
|
||||
}
|
||||
if defaultMaxTokens == 0 {
|
||||
defaultMaxTokens = h.config.Conversation.Summary.MaxTokens
|
||||
if defaultMaxCompletionTokens == 0 {
|
||||
defaultMaxCompletionTokens = h.config.Conversation.Summary.MaxCompletionTokens
|
||||
}
|
||||
defaultNoMatchPrefix = h.config.Conversation.Summary.NoMatchPrefix
|
||||
|
||||
@@ -262,8 +262,8 @@ func (h *Handler) fillSummaryConfigDefaults(ctx context.Context, config *types.S
|
||||
if config.Temperature == 0 {
|
||||
config.Temperature = defaultTemperature
|
||||
}
|
||||
if config.MaxTokens == 0 {
|
||||
config.MaxTokens = defaultMaxTokens
|
||||
if config.MaxCompletionTokens == 0 {
|
||||
config.MaxCompletionTokens = defaultMaxCompletionTokens
|
||||
}
|
||||
if config.NoMatchPrefix == "" {
|
||||
config.NoMatchPrefix = defaultNoMatchPrefix
|
||||
|
||||
@@ -463,7 +463,9 @@ func (h *Handler) handleKnowledgeQARequest(
|
||||
go func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
logger.ErrorWithFields(asyncCtx, errors.NewInternalServerError("Knowledge QA service panicked"), nil)
|
||||
buf := make([]byte, 10240)
|
||||
runtime.Stack(buf, true)
|
||||
logger.ErrorWithFields(asyncCtx, errors.NewInternalServerError(fmt.Sprintf("Knowledge QA service panicked: %v\n%s", r, string(buf))), nil)
|
||||
}
|
||||
}()
|
||||
err := h.sessionService.KnowledgeQA(asyncCtx, session, query, knowledgeBaseIDs, assistantMessage.ID, summaryModelID, webSearchEnabled, eventBus)
|
||||
|
||||
+58
-52
@@ -233,15 +233,16 @@ func (h *TenantHandler) ListTenants(c *gin.Context) {
|
||||
|
||||
// AgentConfigRequest represents the request body for updating agent configuration
|
||||
type AgentConfigRequest struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
MaxIterations int `json:"max_iterations"`
|
||||
ReflectionEnabled bool `json:"reflection_enabled"`
|
||||
AllowedTools []string `json:"allowed_tools"`
|
||||
Temperature float64 `json:"temperature"`
|
||||
ThinkingModelID string `json:"thinking_model_id"`
|
||||
RerankModelID string `json:"rerank_model_id"`
|
||||
SystemPrompt string `json:"system_prompt,omitempty"` // System prompt template with placeholders (optional)
|
||||
UseCustomPrompt *bool `json:"use_custom_system_prompt"`
|
||||
Enabled bool `json:"enabled"`
|
||||
MaxIterations int `json:"max_iterations"`
|
||||
ReflectionEnabled bool `json:"reflection_enabled"`
|
||||
AllowedTools []string `json:"allowed_tools"`
|
||||
Temperature float64 `json:"temperature"`
|
||||
ThinkingModelID string `json:"thinking_model_id"`
|
||||
RerankModelID string `json:"rerank_model_id"`
|
||||
SystemPromptWebEnabled string `json:"system_prompt_web_enabled,omitempty"`
|
||||
SystemPromptWebDisabled string `json:"system_prompt_web_disabled,omitempty"`
|
||||
UseCustomPrompt *bool `json:"use_custom_system_prompt"`
|
||||
}
|
||||
|
||||
// GetTenantAgentConfig retrieves the agent configuration for a tenant
|
||||
@@ -282,46 +283,50 @@ func (h *TenantHandler) GetTenantAgentConfig(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"data": gin.H{
|
||||
"max_iterations": agent.DefaultAgentMaxIterations,
|
||||
"reflection_enabled": agent.DefaultAgentReflectionEnabled,
|
||||
"allowed_tools": agenttools.DefaultAllowedTools(),
|
||||
"temperature": agent.DefaultAgentTemperature,
|
||||
"thinking_model_id": "",
|
||||
"rerank_model_id": "",
|
||||
"system_prompt": agent.DefaultSystemPromptTemplate,
|
||||
"use_custom_system_prompt": false,
|
||||
"available_tools": availableTools,
|
||||
"available_placeholders": availablePlaceholders,
|
||||
"max_iterations": agent.DefaultAgentMaxIterations,
|
||||
"reflection_enabled": agent.DefaultAgentReflectionEnabled,
|
||||
"allowed_tools": agenttools.DefaultAllowedTools(),
|
||||
"temperature": agent.DefaultAgentTemperature,
|
||||
"thinking_model_id": "",
|
||||
"rerank_model_id": "",
|
||||
"system_prompt_web_enabled": agent.ProgressiveRAGSystemPromptWithWeb,
|
||||
"system_prompt_web_disabled": agent.ProgressiveRAGSystemPromptWithoutWeb,
|
||||
"use_custom_system_prompt": false,
|
||||
"available_tools": availableTools,
|
||||
"available_placeholders": availablePlaceholders,
|
||||
},
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Get system prompt, use default if empty
|
||||
systemPrompt := tenant.AgentConfig.SystemPrompt
|
||||
// Get system prompts for both web search states, use defaults if empty
|
||||
systemPromptWithWeb := tenant.AgentConfig.ResolveSystemPrompt(true)
|
||||
if systemPromptWithWeb == "" {
|
||||
systemPromptWithWeb = agent.ProgressiveRAGSystemPromptWithWeb
|
||||
}
|
||||
systemPromptWithoutWeb := tenant.AgentConfig.ResolveSystemPrompt(false)
|
||||
if systemPromptWithoutWeb == "" {
|
||||
systemPromptWithoutWeb = agent.ProgressiveRAGSystemPromptWithoutWeb
|
||||
}
|
||||
|
||||
useCustomPrompt := tenant.AgentConfig.UseCustomSystemPrompt
|
||||
if !useCustomPrompt && systemPrompt != "" && systemPrompt != agent.DefaultSystemPromptTemplate {
|
||||
useCustomPrompt = true
|
||||
}
|
||||
if systemPrompt == "" {
|
||||
systemPrompt = agent.DefaultSystemPromptTemplate
|
||||
}
|
||||
|
||||
logger.Infof(ctx, "Retrieved tenant agent config successfully, Tenant ID: %d", tenant.ID)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"data": gin.H{
|
||||
"enabled": tenant.AgentConfig.Enabled,
|
||||
"max_iterations": tenant.AgentConfig.MaxIterations,
|
||||
"reflection_enabled": tenant.AgentConfig.ReflectionEnabled,
|
||||
"allowed_tools": tenant.AgentConfig.AllowedTools,
|
||||
"temperature": tenant.AgentConfig.Temperature,
|
||||
"thinking_model_id": tenant.AgentConfig.ThinkingModelID,
|
||||
"rerank_model_id": tenant.AgentConfig.RerankModelID,
|
||||
"system_prompt": systemPrompt,
|
||||
"use_custom_system_prompt": useCustomPrompt,
|
||||
"available_tools": availableTools,
|
||||
"available_placeholders": availablePlaceholders,
|
||||
"enabled": tenant.AgentConfig.Enabled,
|
||||
"max_iterations": tenant.AgentConfig.MaxIterations,
|
||||
"reflection_enabled": tenant.AgentConfig.ReflectionEnabled,
|
||||
"allowed_tools": tenant.AgentConfig.AllowedTools,
|
||||
"temperature": tenant.AgentConfig.Temperature,
|
||||
"thinking_model_id": tenant.AgentConfig.ThinkingModelID,
|
||||
"rerank_model_id": tenant.AgentConfig.RerankModelID,
|
||||
"system_prompt_web_enabled": systemPromptWithWeb,
|
||||
"system_prompt_web_disabled": systemPromptWithoutWeb,
|
||||
"use_custom_system_prompt": useCustomPrompt,
|
||||
"available_tools": availableTools,
|
||||
"available_placeholders": availablePlaceholders,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -368,15 +373,16 @@ func (h *TenantHandler) updateTenantAgentConfigInternal(c *gin.Context) {
|
||||
}
|
||||
|
||||
tenant.AgentConfig = &types.AgentConfig{
|
||||
Enabled: req.Enabled,
|
||||
MaxIterations: req.MaxIterations,
|
||||
ReflectionEnabled: req.ReflectionEnabled,
|
||||
AllowedTools: req.AllowedTools,
|
||||
Temperature: req.Temperature,
|
||||
ThinkingModelID: req.ThinkingModelID,
|
||||
RerankModelID: req.RerankModelID,
|
||||
SystemPrompt: req.SystemPrompt,
|
||||
UseCustomSystemPrompt: useCustomPrompt,
|
||||
Enabled: req.Enabled,
|
||||
MaxIterations: req.MaxIterations,
|
||||
ReflectionEnabled: req.ReflectionEnabled,
|
||||
AllowedTools: req.AllowedTools,
|
||||
Temperature: req.Temperature,
|
||||
ThinkingModelID: req.ThinkingModelID,
|
||||
RerankModelID: req.RerankModelID,
|
||||
SystemPromptWebEnabled: req.SystemPromptWebEnabled,
|
||||
SystemPromptWebDisabled: req.SystemPromptWebDisabled,
|
||||
UseCustomSystemPrompt: useCustomPrompt,
|
||||
}
|
||||
|
||||
updatedTenant, err := h.service.UpdateTenant(ctx, tenant)
|
||||
@@ -517,7 +523,7 @@ func (h *TenantHandler) buildDefaultConversationConfig() *types.ConversationConf
|
||||
UseCustomContextTemplate: true,
|
||||
UseCustomSystemPrompt: true,
|
||||
Temperature: h.config.Conversation.Summary.Temperature,
|
||||
MaxTokens: h.config.Conversation.Summary.MaxTokens,
|
||||
MaxCompletionTokens: h.config.Conversation.Summary.MaxCompletionTokens,
|
||||
MaxRounds: h.config.Conversation.MaxRounds,
|
||||
EmbeddingTopK: h.config.Conversation.EmbeddingTopK,
|
||||
KeywordThreshold: h.config.Conversation.KeywordThreshold,
|
||||
@@ -555,8 +561,8 @@ func validateConversationConfig(req *types.ConversationConfig) error {
|
||||
if req.Temperature < 0 || req.Temperature > 2 {
|
||||
return errors.NewBadRequestError("temperature must be between 0 and 2")
|
||||
}
|
||||
if req.MaxTokens <= 0 || req.MaxTokens > 100000 {
|
||||
return errors.NewBadRequestError("max_tokens must be between 1 and 100000")
|
||||
if req.MaxCompletionTokens <= 0 || req.MaxCompletionTokens > 100000 {
|
||||
return errors.NewBadRequestError("max_completion_tokens must be between 1 and 100000")
|
||||
}
|
||||
if req.FallbackStrategy != "" &&
|
||||
req.FallbackStrategy != string(types.FallbackStrategyFixed) &&
|
||||
@@ -609,8 +615,8 @@ func (h *TenantHandler) GetTenantConversationConfig(c *gin.Context) {
|
||||
if tc.Temperature > 0 {
|
||||
defaultCfg.Temperature = tc.Temperature
|
||||
}
|
||||
if tc.MaxTokens > 0 {
|
||||
defaultCfg.MaxTokens = tc.MaxTokens
|
||||
if tc.MaxCompletionTokens > 0 {
|
||||
defaultCfg.MaxCompletionTokens = tc.MaxCompletionTokens
|
||||
}
|
||||
|
||||
// Retrieval parameters
|
||||
|
||||
Reference in New Issue
Block a user