import Foundation import SprachmittlerEngines import SprachmittlerOllama /// Builds the Ollama clients and pipeline from a settings snapshot. This keeps every concrete /// client in one composition helper and away from the app target. public typealias OllamaCatalog = SprachmittlerOllama.OllamaCatalog public enum AppOllama { /// A catalog for the configured endpoint. public static func makeCatalog(settings: AppSettings) throws -> any OllamaCatalog { let http = try OllamaHTTPClient( baseURL: settings.endpoint, allowRemote: settings.allowRemoteEndpoint ) return OllamaCatalogClient(http: http) } /// A translation pipeline for the configured endpoint and chunk limits. public static func makePipeline(settings: AppSettings) throws -> TranslationPipeline { let http = try OllamaHTTPClient( baseURL: settings.endpoint, allowRemote: settings.allowRemoteEndpoint ) let chat = OllamaChatClient(http: http) let registry = AdapterRegistry(adapters: [HyMT3Adapter()]) return TranslationPipeline(chat: chat, registry: registry, chunker: settings.chunker) } /// Warms the selected model with fixed synthetic text. Only for a loopback endpoint. public static func warmUp(settings: AppSettings) async throws { guard settings.warmUpOnLaunch, EndpointPolicy.isLoopback(settings.endpoint) else { return } let http = try OllamaHTTPClient( baseURL: settings.endpoint, allowRemote: settings.allowRemoteEndpoint ) let chat = OllamaChatClient(http: http) let request = HyMT3Adapter().warmUpRequest( model: settings.model, keepAlive: settings.keepModelLoaded ) try await OllamaWarmUpRunner(chat: chat).run(request) } }