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
@testable import SummarizeKit
/// Mock implementation of a real LiteLLMClient for testing the session and responses.
/// This allows injecting controlled outputs or errors without calling the real inference backend.
final class MockLiteLLMClient: LiteLLMClientProtocol {
var respondWith: [String] = [""]
var respondWithError: Error?
func requestChatCompletion(
messages: [LiteLLMMessage],
options: LiteLLMChatOptions
) async throws -> String {
if let error = respondWithError { throw error }
return respondWith.joined(separator: " ")
}
func requestChatCompletionStreamed(
messages: [LiteLLMMessage],
options: LiteLLMChatOptions
) -> AsyncThrowingStream<String, Error> {
AsyncThrowingStream<String, Error> { continuation in
if let error = respondWithError {
continuation.finish(throwing: error)
} else {
for chunk in respondWith { continuation.yield(chunk) }
continuation.finish()
}
}
}
}