M2: TranslationAdapter/AdapterRegistry with documented Hy-MT3 prompts and publisher sampling; all 102 languages with BCP-47 variants, RTL and dense-script flags; normalisation, NLLanguage detection, content classification and exact-join script-aware chunking; protected-token scanning and output validation; prompt policy with one documented fallback; shared TranslationPipeline with Core error mapping. The CLI now reports sourceLanguage and warning codes. M3: pure DoubleCopyDetector, 120 ms PasteboardWatcher with 750 ms own-write suppression, SystemPasteboard snapshot/restore and markers, CapturePolicy for the 4000/2000 limits, ServicesProvider and the menu-bar action. T3.5 (10-app manual matrix) remains intentionally open. Docs: ARCHITECTURE, TRANSLATION_OUTPUT, HYMT3_MODEL (§7 spike), SELECTION_AND_CLIPBOARD, PROGRESS; ADR-016 superseded by ADR-017/018. Verified: make verify green (format, strict lint, scripts, privacy, Debug+Release signatures, package tests); live 7B CLI en→de/de→en/Markdown/JSON/placeholders; empty input exits 2 and unreachable exits 3.
62 lines
3.0 KiB
Swift
62 lines
3.0 KiB
Swift
/// 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)
|
|
}
|
|
}
|
|
}
|