Revision control
Copy as Markdown
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
import Foundation
import MLPAKit
import LLMKit
import Shared
// MARK: - Protocol
/// Creates a ResultsService with using MLPA (App Attest) authentication and LiteLLM.
protocol ResultsServiceFactory {
func make(prefs: Prefs, configFetcher: QuickAnswersConfigFetcher) throws -> ResultsService
}
// MARK: - Default Implementation
public struct DefaultResultsServiceFactory: ResultsServiceFactory {
let liteLLMCreator: LiteLLMCreating
public init(liteLLMCreator: LiteLLMCreating) {
self.liteLLMCreator = liteLLMCreator
}
func make(
prefs: Prefs,
configFetcher: QuickAnswersConfigFetcher
) throws -> ResultsService {
guard let client = makeLiteLLMClient(prefs: prefs, model: configFetcher.feature.model) else {
throw ResultsServiceError.unableToCreateService
}
return DefaultResultsService(client: client, configFetcher: configFetcher)
}
// MARK: - Private Helpers
private func makeLiteLLMClient(prefs: Prefs, model: QuickAnswersModel) -> LiteLLMClientProtocol? {
return liteLLMCreator.createAppAttestLiteLLM(using: prefs, serviceType: model.serviceType)
}
}