fix
This commit is contained in:
@@ -47,6 +47,46 @@ func AppendFormulaConstraints(userTpl string, titleTemplate, descriptionTemplate
|
||||
return userTpl + "\n\n" + joined.String()
|
||||
}
|
||||
|
||||
// FormatTitleSectionConstraint turns free-form --- Title --- section instructions
|
||||
// into a required enhance constraint when no structured title_template elements exist.
|
||||
func FormatTitleSectionConstraint(categoryPrompt string) string {
|
||||
body := strings.TrimSpace(aiprompts.TitleSectionInstructions(categoryPrompt))
|
||||
if body == "" || isBuiltInTitleRoleBoilerplate(body) {
|
||||
return ""
|
||||
}
|
||||
var b strings.Builder
|
||||
b.WriteString("Title instructions (REQUIRED — overrides any shorter \"short retail title\" rule):\n")
|
||||
b.WriteString(body)
|
||||
b.WriteString("\nBuild JSON \"name\" exactly per these instructions in {{language}}.")
|
||||
b.WriteString(" Never copy the supplier Name unchanged when instructions ask for a new name or formula.")
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func isBuiltInTitleRoleBoilerplate(body string) bool {
|
||||
lower := strings.ToLower(strings.TrimSpace(body))
|
||||
return strings.HasPrefix(lower, "role: title")
|
||||
}
|
||||
|
||||
// AppendTitleSectionConstraint appends FormatTitleSectionConstraint when the
|
||||
// category Title role has text and structured title_template is empty/unusable.
|
||||
func AppendTitleSectionConstraint(userTpl, categoryPrompt string, titleTemplate any) string {
|
||||
if FormatTitleFormulaConstraint(titleTemplate) != "" {
|
||||
return strings.TrimSpace(userTpl)
|
||||
}
|
||||
block := FormatTitleSectionConstraint(categoryPrompt)
|
||||
if block == "" {
|
||||
return strings.TrimSpace(userTpl)
|
||||
}
|
||||
userTpl = strings.TrimSpace(userTpl)
|
||||
if strings.Contains(userTpl, "Title instructions (REQUIRED") {
|
||||
return userTpl
|
||||
}
|
||||
if userTpl == "" {
|
||||
return block
|
||||
}
|
||||
return userTpl + "\n\n" + block
|
||||
}
|
||||
|
||||
// MaxAttrAllowlistPromptKeys caps Allowed attribute keys listed in enhance prompts.
|
||||
const MaxAttrAllowlistPromptKeys = 40
|
||||
|
||||
|
||||
Reference in New Issue
Block a user