2023-04-22 16:32:54 -07:00
|
|
|
import Foundation
|
|
|
|
import GRPC
|
|
|
|
import NIO
|
|
|
|
import StableDiffusionCore
|
|
|
|
import StableDiffusionProtos
|
|
|
|
|
|
|
|
struct StableDiffusionClient {
|
|
|
|
let group: EventLoopGroup
|
|
|
|
let channel: GRPCChannel
|
|
|
|
|
|
|
|
let modelService: SdModelServiceAsyncClient
|
2023-05-08 22:12:24 -07:00
|
|
|
let hostModelService: SdHostModelServiceAsyncClient
|
2023-04-22 16:32:54 -07:00
|
|
|
let imageGenerationService: SdImageGenerationServiceAsyncClient
|
2023-05-08 22:12:24 -07:00
|
|
|
let tokenizerService: SdTokenizerServiceAsyncClient
|
|
|
|
let jobService: SdJobServiceAsyncClient
|
|
|
|
let serverMetadataService: SdServerMetadataServiceAsyncClient
|
2023-04-22 16:32:54 -07:00
|
|
|
|
|
|
|
init(connectionTarget: ConnectionTarget, transportSecurity: GRPCChannelPool.Configuration.TransportSecurity) throws {
|
|
|
|
group = PlatformSupport.makeEventLoopGroup(loopCount: 1)
|
|
|
|
|
|
|
|
channel = try GRPCChannelPool.with(
|
|
|
|
target: connectionTarget,
|
|
|
|
transportSecurity: transportSecurity,
|
|
|
|
eventLoopGroup: group
|
|
|
|
)
|
|
|
|
|
|
|
|
modelService = SdModelServiceAsyncClient(channel: channel)
|
2023-05-08 22:12:24 -07:00
|
|
|
hostModelService = SdHostModelServiceAsyncClient(channel: channel)
|
2023-04-22 16:32:54 -07:00
|
|
|
imageGenerationService = SdImageGenerationServiceAsyncClient(channel: channel)
|
2023-05-08 22:12:24 -07:00
|
|
|
tokenizerService = SdTokenizerServiceAsyncClient(channel: channel)
|
|
|
|
jobService = SdJobServiceAsyncClient(channel: channel)
|
|
|
|
serverMetadataService = SdServerMetadataServiceAsyncClient(channel: channel)
|
2023-04-22 16:32:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func close() async throws {
|
|
|
|
try await group.shutdownGracefully()
|
|
|
|
}
|
|
|
|
}
|