f512d94c74
git-subtree-dir: clients/ds-app git-subtree-mainline:a24e3e6f22git-subtree-split:5206cf3b0c
29 lines
1.2 KiB
Swift
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)
|
|
}
|
|
}
|