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
+93
@@ -0,0 +1,93 @@
|
||||
import Foundation
|
||||
import SprachmittlerOllama
|
||||
import Testing
|
||||
@testable import SprachmittlerEngines
|
||||
|
||||
@Suite("Hy-MT3 request factory")
|
||||
struct HyMT3RequestFactoryTests {
|
||||
@Test func warmUpUsesFixedTextAndEightTokens() throws {
|
||||
let request = HyMT3RequestFactory().warmUpRequest()
|
||||
let message = try #require(request.messages.first)
|
||||
#expect(request.messages.count == 1)
|
||||
#expect(message.role == "user")
|
||||
#expect(message.content == "Hello.")
|
||||
#expect(request.options.numPredict == 8)
|
||||
#expect(request.options.numCtx == 8192)
|
||||
#expect(request.keepAlive == "30m")
|
||||
#expect(request.stream)
|
||||
#expect(request.model == HyMT3ModelPreset.defaultModel)
|
||||
}
|
||||
|
||||
@Test func unloadUsesKeepAliveZero() {
|
||||
let request = HyMT3RequestFactory().unloadRequest()
|
||||
#expect(request.keepAlive == "0")
|
||||
#expect(request.messages.map(\.content) == ["Hello."])
|
||||
}
|
||||
|
||||
@Test func translationPromptIsByteExact() throws {
|
||||
let factory = HyMT3RequestFactory(model: "test-model", keepAlive: "5m")
|
||||
let request = factory.translationRequest(text: "Hello.", target: HyMT3Languages.german)
|
||||
let message = try #require(request.messages.first)
|
||||
#expect(request.messages.count == 1)
|
||||
#expect(
|
||||
message.content
|
||||
== "Translate the following text into German. "
|
||||
+ "Note that you should **only output the translated result without any additional explanation**:"
|
||||
+ "\n\nHello."
|
||||
)
|
||||
#expect(request.model == "test-model")
|
||||
#expect(request.keepAlive == "5m")
|
||||
#expect(request.options.numPredict == 4096)
|
||||
#expect(request.options.numCtx == 8192)
|
||||
#expect(request.options.temperature == 0.7)
|
||||
#expect(request.options.topP == 0.6)
|
||||
#expect(request.options.topK == 20)
|
||||
#expect(request.options.repeatPenalty == 1.05)
|
||||
}
|
||||
|
||||
@Test func promptMatchesTheGoldenFixture() throws {
|
||||
let base = try #require(Bundle.module.resourceURL)
|
||||
let url = base.appendingPathComponent("Fixtures/default-prompt.txt")
|
||||
let template = try String(contentsOf: url, encoding: .utf8)
|
||||
.trimmingCharacters(in: .newlines)
|
||||
let expected = template
|
||||
.replacingOccurrences(of: "{target_lang}", with: "German")
|
||||
.replacingOccurrences(of: "{source_text}", with: "Hello.")
|
||||
#expect(
|
||||
HyMT3Prompt.defaultTranslation(target: HyMT3Languages.german, source: "Hello.")
|
||||
== expected
|
||||
)
|
||||
}
|
||||
|
||||
@Test func promptPrefixIsStableForTheSameTarget() {
|
||||
let factory = HyMT3RequestFactory()
|
||||
let first = factory.translationRequest(text: "One.", target: HyMT3Languages.german)
|
||||
let second = factory.translationRequest(text: "Two.", target: HyMT3Languages.german)
|
||||
let firstContent = first.messages[0].content
|
||||
let secondContent = second.messages[0].content
|
||||
let suffix = "\n\n"
|
||||
let firstPrefix = firstContent.components(separatedBy: suffix)[0]
|
||||
let secondPrefix = secondContent.components(separatedBy: suffix)[0]
|
||||
#expect(firstPrefix == secondPrefix)
|
||||
#expect(firstContent.hasSuffix("One."))
|
||||
#expect(secondContent.hasSuffix("Two."))
|
||||
}
|
||||
|
||||
@Test func resolvesOnlyTheProvisionalCommonLanguages() {
|
||||
#expect(HyMT3Languages.resolve("de") == HyMT3Languages.german)
|
||||
#expect(HyMT3Languages.resolve("EN") == HyMT3Languages.english)
|
||||
#expect(HyMT3Languages.resolve("zh-Hant")?.modelName == "Traditional Chinese")
|
||||
#expect(HyMT3Languages.resolve("xx") == nil)
|
||||
#expect(HyMT3Languages.all.count == 16)
|
||||
}
|
||||
|
||||
@Test func optionsMatchTheDocumentedPublisherValues() {
|
||||
#expect(HyMT3Options.translation.temperature == 0.7)
|
||||
#expect(HyMT3Options.translation.topP == 0.6)
|
||||
#expect(HyMT3Options.translation.topK == 20)
|
||||
#expect(HyMT3Options.translation.repeatPenalty == 1.05)
|
||||
#expect(HyMT3Options.translation.numPredict == 4096)
|
||||
#expect(HyMT3Options.translation.numCtx == 8192)
|
||||
#expect(HyMT3Options.warmUp.numPredict == 8)
|
||||
}
|
||||
}
|
||||
-5
@@ -2,11 +2,6 @@ import Foundation
|
||||
import Testing
|
||||
@testable import SprachmittlerEngines
|
||||
|
||||
@Test func moduleLinks() {
|
||||
#expect(SprachmittlerEnginesModule.moduleName == "SprachmittlerEngines")
|
||||
}
|
||||
|
||||
/// T2.2 will replace this with a byte-exact comparison against the adapter's prompt.
|
||||
@Test func canonicalDefaultPromptFixtureIsTheDocumentedTemplate() throws {
|
||||
let base = try #require(Bundle.module.resourceURL)
|
||||
let url = base.appendingPathComponent("Fixtures/default-prompt.txt")
|
||||
Reference in new issue
Block a user