fix
This commit is contained in:
1 parent
7537a41955
commit
ff6c2df618
14 files changed
+767
-349
No files matched your search
@@ -0,0 +1,61 @@
|
||||
package aiprompts
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// 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
|
||||
// localized Description instructions (five *different* H2/paragraphs),
|
||||
// not by copying a repeated HTML instruction five times.
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user