feat: load question expansion prompts from yaml
This commit is contained in:
@@ -34,6 +34,8 @@ type runtimePromptsConfig struct {
|
||||
JSONOutputExampleHeading string `yaml:"json_output_example_heading"`
|
||||
AnalyzeOutputExample string `yaml:"analyze_output_example"`
|
||||
AnalyzeFallbackPromptTemplate string `yaml:"analyze_fallback_prompt_template"`
|
||||
QuestionDistillPromptTemplate string `yaml:"question_distill_prompt_template"`
|
||||
QuestionCombinationFillPromptTemplate string `yaml:"question_combination_fill_prompt_template"`
|
||||
TitleCustomOutputRequirementsSection string `yaml:"title_custom_output_requirements_section"`
|
||||
TitleOutputExample string `yaml:"title_output_example"`
|
||||
TitleFallbackPromptTemplate string `yaml:"title_fallback_prompt_template"`
|
||||
|
||||
@@ -66,16 +66,48 @@ func TestAnalyzeFallbackPromptPrefersQuestionLikeQueries(t *testing.T) {
|
||||
|
||||
prompt := AnalyzeFallbackPrompt(`{"brand_name":"测试品牌","input_params":{"keyword":"全屋定制"}}`)
|
||||
for _, want := range []string{
|
||||
"真实用户会直接搜索的问题型长尾词",
|
||||
"哪家好",
|
||||
"最多返回 6 个竞品和 10 个搜索问题候选",
|
||||
} {
|
||||
"真实用户会直接搜索的问题型长尾词",
|
||||
"哪家好",
|
||||
"最多返回 6 个竞品和 10 个搜索问题候选",
|
||||
} {
|
||||
if !strings.Contains(prompt, want) {
|
||||
t.Fatalf("AnalyzeFallbackPrompt() missing %q in prompt:\n%s", want, prompt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestQuestionExpansionPromptsLoadFromYaml(t *testing.T) {
|
||||
SetConfigFile("")
|
||||
t.Cleanup(func() {
|
||||
SetConfigFile("")
|
||||
})
|
||||
|
||||
distillPrompt := QuestionDistillPrompt("测试品牌", `["竞品A"]`, "全屋定制")
|
||||
for _, want := range []string{
|
||||
"AI 搜索里真实会问的问题",
|
||||
"当前品牌: 测试品牌",
|
||||
`竞品列表: ["竞品A"]`,
|
||||
"主题: 全屋定制",
|
||||
} {
|
||||
if !strings.Contains(distillPrompt, want) {
|
||||
t.Fatalf("QuestionDistillPrompt() missing %q in prompt:\n%s", want, distillPrompt)
|
||||
}
|
||||
}
|
||||
|
||||
fillPrompt := QuestionCombinationFillPrompt("测试品牌", "https://example.com", "品牌描述", `["竞品A"]`, "合肥、华东", `{"core":["装修"]}`)
|
||||
for _, want := range []string{
|
||||
"拓词工具",
|
||||
"品牌: 测试品牌",
|
||||
"官网: https://example.com",
|
||||
"合肥、华东",
|
||||
`{"core":["装修"]}`,
|
||||
} {
|
||||
if !strings.Contains(fillPrompt, want) {
|
||||
t.Fatalf("QuestionCombinationFillPrompt() missing %q in prompt:\n%s", want, fillPrompt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPromptConfigReloadsAndKeepsLastGoodVersion(t *testing.T) {
|
||||
SetConfigFile("")
|
||||
defaultPath := resolvePromptsConfigFile()
|
||||
|
||||
@@ -69,6 +69,27 @@ func AnalyzeFallbackPrompt(contextJSON string) string {
|
||||
))
|
||||
}
|
||||
|
||||
func QuestionDistillPrompt(brandName, competitors, seedTopic string) string {
|
||||
return strings.TrimSpace(fmt.Sprintf(
|
||||
trimPrompt(loadRuntimePrompts().QuestionDistillPromptTemplate),
|
||||
strings.TrimSpace(brandName),
|
||||
strings.TrimSpace(competitors),
|
||||
strings.TrimSpace(seedTopic),
|
||||
))
|
||||
}
|
||||
|
||||
func QuestionCombinationFillPrompt(brandName, website, description, competitors, regionTerms, currentInput string) string {
|
||||
return strings.TrimSpace(fmt.Sprintf(
|
||||
trimPrompt(loadRuntimePrompts().QuestionCombinationFillPromptTemplate),
|
||||
strings.TrimSpace(brandName),
|
||||
strings.TrimSpace(website),
|
||||
strings.TrimSpace(description),
|
||||
strings.TrimSpace(competitors),
|
||||
strings.TrimSpace(regionTerms),
|
||||
strings.TrimSpace(currentInput),
|
||||
))
|
||||
}
|
||||
|
||||
func TitleCustomOutputRequirementsSection() string {
|
||||
return trimPrompt(loadRuntimePrompts().TitleCustomOutputRequirementsSection)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user