This commit is contained in:
greeneclipse committed 2026-10-14 19:23:16 +02:00
1 parent ff6c2df618
commit 43cfaa0411
18 files changed
+683 -299

No files matched your search

@@ -23,7 +23,7 @@ Rules:
- Schema: {"name":"string","description":"string","meta_title":"string","meta_description":"string","attrs":{}}
- Obey the GPT predloga in the user message step by step
- "name" follows the <name> Title formula — never copy Staro_ime_izdelka unchanged when the formula asks for a new name
- "description" is ONE HTML string covering each GPT predloga body section in order (tags matching type: h1/h2/h3/h4, p, ul) — do NOT wrap the reply in <name> or <metaDescription> tags
- "description" is ONE HTML string covering required GPT predloga body sections in order; skip optional sections if unsupported (tags matching type: h1/h2/h3/h4, p, ul) — do NOT wrap the reply in <name> or <metaDescription> tags
- "meta_title" and "meta_description" are plain SEO text from the meta / <metaDescription> formula (never HTML body)
- attrs: only Allowed attribute keys when listed; fill from evidence only; omit unknowns
{{brand_voice}}`
@@ -36,7 +36,7 @@ Rules:
- Schema: {"name":"string","description":"string","meta_title":"string","meta_description":"string","attrs":{}}
- Obey the product template in the user message step by step
- "name" follows the <name> formula — never copy Old_product_name unchanged when the formula asks for a new name
- "description" is ONE HTML string covering each product template body section in order (tags matching type: h1/h2/h3/h4, p, ul) — do NOT wrap the reply in <name> or <metaDescription> tags
- "description" is ONE HTML string covering required template sections in order; skip optional sections if unsupported (tags matching type: h1/h2/h3/h4, p, ul) — do NOT wrap the reply in <name> or <metaDescription> tags
- "meta_title" and "meta_description" are plain SEO text from the meta / <metaDescription> formula (never HTML body)
- Use only the supplied Old_product_name, Old_product_description, Category and Attrs as facts; never invent specifications
- attrs: only Allowed attribute keys when listed; fill from evidence only; omit unknowns
@@ -112,10 +112,10 @@ func buildA1StyleEnhanceUserTemplate(catPrompt string, titleTemplate, descriptio
var predloga strings.Builder
if titleInstr != "" {
fmt.Fprintf(&predloga, "<name>{%s}</name>\n", collapseLegacyInstr(titleInstr))
fmt.Fprintf(&predloga, "<name>{%s}</name>\n", unwrapCategoryInstruction(titleInstr))
}
if !omitSEOMeta && metaInstr != "" {
fmt.Fprintf(&predloga, "<metaDescription>{%s}</metaDescription>\n", collapseLegacyInstr(metaInstr))
fmt.Fprintf(&predloga, "<metaDescription>{%s}</metaDescription>\n", unwrapCategoryInstruction(metaInstr))
}
if descBody != "" {
predloga.WriteString(strings.TrimSpace(descBody))
@@ -216,6 +216,14 @@ var a1StyleLabelsEN = a1StyleLabels{
// by {{language}} in the system prompt either way.
var reSlovenianFormulaCue = regexp.MustCompile(`(?i)novo[ _]ime[ _]izdelka|napiši|napisi|izpostavi|izdelka|znamka`)
func unwrapCategoryInstruction(s string) string {
s = collapseLegacyInstr(s)
if strings.HasPrefix(s, "{") && strings.HasSuffix(s, "}") && !strings.HasPrefix(s, "{{") {
return strings.TrimSpace(s[1 : len(s)-1])
}
return s
}
func collapseLegacyInstr(s string) string {
s = strings.TrimSpace(s)
s = strings.ReplaceAll(s, "\r\n", "\n")
@@ -243,7 +251,7 @@ func FormatDescriptionFormulaAsLegacyHTML(template any) string {
case "h1", "h2", "h3", "h4":
fmt.Fprintf(&b, "<%s>{%s}</%s>", strings.ToUpper(typ), instr, strings.ToUpper(typ))
case "ul", "ol", "li":
fmt.Fprintf(&b, "<b>{Tehnične specifikacije}</b><ul><li>{%s}</li></ul>", instr)
fmt.Fprintf(&b, "<ul><li>{%s}</li></ul>", instr)
case "p", "":
fmt.Fprintf(&b, "<p>{%s}</p>", instr)
default:
+11 -8
View File
@@ -243,14 +243,14 @@ func FormatMetaFormulaConstraint(template any) string {
b.WriteString("SEO meta formula (REQUIRED — distinct from description HTML; plain text only):\n")
b.WriteString("Emit meta_title and meta_description as separate JSON fields in {{language}}.\n")
if metaTitle != "" {
fmt.Fprintf(&b, "- meta_title (50-60 chars): %s\n", metaTitle)
fmt.Fprintf(&b, "- meta_title (concise and distinctive; typically 50–60 characters when natural): %s\n", metaTitle)
} else {
b.WriteString("- meta_title: 50-60 chars, product name + main benefit or use case\n")
b.WriteString("- meta_title: product name + confirmed characteristic, concise and unique\n")
}
if metaDesc != "" {
fmt.Fprintf(&b, "- meta_description (120-155 chars): %s\n", metaDesc)
fmt.Fprintf(&b, "- meta_description (factual, 155 characters maximum; shorter with sparse data): %s\n", metaDesc)
} else {
b.WriteString("- meta_description: 120-155 chars, factual SEO snippet; never HTML\n")
b.WriteString("- meta_description: factual SEO snippet up to 155 characters; never HTML\n")
}
return strings.TrimSpace(b.String())
}
@@ -265,7 +265,7 @@ func FormatDescriptionFormulaConstraint(template any) string {
var b strings.Builder
b.WriteString("Description formula (REQUIRED — overrides any shorter \"1-2 sentences\" rule):\n")
b.WriteString("Emit description as ONE HTML string covering each section in order in {{language}}.\n")
b.WriteString("Use tags matching section type: h1/h2/h3/h4 → <hN>…</hN>, p → <p>…</p>, ul → <ul><li>…</li></ul>.\n")
b.WriteString("Use semantic product-detail HTML only: p → <p>…</p>, h2 → <h2>…</h2>, ul → <ul><li>…</li></ul>. No H1, no product-title duplicate. Skip optional feature/specification blocks when evidence does not support them; never emit empty elements.\n")
for _, s := range sections {
typ := strings.TrimSpace(s.Type)
instr := strings.TrimSpace(s.Instructions)
@@ -279,7 +279,7 @@ func FormatDescriptionFormulaConstraint(template any) string {
fmt.Fprintf(&b, "- %s\n", typ)
continue
}
fmt.Fprintf(&b, "- %s: %s\n", typ, instr)
fmt.Fprintf(&b, "- %s%s: %s\n", typ, map[bool]string{true: " (optional when no sourced facts)", false: ""}[s.Optional], instr)
}
return strings.TrimSpace(b.String())
}
@@ -287,7 +287,7 @@ func FormatDescriptionFormulaConstraint(template any) string {
// descriptionFormulaSystemOverride is appended to the enhance system template when a
// category description_template is present so company/built-in "1-2 sentences" rules
// cannot override the per-category formula (A1 category definition pages).
const descriptionFormulaSystemOverride = `When the user message includes a "Description formula", obey those sections over any shorter "1-2 sentences" / "1-3 paragraphs" guidance: emit one HTML string using tags matching each section type (h1/h2/h3/h4, p, ul), in order, in {{language}}. Never ignore the Description formula.`
const descriptionFormulaSystemOverride = `When the user message includes a "Description formula", obey those sections over any shorter "1-2 sentences" / "1-3 paragraphs" guidance: emit one HTML string using all REQUIRED sections, omitting OPTIONAL ones when no verified facts exist; use tags matching each section type (h1/h2/h3/h4, p, ul), in order, in {{language}}. Never ignore the Description formula.`
// AppendDescriptionFormulaSystemOverride strengthens the system prompt when a
// description formula is active. No-op when template is empty/unparseable.
@@ -406,7 +406,9 @@ func descriptionSatisfiesFormula(desc string, template any) bool {
}
types := make([]string, 0, len(sections))
for _, s := range sections {
types = append(types, s.Type)
if !s.Optional {
types = append(types, s.Type)
}
}
return !company.DescriptionMissingFormulaHTMLTags(desc, types)
}
@@ -419,6 +421,7 @@ type titleFormulaElement struct {
type descriptionFormulaSection struct {
Type string `json:"type"`
Instructions string `json:"instructions"`
Optional bool `json:"optional,omitempty"`
}
func parseTitleFormula(template any) (elements []titleFormulaElement, separator string, ok bool) {
@@ -324,3 +324,27 @@ func TestCategoryFormulasFor_explicitWins(t *testing.T) {
t.Fatal("expected cache formula")
}
}
func TestSEODefaultDescriptionOptionalBlocks(t *testing.T) {
t.Parallel()
tpl := map[string]any{"sections": []any{
map[string]any{"type": "p", "instructions": "Factual intro"},
map[string]any{"type": "h2", "instructions": "Documented benefit", "optional": true},
map[string]any{"type": "p", "instructions": "Benefit details", "optional": true},
map[string]any{"type": "h2", "instructions": "Technical specifications", "optional": true},
map[string]any{"type": "ul", "instructions": "Verified properties only", "optional": true},
}}
if !descriptionSatisfiesFormula("<p>A factual product introduction.</p>", tpl) {
t.Fatal("intro-only HTML must be valid if optional benefits and specs are absent")
}
if descriptionSatisfiesFormula("Only plain text, no HTML", tpl) {
t.Fatal("missing required introductory paragraph must be rejected")
}
if descriptionSatisfiesFormula("", tpl) {
t.Fatal("empty description must be rejected")
}
block := FormatDescriptionFormulaConstraint(tpl)
if !strings.Contains(block, "optional when no sourced facts") || !strings.Contains(block, "No H1") {
t.Fatalf("optional or semantic-HTML constraints missing: %s", block)
}
}
+48 -37
View File
@@ -758,7 +758,7 @@ func appendStepLog(gpt map[string]any, name string, raw any) {
// descriptionFormulaRetrySuffix is appended once when LLM JSON ignored the
// category description_template (short prose / title echo instead of multi-section HTML).
const descriptionFormulaRetrySuffix = "\n\nINVALID DESCRIPTION. Your JSON ignored the Description formula. Reply with ONLY one JSON object; \"description\" must be ONE HTML string covering each formula section in order with matching tags (h1/h2/h3/h4, p, ul)."
const descriptionFormulaRetrySuffix = "\n\nINVALID DESCRIPTION. Your JSON ignored the Description formula. Reply with ONLY one JSON object; \"description\" must be ONE HTML string covering every REQUIRED formula section in order with matching tags; optional feature/specification sections may be omitted when unsupported (h1/h2/h3/h4, p, ul)."
// titleRewriteRetrySuffix is appended when the Title role requires a new retail
// name but the model echoed the supplier Name unchanged.
@@ -1822,63 +1822,74 @@ func synthesizeDescriptionFromFormula(title, category, language string, attrs ma
if title == "" || title == "<nil>" || isPromptLabelTitle(title) {
return ""
}
dims := formatAttrDimPartsLang(attrs, 6, language)
intro := factualDescriptionIntro(title, category, language, attrs)
if intro == "" {
return ""
}
verified := formatAttrDimPartsLang(attrs, 6, language)
if len(verified) == 0 {
verified = factualSecondaryFacts(language, attrs)
}
// No verified attributes: output only the factual introduction. Never
// invent specifications or emit an HTML list with the introduction as an item.
if len(verified) == 0 {
return SanitizeOutput("<p>" + SanitizeOutput(intro) + "</p>")
}
var b strings.Builder
paraUsed := false
paragraphNumber := 0
headingNumber := 0
listUsed := false
headingLevels := map[string]bool{}
for _, s := range sections {
typ := strings.ToLower(strings.TrimSpace(s.Type))
for _, section := range sections {
typ := strings.ToLower(strings.TrimSpace(section.Type))
switch typ {
case "h1", "h2", "h3", "h4":
if headingLevels[typ] {
continue
}
headingLevels[typ] = true
heading := title
if typ != "h1" {
if isSlovenianContentLanguage(language) {
heading = "Ključne lastnosti"
} else {
heading = "Key features"
}
case "h2", "h3", "h4":
headingNumber++
heading := localizedFallbackFeaturesHeading(language)
if section.Optional || headingNumber > 1 {
heading = localizedFallbackSpecificationsHeading(language)
}
fmt.Fprintf(&b, "<%s>%s</%s>", typ, SanitizeOutput(heading), typ)
case "ul":
if listUsed {
continue
}
items := dims
if len(items) == 0 {
if secondary := factualSecondaryFacts(language, attrs); len(secondary) > 0 {
items = secondary
} else {
items = []string{intro}
}
}
b.WriteString("<ul>")
for _, it := range items {
fmt.Fprintf(&b, "<li>%s</li>", SanitizeOutput(it))
for _, item := range verified {
fmt.Fprintf(&b, "<li>%s</li>", SanitizeOutput(item))
}
b.WriteString("</ul>")
listUsed = true
default: // p and unknown → paragraph (once)
if paraUsed {
continue
case "p", "":
paragraphNumber++
if paragraphNumber == 1 {
fmt.Fprintf(&b, "<p>%s</p>", SanitizeOutput(intro))
} else if paragraphNumber == 2 {
fmt.Fprintf(&b, "<p>%s</p>", SanitizeOutput(strings.Join(verified, "; ")))
}
fmt.Fprintf(&b, "<p>%s</p>", SanitizeOutput(intro))
paraUsed = true
}
}
out := strings.TrimSpace(b.String())
if out == "" {
return ""
return SanitizeOutput(strings.TrimSpace(b.String()))
}
// These labels are used only when an AI call fails and a minimal factual HTML
// fallback must be produced. Normal generation follows the localized formulas.
func localizedFallbackFeaturesHeading(lang string) string {
labels := map[string]string{
"sl": "Ključne lastnosti", "hr": "Ključne značajke", "de": "Wichtige Merkmale", "fr": "Caractéristiques principales", "es": "Características principales", "it": "Caratteristiche principali", "nl": "Belangrijkste kenmerken", "pt": "Principais características", "pl": "Najważniejsze cechy", "cs": "Hlavní vlastnosti", "sk": "Hlavné vlastnosti", "hu": "Főbb jellemzők", "ro": "Caracteristici principale", "bg": "Основни характеристики", "sv": "Viktiga egenskaper", "da": "Vigtige egenskaber", "fi": "Tärkeimmät ominaisuudet", "el": "Κύρια χαρακτηριστικά", "et": "Peamised omadused", "lv": "Galvenās īpašības", "lt": "Pagrindinės savybės", "mt": "Karatteristiċi ewlenin", "ga": "Príomhghnéithe", "ja": "主な特長",
}
return SanitizeOutput(out)
if value := labels[language]; value != "" {
return value
}
return "Key features"
}
func localizedFallbackSpecificationsHeading(lang string) string {
labels := map[string]string{
"sl": "Tehnične specifikacije", "hr": "Tehničke specifikacije", "de": "Technische Daten", "fr": "Caractéristiques techniques", "es": "Especificaciones técnicas", "it": "Specifiche tecniche", "nl": "Technische specificaties", "pt": "Especificações técnicas", "pl": "Dane techniczne", "cs": "Technické parametry", "sk": "Technické parametre", "hu": "Műszaki adatok", "ro": "Specificații tehnice", "bg": "Технически характеристики", "sv": "Tekniska specifikationer", "da": "Tekniske specifikationer", "fi": "Tekniset tiedot", "el": "Τεχνικά χαρακτηριστικά", "et": "Tehnilised andmed", "lv": "Tehniskā specifikācija", "lt": "Techninės specifikacijos", "mt": "Speċifikazzjonijiet tekniċi", "ga": "Sonraíochtaí teicniúla", "ja": "製品仕様",
}
if value := labels[lang]; value != "" {
return value
}
return "Technical specifications"
}
// factualDescriptionIntro builds a short non-invent paragraph for formula fallback.