fix
This commit is contained in:
1 parent
7537a41955
commit
ff6c2df618
14 files changed
+767
-349
No files matched your search
@@ -1,4 +1,5 @@
|
||||
// Clean exact repeated heading/paragraph pairs in A1 Slovenija category prompts.
|
||||
// Rewrite repeated heading/paragraph instructions in A1 Slovenija prompts,
|
||||
// keeping the section count and intended product-name inclusion rules.
|
||||
// Runs only for the A1 tenant and never rewrites title or meta instructions.
|
||||
// Dry run by default; pass -apply to write changes atomically.
|
||||
package main
|
||||
@@ -20,50 +21,8 @@ import (
|
||||
|
||||
const a1ID = "604f23a8-b66e-4b21-8b45-0d72b68f4790"
|
||||
|
||||
func dedupeSections(raw string) (string, int, error) {
|
||||
if raw == "" || raw == "null" {
|
||||
return raw, 0, nil
|
||||
}
|
||||
var obj map[string]json.RawMessage
|
||||
if err := json.Unmarshal([]byte(raw), &obj); err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
if obj == nil {
|
||||
return raw, 0, nil
|
||||
}
|
||||
var entries []map[string]json.RawMessage
|
||||
if err := json.Unmarshal(obj["sections"], &entries); err != nil {
|
||||
return raw, 0, nil
|
||||
}
|
||||
seen := make(map[string]bool)
|
||||
result := make([]map[string]json.RawMessage, 0, len(entries))
|
||||
removed := 0
|
||||
for i := 0; i < len(entries); i++ {
|
||||
var typ, instr string
|
||||
_ = json.Unmarshal(entries[i]["type"], &typ)
|
||||
_ = json.Unmarshal(entries[i]["instructions"], &instr)
|
||||
if strings.EqualFold(typ, "h2") && i+1 < len(entries) {
|
||||
var nextTyp, nextInstr string
|
||||
_ = json.Unmarshal(entries[i+1]["type"], &nextTyp)
|
||||
_ = json.Unmarshal(entries[i+1]["instructions"], &nextInstr)
|
||||
if strings.EqualFold(nextTyp, "p") {
|
||||
key := strings.ToLower(strings.Join(strings.Fields(instr+"\x00"+nextInstr), " "))
|
||||
if seen[key] {
|
||||
removed++
|
||||
i++
|
||||
continue
|
||||
}
|
||||
seen[key] = true
|
||||
}
|
||||
}
|
||||
result = append(result, entries[i])
|
||||
}
|
||||
if removed == 0 {
|
||||
return raw, 0, nil
|
||||
}
|
||||
obj["sections"], _ = json.Marshal(result)
|
||||
encoded, err := json.Marshal(obj)
|
||||
return string(encoded), removed, err
|
||||
func normalizeSections(raw string) (string, int, error) {
|
||||
return aiprompts.NormalizeA1DescriptionTemplate(raw)
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -107,7 +66,7 @@ func main() {
|
||||
if len(candidates) == 0 {
|
||||
log.Fatal("no A1 Slovenija categories found; no changes made")
|
||||
}
|
||||
updated, duplicatePairs := 0, 0
|
||||
updated, rewrittenPairs := 0, 0
|
||||
for _, c := range candidates {
|
||||
var prompts map[string]string
|
||||
if err := json.Unmarshal([]byte(c.prompt), &prompts); err != nil {
|
||||
@@ -118,14 +77,14 @@ func main() {
|
||||
}
|
||||
changed, count := false, 0
|
||||
for language, text := range prompts {
|
||||
cleaned, n := aiprompts.DedupeA1DescriptionBlocks(text)
|
||||
cleaned, n := aiprompts.NormalizeA1RepeatedBenefits(text)
|
||||
if n != 0 {
|
||||
prompts[language] = cleaned
|
||||
changed = true
|
||||
count += n
|
||||
}
|
||||
}
|
||||
desc, n, err := dedupeSections(c.desc)
|
||||
desc, n, err := normalizeSections(c.desc)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -137,8 +96,8 @@ func main() {
|
||||
continue
|
||||
}
|
||||
updated++
|
||||
duplicatePairs += count
|
||||
log.Printf("category=%s repeated_pairs_removed=%d", c.id, count)
|
||||
rewrittenPairs += count
|
||||
log.Printf("category=%s repeated_pairs_rewritten=%d", c.id, count)
|
||||
if !*apply {
|
||||
continue
|
||||
}
|
||||
@@ -158,5 +117,5 @@ func main() {
|
||||
log.Fatal(fmt.Errorf("category %s changed concurrently; rerun dry-run", c.id))
|
||||
}
|
||||
}
|
||||
log.Printf("A1 cleanup: categories_scanned=%d categories_requiring_cleanup=%d duplicated_pairs=%d applied=%v", len(candidates), updated, duplicatePairs, *apply)
|
||||
log.Printf("A1 cleanup: categories_scanned=%d categories_requiring_cleanup=%d rewritten_pairs=%d applied=%v", len(candidates), updated, rewrittenPairs, *apply)
|
||||
}
|
||||
Reference in new issue
Block a user