2026-10-14 18:47:00 +02:00
|
|
|
package aiprompts
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
_ "embed"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
"sync"
|
|
|
|
|
)
|
|
|
|
|
|
2026-10-14 20:28:38 +02:00
|
|
|
// This frozen v6 snapshot is used ONLY to identify exact old default templates
|
|
|
|
|
// during migrations. Never serve these obsolete instructions to new categories.
|
|
|
|
|
//
|
|
|
|
|
//go:embed defaults/prompt-rules-v6.json
|
|
|
|
|
var previousOfflinePromptRulesJSON []byte
|
|
|
|
|
|
|
|
|
|
func PreviousOfflineDefaultPromptV6(lang string) (string, error) {
|
|
|
|
|
var rules map[string]offlineRules
|
|
|
|
|
if err := json.Unmarshal(previousOfflinePromptRulesJSON, &rules); err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
rule, ok := rules[lang]
|
|
|
|
|
if !ok || rule.Title == "" || rule.Description == "" || rule.Meta == "" {
|
|
|
|
|
return "", fmt.Errorf("missing historical v6 language %q", lang)
|
|
|
|
|
}
|
|
|
|
|
return "--- Title ---\n" + rule.Title + "\n--- End Title ---\n\n--- Description ---\n" + rule.Description +
|
|
|
|
|
"\n--- End Description ---\n\n--- Meta ---\n" + rule.Meta + "\n--- End Meta ---", nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-14 18:47:00 +02:00
|
|
|
// Shipped, human-readable platform instructions for every supported content
|
|
|
|
|
// language. This is offline reference data, not a request to an LLM.
|
|
|
|
|
//
|
|
|
|
|
//go:embed defaults/prompt-rules-25.json
|
|
|
|
|
var offlinePromptRulesJSON []byte
|
|
|
|
|
|
|
|
|
|
type offlineRules struct {
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
Description string `json:"description"`
|
|
|
|
|
Meta string `json:"meta"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var offlinePromptOnce sync.Once
|
|
|
|
|
var offlinePrompts map[string]offlineRules
|
|
|
|
|
var offlinePromptErr error
|
|
|
|
|
|
|
|
|
|
// OfflineDefaultPrompt returns a fully localized, A1-style platform template.
|
|
|
|
|
// Original category-specific English title instructions continue to live in
|
|
|
|
|
// the English wildcard and the structured title_template; this shared default
|
|
|
|
|
// uses the standard brand/type/model/color formula for non-English languages.
|
|
|
|
|
// Returns an error, rather than silently falling back to English, if a locale
|
|
|
|
|
// has no bundled translation.
|
|
|
|
|
func OfflineDefaultPrompt(lang string) (string, error) {
|
|
|
|
|
offlinePromptOnce.Do(func() {
|
|
|
|
|
offlinePromptErr = json.Unmarshal(offlinePromptRulesJSON, &offlinePrompts)
|
|
|
|
|
})
|
|
|
|
|
if offlinePromptErr != nil {
|
|
|
|
|
return "", fmt.Errorf("load bundled prompts: %w", offlinePromptErr)
|
|
|
|
|
}
|
|
|
|
|
rule, ok := offlinePrompts[lang]
|
|
|
|
|
if !ok || strings.TrimSpace(rule.Title) == "" || strings.TrimSpace(rule.Description) == "" || strings.TrimSpace(rule.Meta) == "" {
|
|
|
|
|
return "", fmt.Errorf("no bundled category formula for language %q", lang)
|
|
|
|
|
}
|
|
|
|
|
// The editor and processing pipeline interpret each role section using
|
|
|
|
|
// the exact marker syntax below. Body structure is defined in the
|
2026-10-14 19:23:16 +02:00
|
|
|
// localized Description HTML instructions, not a repetitive fixed-length article.
|
2026-10-14 18:47:00 +02:00
|
|
|
return "--- Title ---\n" + rule.Title +
|
|
|
|
|
"\n--- End Title ---\n\n--- Description ---\n" + rule.Description +
|
|
|
|
|
"\n--- End Description ---\n\n--- Meta ---\n" + rule.Meta +
|
|
|
|
|
"\n--- End Meta ---", nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func OfflinePromptLanguages() []string {
|
|
|
|
|
offlinePromptOnce.Do(func() { offlinePromptErr = json.Unmarshal(offlinePromptRulesJSON, &offlinePrompts) })
|
|
|
|
|
out := make([]string, 0, len(offlinePrompts))
|
|
|
|
|
for lang := range offlinePrompts {
|
|
|
|
|
out = append(out, lang)
|
|
|
|
|
}
|
|
|
|
|
return out
|
|
|
|
|
}
|