feat: Enhance article generation and outline handling
- Added support for external markdown synchronization in ArticleEditorCanvas.vue. - Implemented a new function to sync markdown from props, ensuring the editor reflects external changes. - Introduced a removeOutlineSection function in TemplateWizardView.vue to manage outline sections dynamically. - Updated UI components to improve user experience, including replacing a-input with a-textarea for better text handling. - Refactored CSS styles for a cleaner layout and improved responsiveness in TemplateWizardView.vue. - Enhanced LLM generation requests to include response format options in ark.go and client.go. - Updated template assist logic to enforce structured outline outputs in template_assist.go. - Added tests for outline result decoding and prompt generation to ensure robustness. - Created migration scripts to update prompt templates with new writing requirements for top X articles.
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user