feat(m1): Ollama client, catalog, streaming chat and CLI (T1.1-T1.6)
Add endpoint policy and redirect-safe ephemeral HTTP client, error mapping, catalog cache and version checks, streaming chat with phase timeouts/cancellation, provisional Hy-MT3 prompt/language/request factory, warm-up policy, and sprachmittler-cli models/show/translate. Recapture the 7B fixtures; defer the 1.8B VERIFY items; document ADR-016. Also fix the signature checker's pipefail SIGPIPE issue.
This commit is contained in:
1 parent
7ca5c710ec
commit
26b493e7e5
93 files changed
+3732
-218
No files matched your search
@@ -0,0 +1,34 @@
|
||||
/// The provisional common-language table for the M1 CLI. T2.3 replaces this with the complete
|
||||
/// 102-language catalogue from docs/LANGUAGES.md.
|
||||
public enum HyMT3Languages {
|
||||
/// English.
|
||||
public static let english = ModelLanguage(code: "en", modelName: "English")
|
||||
/// German.
|
||||
public static let german = ModelLanguage(code: "de", modelName: "German")
|
||||
|
||||
/// The common targets exposed by the M1 CLI.
|
||||
public static let all: [ModelLanguage] = [
|
||||
english,
|
||||
german,
|
||||
ModelLanguage(code: "fr", modelName: "French"),
|
||||
ModelLanguage(code: "es", modelName: "Spanish"),
|
||||
ModelLanguage(code: "it", modelName: "Italian"),
|
||||
ModelLanguage(code: "pt", modelName: "Portuguese"),
|
||||
ModelLanguage(code: "nl", modelName: "Dutch"),
|
||||
ModelLanguage(code: "pl", modelName: "Polish"),
|
||||
ModelLanguage(code: "zh", modelName: "Chinese"),
|
||||
ModelLanguage(code: "zh-Hant", modelName: "Traditional Chinese"),
|
||||
ModelLanguage(code: "ja", modelName: "Japanese"),
|
||||
ModelLanguage(code: "ko", modelName: "Korean"),
|
||||
ModelLanguage(code: "ar", modelName: "Arabic"),
|
||||
ModelLanguage(code: "tr", modelName: "Turkish"),
|
||||
ModelLanguage(code: "ru", modelName: "Russian"),
|
||||
ModelLanguage(code: "uk", modelName: "Ukrainian"),
|
||||
]
|
||||
|
||||
/// Resolves a BCP-47 code case-insensitively; unknown codes return nil (never a guess).
|
||||
public static func resolve(_ code: String) -> ModelLanguage? {
|
||||
let normalized = code.lowercased()
|
||||
return all.first { $0.code.lowercased() == normalized }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/// The provisional Hy-MT3 model tags. The default is decided by the M7 evaluation; this constant
|
||||
/// is the only place the tag appears outside docs and tests.
|
||||
public enum HyMT3ModelPreset {
|
||||
/// The provisional default: Hy-MT3-7B Q4_K_M.
|
||||
public static let defaultModel = "hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M"
|
||||
/// The Fast preset: Hy-MT3-1.8B Q4_K_M.
|
||||
public static let fastModel = "hf.co/tencent/Hy-MT3-1.8B-GGUF:Q4_K_M"
|
||||
/// The settings default for keeping the model warm.
|
||||
public static let defaultKeepAlive = "30m"
|
||||
/// The only text used for warm-up. Never user text.
|
||||
public static let warmUpText = "Hello."
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import SprachmittlerOllama
|
||||
|
||||
/// The documented Hy-MT3 sampling values from docs/HYMT3_MODEL.md §2.
|
||||
public enum HyMT3Options {
|
||||
/// Translation defaults: temperature 0.7, top_p 0.6, top_k 20, repeat_penalty 1.05,
|
||||
/// num_predict 4096, num_ctx 8192.
|
||||
public static let translation = ChatOptions(
|
||||
temperature: 0.7,
|
||||
topP: 0.6,
|
||||
topK: 20,
|
||||
repeatPenalty: 1.05,
|
||||
numPredict: 4096,
|
||||
numCtx: 8192
|
||||
)
|
||||
|
||||
/// Warm-up uses the same model settings but only 8 output tokens.
|
||||
public static let warmUp = ChatOptions(
|
||||
temperature: 0.7,
|
||||
topP: 0.6,
|
||||
topK: 20,
|
||||
repeatPenalty: 1.05,
|
||||
numPredict: 8,
|
||||
numCtx: 8192
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/// The documented Hy-MT3 prompt templates. v1 uses the Default Translation template.
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import SprachmittlerOllama
|
||||
|
||||
/// Builds the documented Hy-MT3 requests. T2.1/T2.2 replace this with the adapter protocol;
|
||||
/// until then this is the only place the translation request shape is assembled.
|
||||
public struct HyMT3RequestFactory: Sendable {
|
||||
/// The model tag.
|
||||
public let model: String
|
||||
/// The Ollama `keep_alive` value.
|
||||
public let keepAlive: String
|
||||
|
||||
/// Creates a factory.
|
||||
public init(
|
||||
model: String = HyMT3ModelPreset.defaultModel,
|
||||
keepAlive: String = HyMT3ModelPreset.defaultKeepAlive
|
||||
) {
|
||||
self.model = model
|
||||
self.keepAlive = keepAlive
|
||||
}
|
||||
|
||||
/// A translation request with the documented prompt and sampling.
|
||||
public func translationRequest(text: String, target: ModelLanguage) -> ChatRequest {
|
||||
ChatRequest(
|
||||
model: model,
|
||||
messages: [ChatMessage(content: HyMT3Prompt.defaultTranslation(target: target, source: text))],
|
||||
stream: true,
|
||||
keepAlive: keepAlive,
|
||||
options: HyMT3Options.translation
|
||||
)
|
||||
}
|
||||
|
||||
/// A warm-up request with fixed synthetic text and `num_predict: 8`.
|
||||
public func warmUpRequest() -> ChatRequest {
|
||||
ChatRequest(
|
||||
model: model,
|
||||
messages: [ChatMessage(content: HyMT3ModelPreset.warmUpText)],
|
||||
stream: true,
|
||||
keepAlive: keepAlive,
|
||||
options: HyMT3Options.warmUp
|
||||
)
|
||||
}
|
||||
|
||||
/// A request that unloads the model after it completes.
|
||||
public func unloadRequest() -> ChatRequest {
|
||||
ChatRequest(
|
||||
model: model,
|
||||
messages: [ChatMessage(content: HyMT3ModelPreset.warmUpText)],
|
||||
stream: true,
|
||||
keepAlive: "0",
|
||||
options: HyMT3Options.warmUp
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/// A BCP-47 code paired with the exact English model-card name used in the prompt.
|
||||
public struct ModelLanguage: Sendable, Hashable, Codable {
|
||||
/// The BCP-47 code, e.g. `de` or `zh-Hant`.
|
||||
public let code: String
|
||||
/// The exact model-card name, e.g. `German` or `Traditional Chinese`.
|
||||
public let modelName: String
|
||||
|
||||
/// Creates a language pair.
|
||||
public init(code: String, modelName: String) {
|
||||
self.code = code
|
||||
self.modelName = modelName
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
// Placeholder so the target compiles. Replace during T0.1+ (see docs/IMPLEMENTATION_PLAN.md).
|
||||
|
||||
/// Namespace for the SprachmittlerEngines module.
|
||||
public enum SprachmittlerEnginesModule {
|
||||
public static let moduleName = "SprachmittlerEngines"
|
||||
}
|
||||
Reference in new issue
Block a user