fix
This commit is contained in:
@@ -11,6 +11,12 @@ var (
|
||||
reLegacyBoldUL = regexp.MustCompile(`(?is)<\s*b\s*>\s*\{?\s*(.*?)\s*\}?\s*<\s*/\s*b\s*>\s*<\s*ul\s*>\s*<\s*li\s*>\s*\{?\s*(.*?)\s*\}?\s*<\s*/\s*li\s*>\s*<\s*/\s*ul\s*>`)
|
||||
)
|
||||
|
||||
// LegacyHTMLFormulaPresent reports whether s contains A1-style HTML formula blocks
|
||||
// (<H2>{…}</H2>, <p>{…}</p>, …) used in category Description GPT predloga.
|
||||
func LegacyHTMLFormulaPresent(s string) bool {
|
||||
return reLegacyHTMLBlock.MatchString(s)
|
||||
}
|
||||
|
||||
// DescriptionFormulaSection is one ordered block in categories.description_template.
|
||||
type DescriptionFormulaSection struct {
|
||||
Type string `json:"type"`
|
||||
@@ -182,6 +188,9 @@ func EffectiveDescriptionFormula(stored any, categoryPrompt string) DescriptionF
|
||||
// Unsectioned prompt may still be a legacy HTML blob.
|
||||
descBody = strings.TrimSpace(categoryPrompt)
|
||||
}
|
||||
if isBuiltInDescriptionRoleBoilerplate(descBody) {
|
||||
descBody = ""
|
||||
}
|
||||
var derived DescriptionFormula
|
||||
if descBody != "" && reLegacyHTMLBlock.MatchString(descBody) {
|
||||
derived = DeriveDescriptionFormulaFromLegacyParts(LegacyEnhanceParts{
|
||||
@@ -194,6 +203,9 @@ func EffectiveDescriptionFormula(stored any, categoryPrompt string) DescriptionF
|
||||
}
|
||||
|
||||
metaBody := ExtractEnhanceSectionBody(categoryPrompt, SectionMetaStart, SectionMetaEnd)
|
||||
if isBuiltInMetaRoleBoilerplate(metaBody) {
|
||||
metaBody = ""
|
||||
}
|
||||
if strings.TrimSpace(out.MetaTitle) == "" && strings.TrimSpace(out.MetaDescription) == "" && strings.TrimSpace(metaBody) != "" {
|
||||
out.MetaDescription = strings.TrimSpace(metaBody)
|
||||
out.MetaTitle = DefaultLegacyMetaTitleRule
|
||||
@@ -208,6 +220,16 @@ func EffectiveDescriptionFormula(stored any, categoryPrompt string) DescriptionF
|
||||
return out
|
||||
}
|
||||
|
||||
func isBuiltInMetaRoleBoilerplate(body string) bool {
|
||||
lower := strings.ToLower(strings.TrimSpace(body))
|
||||
return strings.HasPrefix(lower, "role: meta")
|
||||
}
|
||||
|
||||
func isBuiltInDescriptionRoleBoilerplate(body string) bool {
|
||||
lower := strings.ToLower(strings.TrimSpace(body))
|
||||
return strings.HasPrefix(lower, "role: description")
|
||||
}
|
||||
|
||||
func promptHasRoleMarkers(prompt string) bool {
|
||||
lower := strings.ToLower(prompt)
|
||||
return strings.Contains(lower, strings.ToLower(SectionTitleStart)) ||
|
||||
@@ -220,6 +242,26 @@ func TitleSectionInstructions(categoryPrompt string) string {
|
||||
return ExtractEnhanceSectionBody(categoryPrompt, SectionTitleStart, SectionTitleEnd)
|
||||
}
|
||||
|
||||
// DescriptionSectionInstructions returns the --- Description --- body, or empty
|
||||
// when it is only the built-in Role: description boilerplate.
|
||||
func DescriptionSectionInstructions(categoryPrompt string) string {
|
||||
body := ExtractEnhanceSectionBody(categoryPrompt, SectionDescriptionStart, SectionDescriptionEnd)
|
||||
if isBuiltInDescriptionRoleBoilerplate(body) {
|
||||
return ""
|
||||
}
|
||||
return body
|
||||
}
|
||||
|
||||
// MetaSectionInstructions returns the --- Meta --- body, or empty when it is only
|
||||
// the built-in Role: meta boilerplate.
|
||||
func MetaSectionInstructions(categoryPrompt string) string {
|
||||
body := ExtractEnhanceSectionBody(categoryPrompt, SectionMetaStart, SectionMetaEnd)
|
||||
if isBuiltInMetaRoleBoilerplate(body) {
|
||||
return ""
|
||||
}
|
||||
return body
|
||||
}
|
||||
|
||||
// EffectiveDescriptionTemplateAny is EffectiveDescriptionFormula as a JSON object
|
||||
// for processing.ProductInput.DescriptionTemplate (nil when empty).
|
||||
func EffectiveDescriptionTemplateAny(stored any, categoryPrompt string) any {
|
||||
|
||||
Reference in New Issue
Block a user