Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package processing
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/aiprompts"
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/company"
|
||||
)
|
||||
|
||||
func resolveProductPromptTemplates(in ProductInput) (systemTpl, userTpl string) {
|
||||
systemTpl = strings.TrimSpace(in.EnhanceSystemTemplate)
|
||||
userTpl = strings.TrimSpace(in.EnhanceUserTemplate)
|
||||
// Per-category prompt wins for the user message (company system keeps JSON schema / brand).
|
||||
if cat := strings.TrimSpace(in.CategoryEnhancePrompt); cat != "" {
|
||||
userTpl = cat
|
||||
}
|
||||
def, ok := aiprompts.DefaultFor(aiprompts.KeyProductEnhance)
|
||||
if !ok {
|
||||
return systemTpl, userTpl
|
||||
}
|
||||
if systemTpl == "" {
|
||||
systemTpl = def.SystemTemplate
|
||||
}
|
||||
if userTpl == "" {
|
||||
userTpl = def.UserTemplate
|
||||
}
|
||||
return systemTpl, userTpl
|
||||
}
|
||||
|
||||
// RenderProductEnhancePrompts fills company/built-in templates with product variables.
|
||||
func RenderProductEnhancePrompts(systemTpl, userTpl, category, name, description, gtin, brandPrompt, language string, attrs map[string]any) (system, user string) {
|
||||
attrsJSON := ""
|
||||
compact := CompactAttrs(attrs, MaxAttrKeys)
|
||||
if len(compact) > 0 {
|
||||
attrsJSON = sanitizeJSON(compact)
|
||||
}
|
||||
vars := aiprompts.Vars{
|
||||
"name": SanitizeText(truncateRunes(name, 200)),
|
||||
"description": SanitizeText(truncateRunes(description, MaxProductDescRunes)),
|
||||
"category": SanitizeText(category),
|
||||
"attrs": attrsJSON,
|
||||
"gtin": SanitizeText(gtin),
|
||||
"brand_voice": CompactBrandPrompt(brandPrompt),
|
||||
"language": company.LanguageLabel(language),
|
||||
}
|
||||
system = strings.TrimSpace(aiprompts.Render(systemTpl, vars))
|
||||
user = strings.TrimSpace(aiprompts.Render(userTpl, vars))
|
||||
if user == "" {
|
||||
// Safety net if a custom user template renders empty.
|
||||
user = ProductEnhanceUser(category, name, description, attrs)
|
||||
}
|
||||
return system, user
|
||||
}
|
||||
Reference in New Issue
Block a user