fix
This commit is contained in:
@@ -8,11 +8,33 @@ import (
|
||||
var (
|
||||
reLegacyNameTag = regexp.MustCompile(`(?is)<\s*name\s*>\s*\{?\s*(.*?)\s*\}?\s*<\s*/\s*name\s*>`)
|
||||
reLegacyMetaTag = regexp.MustCompile(`(?is)<\s*metaDescription\s*>\s*\{?\s*(.*?)\s*\}?\s*<\s*/\s*metaDescription\s*>`)
|
||||
reLegacyDescPH = regexp.MustCompile(`(?i)\{\s*""?\s*OPIS\s+IZDELKA\s*""?\s*\}`)
|
||||
reLegacyNamePH = regexp.MustCompile(`(?i)\{\s*""?\s*STARO\s+IME\s+IZDELKA\s*""?\s*\}`)
|
||||
reLegacyDescPH = regexp.MustCompile(`(?i)\{\s*""?\s*(?:OPIS\s+IZDELKA|PRODUCT\s+DESCRIPTION)\s*""?\s*\}`)
|
||||
reLegacyNamePH = regexp.MustCompile(`(?i)\{\s*""?\s*(?:STARO\s+IME\s+IZDELKA|OLD\s+PRODUCT\s+NAME)\s*""?\s*\}`)
|
||||
reDoubledQuotes = regexp.MustCompile(`"{2,}`)
|
||||
)
|
||||
|
||||
// legacyTemplateMarkers introduce the formula body in a combined prompt. The
|
||||
// Slovenian marker is the legacy A1 wording; the English one is used by the
|
||||
// platform-default seed (scripts/seed/default-category-prompts.json), which is the
|
||||
// same template style translated.
|
||||
var legacyTemplateMarkers = []string{"gpt predloga:", "product template:"}
|
||||
|
||||
// legacyIntroLinePrefixes are scaffolding lines above the template body ("here are
|
||||
// the variables", "follow the template step by step") in either language. They are
|
||||
// not body structure and must not become description sections.
|
||||
var legacyIntroLinePrefixes = []string{
|
||||
"ustvari nov opis",
|
||||
"star_opis_izdelka",
|
||||
"staro_ime_izdelka",
|
||||
"uporabi spodnjo gpt",
|
||||
"sledi tej gpt",
|
||||
"create a new product description",
|
||||
"old_product_description",
|
||||
"old_product_name",
|
||||
"use the product template",
|
||||
"follow this product template",
|
||||
}
|
||||
|
||||
// LegacyEnhanceParts holds extracted role content from a combined PHP/A1 category Prompt.
|
||||
type LegacyEnhanceParts struct {
|
||||
TitleRules string
|
||||
@@ -22,7 +44,8 @@ type LegacyEnhanceParts struct {
|
||||
}
|
||||
|
||||
// IsLegacyCombinedEnhancePrompt reports whether prompt looks like the old A1/PHP
|
||||
// combined name+description(+meta) marketing blob (<name>/<metaDescription>/GPT predloga).
|
||||
// combined name+description(+meta) marketing blob (<name>/<metaDescription>/GPT
|
||||
// predloga), or its English platform-default translation (Product template:).
|
||||
func IsLegacyCombinedEnhancePrompt(prompt string) bool {
|
||||
p := strings.TrimSpace(prompt)
|
||||
if p == "" {
|
||||
@@ -32,14 +55,20 @@ func IsLegacyCombinedEnhancePrompt(prompt string) bool {
|
||||
// `do NOT … <name>/<metaDescription> tags` in CategoryEnhanceUserTemplate.
|
||||
hasNameTag := reLegacyNameTag.MatchString(p)
|
||||
hasMetaTag := reLegacyMetaTag.MatchString(p)
|
||||
if hasNameTag && (hasMetaTag || strings.Contains(strings.ToLower(p), "gpt predloga")) {
|
||||
hasTemplateMarker := hasAnyLegacyTemplateMarker(p)
|
||||
hasPlaceholders := reLegacyNamePH.MatchString(p) || reLegacyDescPH.MatchString(p)
|
||||
if hasNameTag && (hasMetaTag || hasTemplateMarker || hasPlaceholders) {
|
||||
return true
|
||||
}
|
||||
if hasNameTag && (strings.Contains(p, "STARO IME IZDELKA") || strings.Contains(p, "OPIS IZDELKA")) {
|
||||
return true
|
||||
}
|
||||
if strings.Contains(p, "STARO IME IZDELKA") && strings.Contains(p, "OPIS IZDELKA") && strings.Contains(strings.ToLower(p), "gpt predloga") {
|
||||
return true
|
||||
return hasPlaceholders && hasTemplateMarker
|
||||
}
|
||||
|
||||
func hasAnyLegacyTemplateMarker(prompt string) bool {
|
||||
lower := strings.ToLower(prompt)
|
||||
for _, marker := range legacyTemplateMarkers {
|
||||
if strings.Contains(lower, marker) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -64,8 +93,11 @@ func ParseLegacyCombinedEnhancePrompt(prompt string) LegacyEnhanceParts {
|
||||
|
||||
rest := reLegacyNameTag.ReplaceAllString(raw, "")
|
||||
rest = reLegacyMetaTag.ReplaceAllString(rest, "")
|
||||
if idx := strings.Index(strings.ToLower(rest), "gpt predloga:"); idx >= 0 {
|
||||
rest = rest[idx+len("gpt predloga:"):]
|
||||
for _, marker := range legacyTemplateMarkers {
|
||||
if idx := strings.Index(strings.ToLower(rest), marker); idx >= 0 {
|
||||
rest = rest[idx+len(marker):]
|
||||
break
|
||||
}
|
||||
}
|
||||
// Drop Slovenian boilerplate intro lines that are not body structure.
|
||||
rest = stripLegacyIntroNoise(rest)
|
||||
@@ -135,6 +167,15 @@ func ExtractEnhanceSectionBody(prompt, start, end string) string {
|
||||
return strings.TrimSpace(strings.TrimPrefix(strings.TrimSuffix(rest, "\n"), "\n"))
|
||||
}
|
||||
|
||||
func hasAnyPrefix(s string, prefixes []string) bool {
|
||||
for _, p := range prefixes {
|
||||
if strings.HasPrefix(s, p) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func cleanLegacyInstruction(s string) string {
|
||||
s = modernizeLegacyPlaceholders(s)
|
||||
s = reDoubledQuotes.ReplaceAllString(s, `"`)
|
||||
@@ -164,11 +205,7 @@ func stripLegacyIntroNoise(s string) string {
|
||||
if len(out) > 0 {
|
||||
out = append(out, "")
|
||||
}
|
||||
case strings.HasPrefix(lower, "ustvari nov opis"),
|
||||
strings.HasPrefix(lower, "star_opis_izdelka"),
|
||||
strings.HasPrefix(lower, "staro_ime_izdelka"),
|
||||
strings.HasPrefix(lower, "uporabi spodnjo gpt"),
|
||||
strings.HasPrefix(lower, "sledi tej gpt"):
|
||||
case hasAnyPrefix(lower, legacyIntroLinePrefixes):
|
||||
continue
|
||||
default:
|
||||
out = append(out, trim)
|
||||
|
||||
Reference in New Issue
Block a user