upddate
This commit is contained in:
1 parent
ff6c2df618
commit
43cfaa0411
18 files changed
+683
-299
No files matched your search
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user