446f865cdf
- Implemented KnowledgeHandler for managing knowledge groups and items, including listing, creating, updating, and deleting operations. - Added database migration scripts to create necessary tables for knowledge management, including knowledge_groups, knowledge_items, knowledge_parse_tasks, and knowledge_chunks_meta. - Introduced prompt_rule_knowledge_groups table to associate prompt rules with knowledge groups.
77 lines
2.3 KiB
Go
77 lines
2.3 KiB
Go
package app
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestBuildPromptContextUsesChineseLabels(t *testing.T) {
|
|
context := buildPromptContext(map[string]interface{}{
|
|
"locale": "zh-CN",
|
|
"title": "测试标题",
|
|
"brand_name": "Rankly",
|
|
"primary_keyword": "GEO 排名",
|
|
"outline_sections": []string{"引言", "结论"},
|
|
})
|
|
|
|
for _, expected := range []string{
|
|
"- 语言: zh-CN",
|
|
"- 标题: 测试标题",
|
|
"- 品牌名: Rankly",
|
|
"- 核心关键词: GEO 排名",
|
|
"- 已选段落: 引言 > 结论",
|
|
} {
|
|
if !strings.Contains(context, expected) {
|
|
t.Fatalf("buildPromptContext() = %q, want %q", context, expected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBuildGenerationLengthGuidanceForEnglishLocaleIsWrittenInChinese(t *testing.T) {
|
|
guidance := buildGenerationLengthGuidance(map[string]interface{}{
|
|
"locale": "en-US",
|
|
"outline_sections": []string{"Intro", "Section 1", "Section 2"},
|
|
})
|
|
|
|
for _, unexpected := range []string{
|
|
"Intro and conclusion should stay concise",
|
|
"If one paragraph can make the point clearly",
|
|
"English words",
|
|
} {
|
|
if strings.Contains(guidance, unexpected) {
|
|
t.Fatalf("buildGenerationLengthGuidance() = %q, contains unexpected English prompt text %q", guidance, unexpected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBuildGenerationPromptAddsTopXBrandPriorityRules(t *testing.T) {
|
|
prompt := buildGenerationPrompt("top_x_article", "Top X 推荐文章", nil, map[string]interface{}{
|
|
"topic": "合肥全屋定制",
|
|
"brand_name": "安徽海翔家居用品销售有限公司",
|
|
"locale": "zh-CN",
|
|
}, "")
|
|
|
|
for _, expected := range []string{
|
|
"模板专项要求:",
|
|
"安徽海翔家居用品销售有限公司",
|
|
"排在第 1 位",
|
|
"篇幅应明显多于其他对象",
|
|
"结论部分先明确推荐",
|
|
} {
|
|
if !strings.Contains(prompt, expected) {
|
|
t.Fatalf("buildGenerationPrompt() = %q, want %q", prompt, expected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBuildGenerationPromptDoesNotAddTopXBrandRulesForOtherTemplates(t *testing.T) {
|
|
prompt := buildGenerationPrompt("product_review", "产品评测", nil, map[string]interface{}{
|
|
"product_name": "测试产品",
|
|
"brand_name": "安徽海翔家居用品销售有限公司",
|
|
}, "")
|
|
|
|
if strings.Contains(prompt, "排在第 1 位") {
|
|
t.Fatalf("buildGenerationPrompt() = %q, should not include top-x ranking rules", prompt)
|
|
}
|
|
}
|