package llm import "strings" // The pair language, as the prompts need to talk about it. // // Three of Petal's prompts name the writer's first language rather than merely // being written in English: the collocation coach asks for a gloss in it, Ask // Petal offers to answer in it, and the explanation translator renders into it. // Before Phase 19 all three said "Simplified Chinese" outright, which made the // zh pair the only one that could ever work. // // A Lang is not a translation of the prompt — the instructions stay in English, // which is what the model follows best. It is the name the model should use for // her language, plus the one word it should watch for when she writes in it. type Lang struct { // Code matches users.pair_lang. Code string // Name is how the prompt refers to the language, spelled the way a model // recognises it. Regional precision matters here: "European Portuguese" is // not "Portuguese" to a model that has read far more pt-BR than pt-PT. Name string // Why asks the same thing she would ask in her own language. It goes into // the Ask Petal prompt as an example, so a model that answers only to // English "why" still recognises the question when she types it her way. Why string } // langs holds every pair Petal can currently be a partner in. A language with a // frontend langpack but no entry here still works — it falls back to zh's // behaviour of the prompts, which is wrong but not broken — so keep the two in // step when a pair ships. var langs = map[string]Lang{ "zh": {Code: "zh", Name: "Simplified Chinese (Mandarin)", Why: "为什么"}, "pt-PT": {Code: "pt-PT", Name: "European Portuguese (pt-PT, never Brazilian Portuguese)", Why: "porquê"}, "fr": {Code: "fr", Name: "French", Why: "pourquoi"}, "es": {Code: "es", Name: "Spanish", Why: "por qué"}, } // DefaultLang is the pair assumed when none is known — the column's default, and // the only pair that existed before Phase 19. var DefaultLang = langs["zh"] // LangFor resolves a users.pair_lang value. An empty or unrecognised code falls // back to the default rather than erroring: a prompt is not the place to // discover a configuration problem, and the writing still has to be checked. func LangFor(code string) Lang { if l, ok := langs[strings.TrimSpace(code)]; ok { return l } return DefaultLang }