feat(prompts): expand keyword guidance to long-tail search queries
Tighten the analyze prompts (runtime + recommendation platform) so the model returns 8-10 question-style search queries (哪家好/有哪些/怎么选/ 价格/排名/避坑 …) instead of generic tag words, and lift the keyword cap in normalizeAnalyzeResult from 5 to 10 to keep them. Add tests covering the new ten-keyword window and the question-like guidance in the seeded analyze prompt. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1156,7 +1156,7 @@ func extractBalancedJSONFragment(input string) (string, bool) {
|
||||
|
||||
func normalizeAnalyzeResult(result AnalyzeTaskResult) AnalyzeTaskResult {
|
||||
result.BrandSummary = strings.TrimSpace(result.BrandSummary)
|
||||
result.Keywords = normalizeStringList(result.Keywords, 5)
|
||||
result.Keywords = normalizeStringList(result.Keywords, 10)
|
||||
result.Competitors = normalizeAssistCompetitors(result.Competitors, 6)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -63,3 +63,33 @@ func TestBuildOutlinePromptForConfiguredTemplateForcesOutlineObject(t *testing.T
|
||||
t.Fatalf("buildOutlinePrompt() = %q, want pure-array prohibition", prompt)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeAnalyzeResultKeepsTenQueryKeywords(t *testing.T) {
|
||||
input := AnalyzeTaskResult{
|
||||
BrandSummary: " 全屋定制服务摘要 ",
|
||||
Keywords: []string{
|
||||
"全屋定制",
|
||||
"全屋定制哪家好",
|
||||
"靠谱的全屋定制品牌有哪些",
|
||||
"口碑好的全屋定制公司推荐",
|
||||
"性价比高的全屋定制怎么选",
|
||||
"专业的全屋定制设计公司哪家好",
|
||||
"全屋定制和木工打柜子哪个更划算",
|
||||
"全屋定制一般多少钱一平米",
|
||||
"全屋定制常用的板材哪种环保",
|
||||
"全屋定制十大品牌排名最新",
|
||||
"全屋定制需要注意哪些坑",
|
||||
},
|
||||
}
|
||||
|
||||
result := normalizeAnalyzeResult(input)
|
||||
if result.BrandSummary != "全屋定制服务摘要" {
|
||||
t.Fatalf("BrandSummary = %q, want trimmed summary", result.BrandSummary)
|
||||
}
|
||||
if got, want := len(result.Keywords), 10; got != want {
|
||||
t.Fatalf("len(Keywords) = %d, want %d: %#v", got, want, result.Keywords)
|
||||
}
|
||||
if result.Keywords[9] != "全屋定制十大品牌排名最新" {
|
||||
t.Fatalf("Keywords[9] = %q, want the tenth query retained", result.Keywords[9])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,9 @@ func TestPlatformTemplateSeedsInjectPromptConfig(t *testing.T) {
|
||||
if !strings.Contains(analyzePrompt, "推荐类文章做品牌与竞品分析") {
|
||||
t.Fatalf("analyze_prompt_template = %q, want yaml-backed analyze prompt", analyzePrompt)
|
||||
}
|
||||
if !strings.Contains(analyzePrompt, "全屋定制哪家好") || !strings.Contains(analyzePrompt, "搜索查询词") {
|
||||
t.Fatalf("analyze_prompt_template = %q, want question-like long-tail query guidance", analyzePrompt)
|
||||
}
|
||||
if !strings.Contains(titlePrompt, "推荐类文章生成 5 个候选标题") {
|
||||
t.Fatalf("title_prompt_template = %q, want yaml-backed title prompt", titlePrompt)
|
||||
}
|
||||
@@ -55,6 +58,24 @@ func TestPlatformTemplateSeedsInjectPromptConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnalyzeFallbackPromptPrefersQuestionLikeQueries(t *testing.T) {
|
||||
SetConfigFile("")
|
||||
t.Cleanup(func() {
|
||||
SetConfigFile("")
|
||||
})
|
||||
|
||||
prompt := AnalyzeFallbackPrompt(`{"brand_name":"测试品牌","input_params":{"keyword":"全屋定制"}}`)
|
||||
for _, want := range []string{
|
||||
"真实用户会直接搜索的问题型长尾词",
|
||||
"哪家好",
|
||||
"最多返回 6 个竞品和 10 个关键词",
|
||||
} {
|
||||
if !strings.Contains(prompt, want) {
|
||||
t.Fatalf("AnalyzeFallbackPrompt() missing %q in prompt:\n%s", want, prompt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPromptConfigReloadsAndKeepsLastGoodVersion(t *testing.T) {
|
||||
SetConfigFile("")
|
||||
defaultPath := resolvePromptsConfigFile()
|
||||
|
||||
Reference in New Issue
Block a user