Files
hyungi_document_server/clients/ds-app/Tests/AITests/TestProviders.swift
T

29 lines
1.2 KiB
Swift

import Foundation
@testable import AIFabric
/// providerUsed=id provider(MockAIProvider providerUsed ).
struct EchoProvider: AIProvider {
let id: AIProviderID
let available: Bool
init(id: AIProviderID, available: Bool = true) {
self.id = id
self.available = available
}
var isAvailable: Bool { get async { available } }
func complete(_ request: AICompletionRequest) async throws -> AICompletionResponse {
AICompletionResponse(text: "echo:\(id.rawValue)", providerUsed: id)
}
}
/// sleep Task CancellationError(S2-Fe URLSession ).
struct SleepingProvider: AIProvider {
let id: AIProviderID
init(id: AIProviderID = .localMLX) { self.id = id }
var isAvailable: Bool { get async { true } }
func complete(_ request: AICompletionRequest) async throws -> AICompletionResponse {
try await Task.sleep(nanoseconds: 5_000_000_000) // CancellationError throw
try Task.checkCancellation()
return AICompletionResponse(text: "done", providerUsed: id)
}
}