fix
This commit is contained in:
@@ -10,9 +10,10 @@ import (
|
||||
func resolveProductPromptTemplates(in ProductInput) (systemTpl, userTpl string) {
|
||||
systemTpl = strings.TrimSpace(in.EnhanceSystemTemplate)
|
||||
userTpl = strings.TrimSpace(in.EnhanceUserTemplate)
|
||||
catPrompt := strings.TrimSpace(in.CategoryEnhancePrompt)
|
||||
// Per-category prompt wins for the user message (company system keeps JSON schema / brand).
|
||||
if cat := strings.TrimSpace(in.CategoryEnhancePrompt); cat != "" {
|
||||
userTpl = ensureCategoryEnhanceUserContext(cat)
|
||||
if catPrompt != "" {
|
||||
userTpl = ensureCategoryEnhanceUserContext(catPrompt)
|
||||
}
|
||||
def, ok := aiprompts.DefaultFor(aiprompts.KeyProductEnhance)
|
||||
if ok {
|
||||
@@ -25,9 +26,17 @@ func resolveProductPromptTemplates(in ProductInput) (systemTpl, userTpl string)
|
||||
}
|
||||
// Category formulas are language-agnostic; inject once into the shared user skeleton.
|
||||
userTpl = AppendFormulaConstraints(userTpl, in.TitleTemplate, in.DescriptionTemplate)
|
||||
// Category attribute allowlist + title-formula keys guide JSON "attrs" extraction.
|
||||
allowed := enhanceAllowedAttrKeys(in, in.CategoryUniqueID)
|
||||
userTpl = AppendAttributeConstraints(userTpl, allowed, in.TitleTemplate)
|
||||
// Company/built-in system prompts often say "1-2 sentences"; when a category
|
||||
// description formula exists, override that so process matches A1 category defs.
|
||||
systemTpl = AppendDescriptionFormulaSystemOverride(systemTpl, in.DescriptionTemplate)
|
||||
// Same for title_template vs "short retail title" — formulas win for name structure.
|
||||
systemTpl = AppendTitleFormulaSystemOverride(systemTpl, in.TitleTemplate)
|
||||
systemTpl = AppendMetaFormulaSystemOverride(systemTpl, in.DescriptionTemplate)
|
||||
// categories.prompt applies to name, description, and attrs (not description-only).
|
||||
systemTpl = AppendCategoryEnhanceSystemOverlay(systemTpl, catPrompt)
|
||||
return systemTpl, userTpl
|
||||
}
|
||||
|
||||
@@ -45,12 +54,36 @@ func templateHasVar(tpl, name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ensureCategoryEnhanceUserContext appends standard product context placeholders when a
|
||||
// category override omits {{attrs}} (common in DB category prompts). Does not rewrite
|
||||
// category copy that already includes attrs.
|
||||
// categoryEnhanceUserOverlayPrefix frames free-form categories.prompt text so the
|
||||
// model applies it to name, description, and attrs (not description alone). Canonical
|
||||
// CategoryEnhanceUserTemplate already covers all roles — skip double-framing there.
|
||||
const categoryEnhanceUserOverlayPrefix = "Category guidance (applies to name, description, and attrs; obey Title/Description formulas and Allowed attribute keys when present):\n"
|
||||
|
||||
func categoryEnhancePromptAlreadyCoversTitle(userTpl string) bool {
|
||||
lower := strings.ToLower(userTpl)
|
||||
if strings.Contains(lower, "applies to name, description, and attrs") {
|
||||
return true
|
||||
}
|
||||
if strings.Contains(lower, "applies to name and description") {
|
||||
return true
|
||||
}
|
||||
// Repaired / built-in overlay: explicit name + Title formula bullets / role sections.
|
||||
return strings.Contains(lower, `"name"`) && (strings.Contains(lower, "title formula") || strings.Contains(lower, "--- title ---"))
|
||||
}
|
||||
|
||||
// ensureCategoryEnhanceUserContext frames category overlay for title+description,
|
||||
// then appends standard product context placeholders when a category override omits
|
||||
// {{attrs}} (common in DB category prompts). Does not rewrite category copy that
|
||||
// already includes attrs (aside from optional title framing).
|
||||
func ensureCategoryEnhanceUserContext(userTpl string) string {
|
||||
userTpl = strings.TrimSpace(userTpl)
|
||||
if userTpl == "" || templateHasVar(userTpl, "attrs") {
|
||||
if userTpl == "" {
|
||||
return userTpl
|
||||
}
|
||||
if !categoryEnhancePromptAlreadyCoversTitle(userTpl) {
|
||||
userTpl = categoryEnhanceUserOverlayPrefix + userTpl
|
||||
}
|
||||
if templateHasVar(userTpl, "attrs") {
|
||||
return userTpl
|
||||
}
|
||||
var b strings.Builder
|
||||
@@ -71,7 +104,7 @@ func ensureCategoryEnhanceUserContext(userTpl string) string {
|
||||
appendLine("Name: {{name}}")
|
||||
}
|
||||
if !templateHasVar(userTpl, "description") {
|
||||
appendLine("Desc: {{description}}")
|
||||
appendLine("Description: {{description}}")
|
||||
}
|
||||
appendLine("Attrs: {{attrs}}")
|
||||
return b.String()
|
||||
|
||||
Reference in New Issue
Block a user