From 41f1a7dbe4899856fa6c6a9d1afc7683883031fb Mon Sep 17 00:00:00 2001 From: GreenEclipse Date: Wed, 11 Nov 2026 20:24:59 +0100 Subject: [PATCH] Fix --- .../processing/description_richness_test.go | 38 +++++++++++++++++++ apps/api/internal/processing/prompt_render.go | 22 ++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 apps/api/internal/processing/description_richness_test.go diff --git a/apps/api/internal/processing/description_richness_test.go b/apps/api/internal/processing/description_richness_test.go new file mode 100644 index 0000000..4faa62f --- /dev/null +++ b/apps/api/internal/processing/description_richness_test.go @@ -0,0 +1,38 @@ +package processing + +import ( + "strings" + "testing" +) + +func TestAppendDescriptionRichnessOverrideIsIdempotent(t *testing.T) { + once := AppendDescriptionRichnessOverride("base system") + if !strings.HasPrefix(once, "base system\n") || !strings.Contains(once, "Description depth (platform rule") { + t.Fatalf("override not appended: %q", once) + } + if twice := AppendDescriptionRichnessOverride(once); twice != once { + t.Fatal("override appended twice") + } + if AppendDescriptionRichnessOverride("") != descriptionRichnessOverride { + t.Fatal("empty system should become the override alone") + } +} + +func TestResolveProductPromptTemplatesAddsRichnessOverride(t *testing.T) { + cases := map[string]ProductInput{ + "category prompt": { + CategoryEnhancePrompt: "Opis: {{description}} {{attrs}}", + CategoryUniqueID: "televizorji", + }, + "no prompt": {}, + } + for name, in := range cases { + sys, _ := resolveProductPromptTemplates(in) + if !strings.Contains(sys, "Description depth (platform rule") { + t.Errorf("%s: system prompt lacks richness override", name) + } + if !strings.Contains(sys, "never") && !strings.Contains(sys, "Do not invent") { + t.Errorf("%s: override must keep the no-invention rule", name) + } + } +} diff --git a/apps/api/internal/processing/prompt_render.go b/apps/api/internal/processing/prompt_render.go index 7532ac6..cbbdfbd 100644 --- a/apps/api/internal/processing/prompt_render.go +++ b/apps/api/internal/processing/prompt_render.go @@ -26,7 +26,7 @@ func resolveProductPromptTemplates(in ProductInput) (systemTpl, userTpl string) } allowed := enhanceAllowedAttrKeys(in, in.CategoryUniqueID) userTpl = AppendAttributeConstraints(userTpl, allowed, in.TitleTemplate) - return systemTpl, userTpl + return AppendDescriptionRichnessOverride(systemTpl), userTpl } // Per-category prompt wins for the user message (company system keeps JSON schema / brand). @@ -61,7 +61,25 @@ func resolveProductPromptTemplates(in ProductInput) (systemTpl, userTpl string) } // categories.prompt applies to name, description, and attrs (not description-only). systemTpl = AppendCategoryEnhanceSystemOverlay(systemTpl, catPrompt) - return systemTpl, userTpl + return AppendDescriptionRichnessOverride(systemTpl), userTpl +} + +// descriptionRichnessOverride is a platform-wide rule layered on top of every +// category prompt, so tenants keep their own prompts yet get fuller copy. Category +// prompts usually state modest word ranges and "shorter when sparse"; without this +// the model stops at the bottom of those ranges even when the source is rich. +const descriptionRichnessOverride = `Description depth (platform rule, applies on top of the Description formula): treat every word range in the formula as a minimum to reach whenever the input supports it, and aim for the upper end of it or more. Use ALL verified facts present in Name, Description and Attrs — every feature, technology, capability, connectivity, dimension, certification and warranty detail — and for each one explain what it means for the buyer in complete, developed sentences instead of a one-line summary. Fill every heading/paragraph pair the formula allows; when the supplied Description is rich, write full paragraphs, not a condensed recap, and never drop a supplied fact. Do not invent: any fact, number, percentage or specification must appear literally in the input. When the input is sparse, keep the text short rather than padding or guessing.` + +// AppendDescriptionRichnessOverride appends descriptionRichnessOverride once. +func AppendDescriptionRichnessOverride(systemTpl string) string { + systemTpl = strings.TrimSpace(systemTpl) + if strings.Contains(systemTpl, "Description depth (platform rule") { + return systemTpl + } + if systemTpl == "" { + return descriptionRichnessOverride + } + return systemTpl + "\n" + descriptionRichnessOverride } // withDefaultCategoryFormula supplies the platform-default formula when the