feat: enhance localization and configuration support

- Added timezone and language settings to the environment configuration.
- Introduced built-in agent configurations with multilingual support for various agents.
- Updated Docker Compose to utilize new environment variables for timezone and language.
- Created new prompt templates for question generation, summary generation, and keywords extraction.
This commit is contained in:
wizardchen
2026-03-17 15:33:19 +08:00
committed by lyingbug
parent 09d9fe5ddb
commit 139a9c40ff
54 changed files with 2524 additions and 1482 deletions
@@ -3,7 +3,6 @@ package chatpipline
import (
"context"
"strings"
"time"
"github.com/Tencent/WeKnora/internal/common"
"github.com/Tencent/WeKnora/internal/logger"
@@ -55,7 +54,7 @@ func prepareChatModel(ctx context.Context, modelService interfaces.ModelService,
// prepareMessagesWithHistory prepare complete messages including history
func prepareMessagesWithHistory(chatManage *types.ChatManage) []chat.Message {
// Replace placeholders in system prompt
systemPrompt := renderSystemPromptPlaceholders(chatManage.SummaryConfig.Prompt)
systemPrompt := renderSystemPromptPlaceholders(chatManage.SummaryConfig.Prompt, chatManage.Language)
chatMessages := []chat.Message{
{Role: "system", Content: systemPrompt},
@@ -94,14 +93,11 @@ func extractImageCaptions(images types.MessageImages) string {
// renderSystemPromptPlaceholders replaces placeholders in system prompt
// Supported placeholders:
// - {{current_time}} -> current time in RFC3339 format
func renderSystemPromptPlaceholders(prompt string) string {
result := prompt
// Replace {{current_time}} placeholder
if strings.Contains(result, "{{current_time}}") {
currentTime := time.Now().Format(time.RFC3339)
result = strings.ReplaceAll(result, "{{current_time}}", currentTime)
// - {{language}} -> user language name (replaced if present; empty string if not set in ChatManage)
func renderSystemPromptPlaceholders(prompt string, language ...string) string {
vals := types.PlaceholderValues{}
if len(language) > 0 {
vals["language"] = language[0]
}
return result
return types.RenderPromptPlaceholders(prompt, vals)
}
@@ -6,7 +6,6 @@ import (
"fmt"
"regexp"
"strings"
"time"
"github.com/Tencent/WeKnora/internal/types"
"github.com/Tencent/WeKnora/internal/utils"
@@ -74,9 +73,6 @@ func (p *PluginIntoChatMessage) OnEvent(ctx context.Context,
return ErrTemplateExecute.WithError(fmt.Errorf("user query contains invalid content"))
}
// Prepare weekday names
weekdayName := []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
// Intent-based no-search path: bypass "reference materials" template entirely.
if chatManage.SkipKBSearch {
// Prefer rewritten query in no-search mode; fallback to original query.
@@ -140,11 +136,11 @@ func (p *PluginIntoChatMessage) OnEvent(ctx context.Context,
}
// Replace placeholders in context template
userContent := chatManage.SummaryConfig.ContextTemplate
userContent = strings.ReplaceAll(userContent, "{{query}}", safeQuery)
userContent = strings.ReplaceAll(userContent, "{{contexts}}", contextsBuilder.String())
userContent = strings.ReplaceAll(userContent, "{{current_time}}", time.Now().Format("2006-01-02 15:04:05"))
userContent = strings.ReplaceAll(userContent, "{{current_week}}", weekdayName[time.Now().Weekday()])
userContent := types.RenderPromptPlaceholders(chatManage.SummaryConfig.ContextTemplate, types.PlaceholderValues{
"query": safeQuery,
"contexts": contextsBuilder.String(),
"language": chatManage.Language,
})
// Append image description as text fallback only when the chat model cannot
// process images directly. Vision-capable models see images via MultiContent.
@@ -354,18 +354,15 @@ func (p *PluginRewrite) buildPrompts(chatManage *types.ChatManage, historyList [
}
conversationText := formatConversationHistory(historyList)
currentTime := time.Now().Format("2006-01-02 15:04:05")
yesterday := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
replacePlaceholders := func(s string) string {
s = strings.ReplaceAll(s, "{{conversation}}", conversationText)
s = strings.ReplaceAll(s, "{{query}}", chatManage.Query)
s = strings.ReplaceAll(s, "{{current_time}}", currentTime)
s = strings.ReplaceAll(s, "{{yesterday}}", yesterday)
return s
vals := types.PlaceholderValues{
"conversation": conversationText,
"query": chatManage.Query,
"language": chatManage.Language,
}
return replacePlaceholders(systemPrompt), replacePlaceholders(userPrompt)
return types.RenderPromptPlaceholders(systemPrompt, vals),
types.RenderPromptPlaceholders(userPrompt, vals)
}
// parseRewriteOutput extracts intent classification, rewritten query, and