This commit is contained in:
2026-08-16 19:21:49 +02:00
parent d6fe7c38d5
commit 106f602232
8 changed files with 212 additions and 15 deletions
+24 -1
View File
@@ -76,7 +76,9 @@ func FormatDescriptionFormulaConstraint(template any) string {
return ""
}
var b strings.Builder
b.WriteString("Description formula (cover each section in order; write in {{language}}):\n")
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")
for _, s := range sections {
typ := strings.TrimSpace(s.Type)
instr := strings.TrimSpace(s.Instructions)
@@ -95,6 +97,27 @@ func FormatDescriptionFormulaConstraint(template any) string {
return strings.TrimSpace(b.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.`
// AppendDescriptionFormulaSystemOverride strengthens the system prompt when a
// description formula is active. No-op when template is empty/unparseable.
func AppendDescriptionFormulaSystemOverride(systemTpl string, descriptionTemplate any) string {
if FormatDescriptionFormulaConstraint(descriptionTemplate) == "" {
return strings.TrimSpace(systemTpl)
}
systemTpl = strings.TrimSpace(systemTpl)
if systemTpl == "" {
return descriptionFormulaSystemOverride
}
if strings.Contains(systemTpl, "Description formula") {
return systemTpl
}
return systemTpl + "\n" + descriptionFormulaSystemOverride
}
type titleFormulaElement struct {
Type string `json:"type"`
Value string `json:"value"`