feat(prompt): enhance context and intent classification in templates

- Updated context template to include runtime metadata such as current time and week, improving contextual awareness in user queries.
- Enhanced rewrite template with critical instructions for intent classification, ensuring that rewritten questions preserve essential entities and keywords.
- Refined intent classification logic to prioritize user intents more effectively, improving the accuracy of responses based on user queries.
- Added examples to clarify expected input and output formats for intent classification, enhancing usability for developers.
This commit is contained in:
wizardchen
2026-03-26 16:45:51 +08:00
committed by lyingbug
parent 27d4525ba9
commit 72dfb9ce75
44 changed files with 451 additions and 135 deletions
@@ -65,7 +65,11 @@ func prepareMessagesWithHistory(chatManage *types.ChatManage) []chat.Message {
if chatManage.SystemPromptOverride != "" {
base = chatManage.SystemPromptOverride
}
systemPrompt := renderSystemPromptPlaceholders(base, chatManage.Language)
systemPrompt := types.RenderPromptPlaceholders(base, types.PlaceholderValues{
"query": chatManage.Query,
"language": chatManage.Language,
"contexts": chatManage.RenderedContexts,
})
chatMessages := []chat.Message{
{Role: "system", Content: systemPrompt},
@@ -110,9 +114,13 @@ func loadAndProcessHistory(
h = &types.History{}
}
if message.Role == "user" {
h.Query = message.Content
if message.RenderedContent != "" {
h.Query = message.RenderedContent
} else {
h.Query = message.Content
}
h.CreateAt = message.CreatedAt
if desc := extractImageCaptions(message.Images); desc != "" {
if desc := extractImageCaptions(message.Images); desc != "" && message.RenderedContent == "" {
h.Query += "\n\n[用户上传图片内容]\n" + desc
}
} else {
@@ -154,18 +162,6 @@ func extractImageCaptions(images types.MessageImages) string {
return strings.Join(parts, "\n")
}
// renderSystemPromptPlaceholders replaces placeholders in system prompt
// Supported placeholders:
// - {{current_time}} -> current time in RFC3339 format
// - {{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 types.RenderPromptPlaceholders(prompt, vals)
}
// ---------------------------------------------------------------------------
// Concurrency utilities
// ---------------------------------------------------------------------------