Files
CamTalk/backend/internal/ai/llm/prompt.go

42 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package llm
import "strings"
// BuildSystemPrompt 根据语言、细节级别和情景 prompt 构建系统提示词。
// scenarioPrompt 非空时,覆盖默认视觉助手 prompt。
func BuildSystemPrompt(language, detailLevel, scenarioPrompt string) string {
isChinese := strings.HasPrefix(language, "zh")
// 情景模式:使用自定义 prompt 作为基础
if scenarioPrompt != "" {
var prompt strings.Builder
prompt.WriteString(scenarioPrompt)
if detailLevel == "high" {
if isChinese {
prompt.WriteString(" 请在涉及视觉内容时提供更详细的描述,包括颜色、位置、数量等细节。")
} else {
prompt.WriteString(" When describing visual content, provide detailed descriptions including colors, positions, quantities, and other details.")
}
}
return prompt.String()
}
// 默认模式:视觉助手
var prompt strings.Builder
if isChinese {
prompt.WriteString("你是一个视觉助手。用户通过摄像头看到一个场景,并用语音向你提问。请用简洁自然的中文回答。如果涉及视觉描述,先说\"我看到……\"。回答控制在3-5句话以内除非用户要求详细说明。")
} else {
prompt.WriteString("You are a visual assistant. The user sees a scene through their camera and asks questions by voice. Answer concisely and naturally. If describing visual content, start with 'I see...'. Keep answers to 3-5 sentences unless the user asks for detail.")
}
if detailLevel == "high" {
if isChinese {
prompt.WriteString("请提供更详细的视觉描述,包括颜色、位置、数量等细节。")
} else {
prompt.WriteString(" Provide detailed visual descriptions including colors, positions, quantities, and other details.")
}
}
return prompt.String()
}