Files
Sprachmittler/Packages/SprachmittlerKit/Sources/SprachmittlerEngines/HyMT3RequestFactory.swift
T
schihei 26b493e7e5 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.
2026-11-26 13:04:22 +01:00

53 lines
1.7 KiB
Swift

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
)
}
}