fix
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
package processing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/aiprompts"
|
||||
)
|
||||
|
||||
type a1SmokeCompleter struct {
|
||||
system, user string
|
||||
reply string
|
||||
}
|
||||
|
||||
func (c *a1SmokeCompleter) Complete(_ context.Context, system, user string) (Completion, error) {
|
||||
c.system, c.user = system, user
|
||||
return Completion{Text: c.reply, TotalTokens: 12}, nil
|
||||
}
|
||||
|
||||
func (c *a1SmokeCompleter) Enabled() bool { return true }
|
||||
|
||||
func TestEnhance_A1StyleFormulaLocalSmoke(t *testing.T) {
|
||||
t.Parallel()
|
||||
prompt := aiprompts.SectionTitleStart + "\n" +
|
||||
`Napiši novo ime izdelka po formuli: "tip izdelka sentence case", "znamka s pravilno kapitalizacijo", "model", barva v eni besedi. Ne uporabljaj vejic.` + "\n" +
|
||||
aiprompts.SectionTitleEnd + "\n\n" +
|
||||
aiprompts.SectionDescriptionStart + "\n" +
|
||||
`<H2>{Napiši Novo ime izdelka in izpostavi en benefit}</H2>` +
|
||||
`<p>{Napiši odstavek, ki je dolg 100 besed, ki NE vsebuje Novo ime izdelka.}</p>` +
|
||||
`<H2>{Izpostavi en benefit, in NE napiši Novo ime izdelka}</H2>` +
|
||||
`<p>{Napiši odstavek, ki je dolg 100 besed in VKLJUČI tudi tip izdelka lowercase}</p>` +
|
||||
`<b>{Tehnične specifikacije}</b><ul><li>{Napiši 3-10 tehničnih specifikacij v alinejah}</li></ul>` + "\n" +
|
||||
aiprompts.SectionDescriptionEnd + "\n\n" +
|
||||
aiprompts.SectionMetaStart + "\n" +
|
||||
`Najprej napiši Novo ime izdelka in potem nadaljuj dokler nisi zapisal 140 znakov.` + "\n" +
|
||||
aiprompts.SectionMetaEnd
|
||||
|
||||
replyObj := map[string]any{
|
||||
"name": "ovitek PanzerGlass Honor 200 Smart črna",
|
||||
"description": "<h2>Zaščita z elegantnim videzom</h2><p>" + strings.Repeat("Besedilo o ovitku. ", 20) +
|
||||
"</p><h2>Trden oprijem</h2><p>" + strings.Repeat("Še več besedila. ", 20) +
|
||||
"</p><ul><li>Barva: črna</li><li>Model: Honor 200 Smart</li></ul>",
|
||||
"meta_title": "ovitek PanzerGlass Honor 200 Smart črna | zaščita",
|
||||
"meta_description": "ovitek PanzerGlass Honor 200 Smart črna z elegantnim videzom in trdnim oprijemom za vsakodnevno uporabo.",
|
||||
"attrs": map[string]any{"brand": "PanzerGlass"},
|
||||
}
|
||||
raw, _ := json.Marshal(replyObj)
|
||||
cap := &a1SmokeCompleter{reply: string(raw)}
|
||||
eng := &Engine{Completer: cap}
|
||||
|
||||
descTpl := aiprompts.EffectiveDescriptionTemplateAny(nil, prompt)
|
||||
name, desc, _, meta, err := eng.enhance(context.Background(), ProductInput{
|
||||
Name: "ovitek PanzerGlass 200 Smart",
|
||||
Description: "Zaščitni ovitek za telefon.",
|
||||
Language: "sl",
|
||||
CategoryEnhancePrompt: prompt,
|
||||
DescriptionTemplate: descTpl,
|
||||
CategoryUniqueID: "ovitki",
|
||||
}, "Ovitki in mape", map[string]any{"brand": "PanzerGlass", "product_model": "Honor 200 Smart"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(cap.system, "Si tekstopisec") {
|
||||
t.Fatalf("expected A1 system, got: %s", cap.system)
|
||||
}
|
||||
if !strings.Contains(cap.user, "GPT predloga:") || !strings.Contains(cap.user, "<name>{") {
|
||||
t.Fatalf("expected legacy GPT predloga user, got: %s", cap.user)
|
||||
}
|
||||
if !strings.Contains(cap.user, "Staro_ime_izdelka: ovitek PanzerGlass 200 Smart") {
|
||||
t.Fatalf("expected supplier name substituted like legacy STARO IME: %s", cap.user)
|
||||
}
|
||||
if !strings.Contains(cap.user, "<H2>{") && !strings.Contains(cap.user, "<h2>{") {
|
||||
t.Fatalf("expected HTML formula in predloga: %s", cap.user)
|
||||
}
|
||||
if name != "ovitek PanzerGlass Honor 200 Smart črna" {
|
||||
t.Fatalf("name=%q", name)
|
||||
}
|
||||
if !descriptionSatisfiesFormula(desc, descTpl) {
|
||||
t.Fatalf("description must satisfy formula: %s", desc)
|
||||
}
|
||||
st, _ := meta.(map[string]any)
|
||||
if st == nil || st["status"] != "ok" {
|
||||
t.Fatalf("meta=%#v", meta)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user