/// The documented Hy-MT3 prompt templates (`docs/HYMT3_MODEL.md` §3–§4). /// /// These are the only prompt strings in the app. The Default template is canonical for v1; the /// Delimiters and Structured Data 1 templates are the only documented fallbacks (ADR-012). public enum HyMT3Prompt { /// The byte-exact Default Translation prompt from `docs/HYMT3_MODEL.md` §3. /// /// The prefix depends only on the target language; the source text is appended last so the /// Ollama prompt cache stays valid. public static func defaultTranslation(target: ModelLanguage, source: String) -> String { let prefix = "Translate the following text into \(target.modelName). " + "Note that you should **only output the translated result without any additional explanation**:" return prefix + "\n\n" + source } /// The byte-exact Delimiters prompt, the single documented fallback for a lost token. public static func delimiters(target: ModelLanguage, source: String) -> String { let instruction = "Please accurately translate the following text into \(target.modelName). " + "You must **retain the exact same number of delimiters in the translation. Strictly do " + "not omit, escape, or translate these symbols, and pay close attention to their placement**." return instruction + "\n\n" + source } /// The byte-exact Structured Data 1 prompt for JSON, HTML or Markdown. public static func structuredData1( format: StructuredFormat, target: ModelLanguage, source: String ) -> String { let type = format.rawValue let preservation = "1. **Structure Preservation:** You MUST preserve the original \(type) data " + "structure, nesting, hierarchy, and indentation exactly as they are." let nonTranslation = "3. **Strict Non-Translation:** NEVER translate or alter code tags, keys, " + "properties, object names, or variable placeholders. Leave them exactly in their original " + "English/code form." return [ "### Task", "Translate the user-facing text within the following \(type) data into \(target.modelName).", "", "### Strict Rules", preservation, "2. **Selective Translation:** Translate ONLY the visible, user-facing text content/values.", nonTranslation, "", "### Source Data", source, ].joined(separator: "\n") } /// Builds the prompt for a variant. public static func text(for variant: PromptVariant, target: ModelLanguage, source: String) -> String { switch variant { case .defaultTranslation: defaultTranslation(target: target, source: source) case .delimiters: delimiters(target: target, source: source) case let .structuredData1(format): structuredData1(format: format, target: target, source: source) } } }