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,129 @@
|
||||
package aiprompts
|
||||
|
||||
// Prompt keys stored in ai_prompt_templates.prompt_key.
|
||||
const (
|
||||
KeyProductEnhance = "product_enhance"
|
||||
KeySEOMeta = "seo_meta"
|
||||
KeyCampaignEmail = "campaign_email"
|
||||
)
|
||||
|
||||
// MaxSystemRunes / MaxUserRunes bound stored templates (prompt-injection surface).
|
||||
const (
|
||||
MaxSystemRunes = 6000
|
||||
MaxUserRunes = 4000
|
||||
)
|
||||
|
||||
// Variable describes a placeholder tenants can insert into templates.
|
||||
type Variable struct {
|
||||
Name string `json:"name"`
|
||||
Label string `json:"label"`
|
||||
Description string `json:"description"`
|
||||
Keys []string `json:"keys"` // prompt_key values that support this variable
|
||||
}
|
||||
|
||||
// Catalog of supported {{variables}} (only these are substituted; unknown tokens stay literal).
|
||||
var VariableCatalog = []Variable{
|
||||
{Name: "name", Label: "Product name", Description: "Current product title", Keys: []string{KeyProductEnhance, KeySEOMeta}},
|
||||
{Name: "description", Label: "Description", Description: "Current product description", Keys: []string{KeyProductEnhance, KeySEOMeta}},
|
||||
{Name: "category", Label: "Category", Description: "Resolved category name", Keys: []string{KeyProductEnhance, KeySEOMeta}},
|
||||
{Name: "attrs", Label: "Attributes", Description: "Compact JSON of product attributes", Keys: []string{KeyProductEnhance}},
|
||||
{Name: "gtin", Label: "GTIN", Description: "Product GTIN / barcode when present", Keys: []string{KeyProductEnhance}},
|
||||
{Name: "brand", Label: "Brand name", Description: "Company or product brand label", Keys: []string{KeySEOMeta, KeyCampaignEmail}},
|
||||
{Name: "brand_voice", Label: "Brand voice", Description: "Brand kit tone / dos / don'ts block", Keys: []string{KeyProductEnhance, KeySEOMeta, KeyCampaignEmail}},
|
||||
{Name: "language", Label: "Content language", Description: "Company content language (English display name)", Keys: []string{KeyProductEnhance, KeySEOMeta, KeyCampaignEmail}},
|
||||
{Name: "campaign_prompt", Label: "Campaign brief", Description: "Per-campaign user brief or template default", Keys: []string{KeyCampaignEmail}},
|
||||
{Name: "products", Label: "Product list", Description: "Plain-text product snippets for the campaign", Keys: []string{KeyCampaignEmail}},
|
||||
{Name: "template_key", Label: "Template key", Description: "Campaign template id (christmas, custom, …)", Keys: []string{KeyCampaignEmail}},
|
||||
}
|
||||
|
||||
// DefaultTemplate is the built-in prompt when the company has no custom row or disabled it.
|
||||
type DefaultTemplate struct {
|
||||
Key string `json:"key"`
|
||||
Label string `json:"label"`
|
||||
Description string `json:"description"`
|
||||
SystemTemplate string `json:"system_template"`
|
||||
UserTemplate string `json:"user_template"`
|
||||
}
|
||||
|
||||
// BuiltInDefaults match the previous hardcoded system prompts, with structured user templates.
|
||||
var BuiltInDefaults = []DefaultTemplate{
|
||||
{
|
||||
Key: KeyProductEnhance,
|
||||
Label: "Product title & description",
|
||||
Description: "Used when processing products (AI enhance step).",
|
||||
SystemTemplate: `Retail product copywriter.
|
||||
Rules:
|
||||
- Reply with ONLY JSON (no markdown)
|
||||
- Schema: {"name":"string","description":"string"}
|
||||
- name: short retail title
|
||||
- description: 1-2 factual sentences
|
||||
- Write name and description in {{language}}
|
||||
Example:
|
||||
{"name":"Acme Widget Pro","description":"Durable widget for everyday use. Clear specs, ready to ship."}
|
||||
{{brand_voice}}`,
|
||||
UserTemplate: `Category: {{category}}
|
||||
Name: {{name}}
|
||||
Desc: {{description}}
|
||||
Attrs: {{attrs}}`,
|
||||
},
|
||||
{
|
||||
Key: KeySEOMeta,
|
||||
Label: "SEO meta title & description",
|
||||
Description: "Used when applying AI SEO meta to a product.",
|
||||
SystemTemplate: `SEO meta writer for ecommerce.
|
||||
Rules:
|
||||
- Reply with ONLY JSON (no markdown)
|
||||
- Schema: {"meta_title":"string","meta_description":"string"}
|
||||
- meta_title: 50-60 chars, product + benefit
|
||||
- meta_description: 120-155 chars, factual
|
||||
- Write meta_title and meta_description in {{language}}
|
||||
Example:
|
||||
{"meta_title":"Acme Widget Pro | Durable Daily Use","meta_description":"Shop Acme Widget Pro for reliable everyday performance. Clear specs and fast delivery."}
|
||||
{{brand_voice}}`,
|
||||
UserTemplate: `Name: {{name}}
|
||||
Category: {{category}}
|
||||
Desc: {{description}}`,
|
||||
},
|
||||
{
|
||||
Key: KeyCampaignEmail,
|
||||
Label: "Campaign email",
|
||||
Description: "Used when generating marketing emails with AI.",
|
||||
SystemTemplate: `Marketing email writer.
|
||||
Rules:
|
||||
- Reply with ONLY JSON (no markdown)
|
||||
- Schema: {"subject":"string","html_body":"string","plain_body":"string"}
|
||||
- subject: short
|
||||
- html_body: simple HTML (<p>, <ul>, <a> only)
|
||||
- plain_body: plain text mirror
|
||||
- Write subject, html_body, and plain_body in {{language}}
|
||||
Example:
|
||||
{"subject":"Holiday picks from Acme","html_body":"<p>Season's greetings.</p><ul><li>Widget Pro</li></ul><p><a href=\"#\">Shop now</a></p>","plain_body":"Season's greetings.\n- Widget Pro\nShop now"}
|
||||
{{brand_voice}}`,
|
||||
UserTemplate: `{{campaign_prompt}}
|
||||
|
||||
Products:
|
||||
{{products}}
|
||||
Brand: {{brand}}
|
||||
Template: {{template_key}}`,
|
||||
},
|
||||
}
|
||||
|
||||
// ValidPromptKey reports whether key is a known prompt_key.
|
||||
func ValidPromptKey(key string) bool {
|
||||
switch key {
|
||||
case KeyProductEnhance, KeySEOMeta, KeyCampaignEmail:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultFor returns the built-in default for key, or empty if unknown.
|
||||
func DefaultFor(key string) (DefaultTemplate, bool) {
|
||||
for _, d := range BuiltInDefaults {
|
||||
if d.Key == key {
|
||||
return d, true
|
||||
}
|
||||
}
|
||||
return DefaultTemplate{}, false
|
||||
}
|
||||
Reference in New Issue
Block a user