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.
39 lines
1.4 KiB
Swift
39 lines
1.4 KiB
Swift
import Foundation
|
|
import SprachmittlerEngines
|
|
import SprachmittlerOllama
|
|
|
|
struct TranslateOutcome: Sendable, Equatable {
|
|
let translation: String
|
|
let model: String
|
|
let target: ModelLanguage
|
|
let metrics: ChatMetrics
|
|
let firstTokenMs: Int?
|
|
let totalMs: Int
|
|
let sourceCharacters: Int
|
|
|
|
/// The CLI JSON contract from docs/TRANSLATION_OUTPUT.md §10. `sourceLanguage` stays null
|
|
/// until T2.4; warnings stay empty until T2.5.
|
|
func jsonData(includeSource: Bool, source: String) throws -> Data {
|
|
let timing: [String: Any] = [
|
|
"firstTokenMs": firstTokenMs.map { $0 as Any } ?? NSNull(),
|
|
"totalMs": totalMs,
|
|
"promptTokens": metrics.promptEvalCount.map { $0 as Any } ?? NSNull(),
|
|
"outputTokens": metrics.evalCount.map { $0 as Any } ?? NSNull(),
|
|
]
|
|
var object: [String: Any] = [
|
|
"schema": "sprachmittler-translation-v1",
|
|
"sourceLanguage": NSNull(),
|
|
"targetLanguage": target.code,
|
|
"model": model,
|
|
"sourceCharacters": sourceCharacters,
|
|
"translation": translation,
|
|
"warnings": [String](),
|
|
"timing": timing,
|
|
]
|
|
if includeSource {
|
|
object["source"] = source
|
|
}
|
|
return try JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted, .sortedKeys])
|
|
}
|
|
}
|