diff --git a/Clients/Cpp/sample.cpp b/Clients/Cpp/sample.cpp index 3fc2155..5d23575 100644 --- a/Clients/Cpp/sample.cpp +++ b/Clients/Cpp/sample.cpp @@ -1,25 +1,11 @@ #include "host.grpc.pb.h" +#include "model.grpc.pb.h" #include "image_generation.grpc.pb.h" #include using namespace gay::pizza::stable::diffusion; -int CompareModelInfoByLoadedFirst(ModelInfo& left, ModelInfo& right) { - if (left.is_loaded() && right.is_loaded()) { - return 0; - } - - if (left.is_loaded()) { - return 1; - } - - if (right.is_loaded()) { - return -1; - } - return 0; -} - int main() { auto channel = grpc::CreateChannel("localhost:4546", grpc::InsecureChannelCredentials()); auto modelService = ModelService::NewStub(channel); @@ -34,9 +20,5 @@ int main() { for (const auto &item: models) { std::cout << "Model Name: " << item.name() << std::endl; } - - std::sort(models.begin(), models.end(), CompareModelInfoByLoadedFirst); - auto model = models.begin(); - std::cout << "Chosen Model: " << model->name() << std::endl; return 0; } diff --git a/Clients/Java/sample/src/main/kotlin/gay/pizza/stable/diffusion/sample/main.kt b/Clients/Java/sample/src/main/kotlin/gay/pizza/stable/diffusion/sample/main.kt index d5556e1..0cac790 100644 --- a/Clients/Java/sample/src/main/kotlin/gay/pizza/stable/diffusion/sample/main.kt +++ b/Clients/Java/sample/src/main/kotlin/gay/pizza/stable/diffusion/sample/main.kt @@ -49,8 +49,7 @@ fun main(args: Array) { } println("available models:") for (model in modelListResponse.availableModelsList) { - val maybeLoadedComputeUnits = if (model.isLoaded) " loaded_compute_units=${model.loadedComputeUnits.name}" else "" - println(" model ${model.name} attention=${model.attention} loaded=${model.isLoaded}${maybeLoadedComputeUnits}") + println(" model ${model.name} attention=${model.attention}") } val model = if (chosenModelName == null) { @@ -59,15 +58,11 @@ fun main(args: Array) { modelListResponse.availableModelsList.first { it.name == chosenModelName } } - if (!model.isLoaded) { - println("loading model ${model.name}...") - client.modelServiceBlocking.loadModel(LoadModelRequest.newBuilder().apply { - modelName = model.name - computeUnits = model.supportedComputeUnitsList.first() - }.build()) - } else { - println("using model ${model.name}...") - } + println("loading model ${model.name}...") + client.hostModelServiceBlocking.loadModel(LoadModelRequest.newBuilder().apply { + modelName = model.name + computeUnits = model.supportedComputeUnitsList.first() + }.build()) println("tokenizing prompts...") diff --git a/Clients/Java/src/main/kotlin/gay/pizza/stable/diffusion/StableDiffusionRpcClient.kt b/Clients/Java/src/main/kotlin/gay/pizza/stable/diffusion/StableDiffusionRpcClient.kt index 58275ab..65aafb3 100644 --- a/Clients/Java/src/main/kotlin/gay/pizza/stable/diffusion/StableDiffusionRpcClient.kt +++ b/Clients/Java/src/main/kotlin/gay/pizza/stable/diffusion/StableDiffusionRpcClient.kt @@ -20,6 +20,22 @@ class StableDiffusionRpcClient(val channel: Channel) { ModelServiceGrpcKt.ModelServiceCoroutineStub(channel) } + val hostModelService: HostModelServiceGrpc.HostModelServiceStub by lazy { + HostModelServiceGrpc.newStub(channel) + } + + val hostModelServiceBlocking: HostModelServiceGrpc.HostModelServiceBlockingStub by lazy { + HostModelServiceGrpc.newBlockingStub(channel) + } + + val hostModelServiceFuture: HostModelServiceGrpc.HostModelServiceFutureStub by lazy { + HostModelServiceGrpc.newFutureStub(channel) + } + + val hostModelServiceCoroutine: HostModelServiceGrpcKt.HostModelServiceCoroutineStub by lazy { + HostModelServiceGrpcKt.HostModelServiceCoroutineStub(channel) + } + val imageGenerationService: ImageGenerationServiceGrpc.ImageGenerationServiceStub by lazy { ImageGenerationServiceGrpc.newStub(channel) } diff --git a/Common/host.proto b/Common/host.proto index 713e6e0..6b1fc5c 100644 --- a/Common/host.proto +++ b/Common/host.proto @@ -11,21 +11,6 @@ import "shared.proto"; option swift_prefix = "Sd"; option java_multiple_files = true; -/** - * Represents a request to list the models available on the host. - */ -message ListModelsRequest {} - -/** - * Represents a response to listing the models available on the host. - */ -message ListModelsResponse { - /** - * The available models on the Stable Diffusion server. - */ - repeated ModelInfo available_models = 1; -} - /** * Represents a request to load a model into a specified compute unit. */ @@ -49,13 +34,7 @@ message LoadModelResponse {} /** * The model service, for management and loading of models. */ -service ModelService { - /** - * Lists the available models on the host. - * This will return both models that are currently loaded, and models that are not yet loaded. - */ - rpc ListModels(ListModelsRequest) returns (ListModelsResponse); - +service HostModelService { /** * Loads a model onto a compute unit. */ diff --git a/Common/jobs.proto b/Common/jobs.proto index 9539435..d160cc6 100644 --- a/Common/jobs.proto +++ b/Common/jobs.proto @@ -17,7 +17,7 @@ enum JobState { /** * The job is in an unknown state. */ - unknown = 0; + unknown_state = 0; /** * The job is queued. It has not started the work. diff --git a/Common/metadata.proto b/Common/metadata.proto new file mode 100644 index 0000000..f0d95f0 --- /dev/null +++ b/Common/metadata.proto @@ -0,0 +1,30 @@ +/** + * Server metadata for the Stable Diffusion RPC service. + */ +syntax = "proto3"; +package gay.pizza.stable.diffusion; + +/** + * Utilize a prefix of 'Sd' for Swift. + */ +option swift_prefix = "Sd"; +option java_multiple_files = true; + +enum ServerRole { + unknown_role = 0; + node = 1; + coordinator = 2; +} + +message ServerMetadata { + ServerRole role = 1; +} + +message GetServerMetadataRequest {} +message GetServerMetadataResponse { + ServerMetadata metadata = 1; +} + +service ServerMetadataService { + rpc GetServerMetadata(GetServerMetadataRequest) returns (GetServerMetadataResponse); +} diff --git a/Common/model.proto b/Common/model.proto new file mode 100644 index 0000000..49e3be1 --- /dev/null +++ b/Common/model.proto @@ -0,0 +1,38 @@ +/** + * Host management for the Stable Diffusion RPC service. + */ +syntax = "proto3"; +package gay.pizza.stable.diffusion; +import "shared.proto"; + +/** + * Utilize a prefix of 'Sd' for Swift. + */ +option swift_prefix = "Sd"; +option java_multiple_files = true; + +/** + * Represents a request to list the models available on the host. + */ +message ListModelsRequest {} + +/** + * Represents a response to listing the models available on the host. + */ +message ListModelsResponse { + /** + * The available models on the Stable Diffusion server. + */ + repeated ModelInfo available_models = 1; +} + +/** + * The model service, for management and loading of models. + */ +service ModelService { + /** + * Lists the available models on the host. + * This will return both models that are currently loaded, and models that are not yet loaded. + */ + rpc ListModels(ListModelsRequest) returns (ListModelsResponse); +} diff --git a/Common/shared.proto b/Common/shared.proto index 93d9fb6..b4b26b4 100644 --- a/Common/shared.proto +++ b/Common/shared.proto @@ -10,6 +10,21 @@ package gay.pizza.stable.diffusion; option swift_prefix = "Sd"; option java_multiple_files = true; +/** + * Represents a 128-bit UUID value. + */ +message UniqueIdentifier { + /** + * The upper bits of the UUID. + */ + uint64 upper_bits = 1; + + /** + * The lower bits of the UUID. + */ + uint64 lower_bits = 2; +} + /** * Represents the model attention. Model attention has to do with how the model is encoded, and * can determine what compute units are able to support a particular model. @@ -73,9 +88,7 @@ enum ComputeUnits { */ message ModelInfo { /** - * The name of the available model. Note that within the context of a single RPC server, - * the name of a model is a unique identifier. This may not be true when utilizing a cluster or - * load balanced server, so keep that in mind. + * The name of the available model. Note that a model name is considered a unique identifier. */ string name = 1; @@ -85,17 +98,6 @@ message ModelInfo { */ ModelAttention attention = 2; - /** - * Whether the model is currently loaded onto an available compute unit. - */ - bool is_loaded = 3; - - /** - * The compute unit that the model is currently loaded into, if it is loaded to one at all. - * When is_loaded is false, the value of this field should be null. - */ - ComputeUnits loaded_compute_units = 4; - /** * The compute units that this model supports using. */ diff --git a/Package.swift b/Package.swift index 7317e09..b063a60 100644 --- a/Package.swift +++ b/Package.swift @@ -5,7 +5,7 @@ let package = Package( name: "stable-diffusion-rpc", platforms: [.macOS("13.1"), .iOS("16.2")], products: [ - .executable(name: "stable-diffusion-rpc", targets: ["StableDiffusionServer"]), + .executable(name: "stable-diffusion-rpc", targets: ["StableDiffusionNode"]), .library(name: "StableDiffusionProtos", targets: ["StableDiffusionProtos"]), .executable(name: "stable-diffusion-ctl", targets: ["StableDiffusionControl"]) ], @@ -24,7 +24,7 @@ let package = Package( .product(name: "StableDiffusion", package: "ml-stable-diffusion"), .target(name: "StableDiffusionProtos") ]), - .executableTarget(name: "StableDiffusionServer", dependencies: [ + .executableTarget(name: "StableDiffusionNode", dependencies: [ .product(name: "StableDiffusion", package: "ml-stable-diffusion"), .product(name: "SwiftProtobuf", package: "swift-protobuf"), .product(name: "GRPC", package: "grpc-swift"), diff --git a/Sources/StableDiffusionControl/StableDiffusionClient.swift b/Sources/StableDiffusionControl/StableDiffusionClient.swift index 2c0d90a..b136ade 100644 --- a/Sources/StableDiffusionControl/StableDiffusionClient.swift +++ b/Sources/StableDiffusionControl/StableDiffusionClient.swift @@ -9,7 +9,11 @@ struct StableDiffusionClient { let channel: GRPCChannel let modelService: SdModelServiceAsyncClient + let hostModelService: SdHostModelServiceAsyncClient let imageGenerationService: SdImageGenerationServiceAsyncClient + let tokenizerService: SdTokenizerServiceAsyncClient + let jobService: SdJobServiceAsyncClient + let serverMetadataService: SdServerMetadataServiceAsyncClient init(connectionTarget: ConnectionTarget, transportSecurity: GRPCChannelPool.Configuration.TransportSecurity) throws { group = PlatformSupport.makeEventLoopGroup(loopCount: 1) @@ -21,7 +25,11 @@ struct StableDiffusionClient { ) modelService = SdModelServiceAsyncClient(channel: channel) + hostModelService = SdHostModelServiceAsyncClient(channel: channel) imageGenerationService = SdImageGenerationServiceAsyncClient(channel: channel) + tokenizerService = SdTokenizerServiceAsyncClient(channel: channel) + jobService = SdJobServiceAsyncClient(channel: channel) + serverMetadataService = SdServerMetadataServiceAsyncClient(channel: channel) } func close() async throws { diff --git a/Sources/StableDiffusionControl/main.swift b/Sources/StableDiffusionControl/main.swift index eb8801c..fcf645a 100644 --- a/Sources/StableDiffusionControl/main.swift +++ b/Sources/StableDiffusionControl/main.swift @@ -11,7 +11,7 @@ Task { @MainActor in let modelListResponse = try await client.modelService.listModels(.init()) print("Loading random model...") let modelInfo = modelListResponse.availableModels.randomElement()! - _ = try await client.modelService.loadModel(.with { request in + _ = try await client.hostModelService.loadModel(.with { request in request.modelName = modelInfo.name }) print("Loaded random model.") diff --git a/Sources/StableDiffusionCore/ModelManager.swift b/Sources/StableDiffusionCore/ModelManager.swift index c2340f8..d06d2b9 100644 --- a/Sources/StableDiffusionCore/ModelManager.swift +++ b/Sources/StableDiffusionCore/ModelManager.swift @@ -32,15 +32,6 @@ public actor ModelManager { var results: [SdModelInfo] = [] for simpleInfo in modelInfos.values { var info = try SdModelInfo(jsonString: simpleInfo.jsonString()) - if let maybeLoaded = modelStates[info.name] { - info.isLoaded = await maybeLoaded.isModelLoaded() - if let loadedComputeUnits = await maybeLoaded.loadedModelComputeUnits() { - info.loadedComputeUnits = loadedComputeUnits - } - } else { - info.isLoaded = false - info.loadedComputeUnits = .init() - } if info.attention == .splitEinSum { info.supportedComputeUnits = [ diff --git a/Sources/StableDiffusionNode/HostModelService.swift b/Sources/StableDiffusionNode/HostModelService.swift new file mode 100644 index 0000000..dc51a1a --- /dev/null +++ b/Sources/StableDiffusionNode/HostModelService.swift @@ -0,0 +1,18 @@ +import Foundation +import GRPC +import StableDiffusionCore +import StableDiffusionProtos + +class HostModelServiceProvider: SdHostModelServiceAsyncProvider { + private let modelManager: ModelManager + + init(modelManager: ModelManager) { + self.modelManager = modelManager + } + + func loadModel(request: SdLoadModelRequest, context _: GRPCAsyncServerCallContext) async throws -> SdLoadModelResponse { + let state = try await modelManager.createModelState(name: request.modelName) + try await state.load(request: request) + return SdLoadModelResponse() + } +} diff --git a/Sources/StableDiffusionServer/ImageGenerationService.swift b/Sources/StableDiffusionNode/ImageGenerationService.swift similarity index 100% rename from Sources/StableDiffusionServer/ImageGenerationService.swift rename to Sources/StableDiffusionNode/ImageGenerationService.swift diff --git a/Sources/StableDiffusionServer/JobService.swift b/Sources/StableDiffusionNode/JobService.swift similarity index 100% rename from Sources/StableDiffusionServer/JobService.swift rename to Sources/StableDiffusionNode/JobService.swift diff --git a/Sources/StableDiffusionServer/ModelService.swift b/Sources/StableDiffusionNode/ModelService.swift similarity index 66% rename from Sources/StableDiffusionServer/ModelService.swift rename to Sources/StableDiffusionNode/ModelService.swift index 1a36dbf..d23d93e 100644 --- a/Sources/StableDiffusionServer/ModelService.swift +++ b/Sources/StableDiffusionNode/ModelService.swift @@ -16,10 +16,4 @@ class ModelServiceProvider: SdModelServiceAsyncProvider { response.availableModels.append(contentsOf: models) return response } - - func loadModel(request: SdLoadModelRequest, context _: GRPCAsyncServerCallContext) async throws -> SdLoadModelResponse { - let state = try await modelManager.createModelState(name: request.modelName) - try await state.load(request: request) - return SdLoadModelResponse() - } } diff --git a/Sources/StableDiffusionNode/ServerMetadataService.swift b/Sources/StableDiffusionNode/ServerMetadataService.swift new file mode 100644 index 0000000..ae5027e --- /dev/null +++ b/Sources/StableDiffusionNode/ServerMetadataService.swift @@ -0,0 +1,14 @@ +import Foundation +import GRPC +import StableDiffusionCore +import StableDiffusionProtos + +class ServerMetadataServiceProvider: SdServerMetadataServiceAsyncProvider { + func getServerMetadata(request _: SdGetServerMetadataRequest, context _: GRPCAsyncServerCallContext) async throws -> SdGetServerMetadataResponse { + .with { response in + response.metadata = .with { metadata in + metadata.role = .node + } + } + } +} diff --git a/Sources/StableDiffusionServer/TokenizerService.swift b/Sources/StableDiffusionNode/TokenizerService.swift similarity index 100% rename from Sources/StableDiffusionServer/TokenizerService.swift rename to Sources/StableDiffusionNode/TokenizerService.swift diff --git a/Sources/StableDiffusionServer/main.swift b/Sources/StableDiffusionNode/main.swift similarity index 85% rename from Sources/StableDiffusionServer/main.swift rename to Sources/StableDiffusionNode/main.swift index adb6ced..eea960d 100644 --- a/Sources/StableDiffusionServer/main.swift +++ b/Sources/StableDiffusionNode/main.swift @@ -35,13 +35,15 @@ struct ServerCommand: ParsableCommand { _ = Server.insecure(group: group) .withServiceProviders([ ModelServiceProvider(modelManager: modelManager), + HostModelServiceProvider(modelManager: modelManager), ImageGenerationServiceProvider(jobManager: jobManager, modelManager: modelManager), TokenizerServiceProvider(modelManager: modelManager), - JobServiceProvider(jobManager: jobManager) + JobServiceProvider(jobManager: jobManager), + ServerMetadataServiceProvider() ]) .bind(host: bindHost, port: bindPort) - print("Stable Diffusion RPC running on \(bindHost):\(bindPort)") + print("Stable Diffusion RPC node running on \(bindHost):\(bindPort)") dispatchMain() } diff --git a/Sources/StableDiffusionProtos/host.grpc.swift b/Sources/StableDiffusionProtos/host.grpc.swift index 20dff0c..8612409 100644 --- a/Sources/StableDiffusionProtos/host.grpc.swift +++ b/Sources/StableDiffusionProtos/host.grpc.swift @@ -29,15 +29,10 @@ import SwiftProtobuf ///* /// The model service, for management and loading of models. /// -/// Usage: instantiate `SdModelServiceClient`, then call methods of this protocol to make API calls. -public protocol SdModelServiceClientProtocol: GRPCClient { +/// Usage: instantiate `SdHostModelServiceClient`, then call methods of this protocol to make API calls. +public protocol SdHostModelServiceClientProtocol: GRPCClient { var serviceName: String { get } - var interceptors: SdModelServiceClientInterceptorFactoryProtocol? { get } - - func listModels( - _ request: SdListModelsRequest, - callOptions: CallOptions? - ) -> UnaryCall + var interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? { get } func loadModel( _ request: SdLoadModelRequest, @@ -45,29 +40,9 @@ public protocol SdModelServiceClientProtocol: GRPCClient { ) -> UnaryCall } -extension SdModelServiceClientProtocol { +extension SdHostModelServiceClientProtocol { public var serviceName: String { - return "gay.pizza.stable.diffusion.ModelService" - } - - ///* - /// Lists the available models on the host. - /// This will return both models that are currently loaded, and models that are not yet loaded. - /// - /// - Parameters: - /// - request: Request to send to ListModels. - /// - callOptions: Call options. - /// - Returns: A `UnaryCall` with futures for the metadata, status and response. - public func listModels( - _ request: SdListModelsRequest, - callOptions: CallOptions? = nil - ) -> UnaryCall { - return self.makeUnaryCall( - path: SdModelServiceClientMetadata.Methods.listModels.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makeListModelsInterceptors() ?? [] - ) + return "gay.pizza.stable.diffusion.HostModelService" } ///* @@ -82,7 +57,7 @@ extension SdModelServiceClientProtocol { callOptions: CallOptions? = nil ) -> UnaryCall { return self.makeUnaryCall( - path: SdModelServiceClientMetadata.Methods.loadModel.path, + path: SdHostModelServiceClientMetadata.Methods.loadModel.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeLoadModelInterceptors() ?? [] @@ -92,25 +67,25 @@ extension SdModelServiceClientProtocol { #if compiler(>=5.6) @available(*, deprecated) -extension SdModelServiceClient: @unchecked Sendable {} +extension SdHostModelServiceClient: @unchecked Sendable {} #endif // compiler(>=5.6) -@available(*, deprecated, renamed: "SdModelServiceNIOClient") -public final class SdModelServiceClient: SdModelServiceClientProtocol { +@available(*, deprecated, renamed: "SdHostModelServiceNIOClient") +public final class SdHostModelServiceClient: SdHostModelServiceClientProtocol { private let lock = Lock() private var _defaultCallOptions: CallOptions - private var _interceptors: SdModelServiceClientInterceptorFactoryProtocol? + private var _interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? public let channel: GRPCChannel public var defaultCallOptions: CallOptions { get { self.lock.withLock { return self._defaultCallOptions } } set { self.lock.withLockVoid { self._defaultCallOptions = newValue } } } - public var interceptors: SdModelServiceClientInterceptorFactoryProtocol? { + public var interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? { get { self.lock.withLock { return self._interceptors } } set { self.lock.withLockVoid { self._interceptors = newValue } } } - /// Creates a client for the gay.pizza.stable.diffusion.ModelService service. + /// Creates a client for the gay.pizza.stable.diffusion.HostModelService service. /// /// - Parameters: /// - channel: `GRPCChannel` to the service host. @@ -119,7 +94,7 @@ public final class SdModelServiceClient: SdModelServiceClientProtocol { public init( channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions(), - interceptors: SdModelServiceClientInterceptorFactoryProtocol? = nil + interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? = nil ) { self.channel = channel self._defaultCallOptions = defaultCallOptions @@ -127,12 +102,12 @@ public final class SdModelServiceClient: SdModelServiceClientProtocol { } } -public struct SdModelServiceNIOClient: SdModelServiceClientProtocol { +public struct SdHostModelServiceNIOClient: SdHostModelServiceClientProtocol { public var channel: GRPCChannel public var defaultCallOptions: CallOptions - public var interceptors: SdModelServiceClientInterceptorFactoryProtocol? + public var interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? - /// Creates a client for the gay.pizza.stable.diffusion.ModelService service. + /// Creates a client for the gay.pizza.stable.diffusion.HostModelService service. /// /// - Parameters: /// - channel: `GRPCChannel` to the service host. @@ -141,7 +116,7 @@ public struct SdModelServiceNIOClient: SdModelServiceClientProtocol { public init( channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions(), - interceptors: SdModelServiceClientInterceptorFactoryProtocol? = nil + interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? = nil ) { self.channel = channel self.defaultCallOptions = defaultCallOptions @@ -153,14 +128,9 @@ public struct SdModelServiceNIOClient: SdModelServiceClientProtocol { ///* /// The model service, for management and loading of models. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -public protocol SdModelServiceAsyncClientProtocol: GRPCClient { +public protocol SdHostModelServiceAsyncClientProtocol: GRPCClient { static var serviceDescriptor: GRPCServiceDescriptor { get } - var interceptors: SdModelServiceClientInterceptorFactoryProtocol? { get } - - func makeListModelsCall( - _ request: SdListModelsRequest, - callOptions: CallOptions? - ) -> GRPCAsyncUnaryCall + var interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? { get } func makeLoadModelCall( _ request: SdLoadModelRequest, @@ -169,33 +139,21 @@ public protocol SdModelServiceAsyncClientProtocol: GRPCClient { } @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -extension SdModelServiceAsyncClientProtocol { +extension SdHostModelServiceAsyncClientProtocol { public static var serviceDescriptor: GRPCServiceDescriptor { - return SdModelServiceClientMetadata.serviceDescriptor + return SdHostModelServiceClientMetadata.serviceDescriptor } - public var interceptors: SdModelServiceClientInterceptorFactoryProtocol? { + public var interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? { return nil } - public func makeListModelsCall( - _ request: SdListModelsRequest, - callOptions: CallOptions? = nil - ) -> GRPCAsyncUnaryCall { - return self.makeAsyncUnaryCall( - path: SdModelServiceClientMetadata.Methods.listModels.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makeListModelsInterceptors() ?? [] - ) - } - public func makeLoadModelCall( _ request: SdLoadModelRequest, callOptions: CallOptions? = nil ) -> GRPCAsyncUnaryCall { return self.makeAsyncUnaryCall( - path: SdModelServiceClientMetadata.Methods.loadModel.path, + path: SdHostModelServiceClientMetadata.Methods.loadModel.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeLoadModelInterceptors() ?? [] @@ -204,25 +162,13 @@ extension SdModelServiceAsyncClientProtocol { } @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -extension SdModelServiceAsyncClientProtocol { - public func listModels( - _ request: SdListModelsRequest, - callOptions: CallOptions? = nil - ) async throws -> SdListModelsResponse { - return try await self.performAsyncUnaryCall( - path: SdModelServiceClientMetadata.Methods.listModels.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makeListModelsInterceptors() ?? [] - ) - } - +extension SdHostModelServiceAsyncClientProtocol { public func loadModel( _ request: SdLoadModelRequest, callOptions: CallOptions? = nil ) async throws -> SdLoadModelResponse { return try await self.performAsyncUnaryCall( - path: SdModelServiceClientMetadata.Methods.loadModel.path, + path: SdHostModelServiceClientMetadata.Methods.loadModel.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeLoadModelInterceptors() ?? [] @@ -231,15 +177,15 @@ extension SdModelServiceAsyncClientProtocol { } @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -public struct SdModelServiceAsyncClient: SdModelServiceAsyncClientProtocol { +public struct SdHostModelServiceAsyncClient: SdHostModelServiceAsyncClientProtocol { public var channel: GRPCChannel public var defaultCallOptions: CallOptions - public var interceptors: SdModelServiceClientInterceptorFactoryProtocol? + public var interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? public init( channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions(), - interceptors: SdModelServiceClientInterceptorFactoryProtocol? = nil + interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? = nil ) { self.channel = channel self.defaultCallOptions = defaultCallOptions @@ -249,35 +195,25 @@ public struct SdModelServiceAsyncClient: SdModelServiceAsyncClientProtocol { #endif // compiler(>=5.6) -public protocol SdModelServiceClientInterceptorFactoryProtocol: GRPCSendable { - - /// - Returns: Interceptors to use when invoking 'listModels'. - func makeListModelsInterceptors() -> [ClientInterceptor] +public protocol SdHostModelServiceClientInterceptorFactoryProtocol: GRPCSendable { /// - Returns: Interceptors to use when invoking 'loadModel'. func makeLoadModelInterceptors() -> [ClientInterceptor] } -public enum SdModelServiceClientMetadata { +public enum SdHostModelServiceClientMetadata { public static let serviceDescriptor = GRPCServiceDescriptor( - name: "ModelService", - fullName: "gay.pizza.stable.diffusion.ModelService", + name: "HostModelService", + fullName: "gay.pizza.stable.diffusion.HostModelService", methods: [ - SdModelServiceClientMetadata.Methods.listModels, - SdModelServiceClientMetadata.Methods.loadModel, + SdHostModelServiceClientMetadata.Methods.loadModel, ] ) public enum Methods { - public static let listModels = GRPCMethodDescriptor( - name: "ListModels", - path: "/gay.pizza.stable.diffusion.ModelService/ListModels", - type: GRPCCallType.unary - ) - public static let loadModel = GRPCMethodDescriptor( name: "LoadModel", - path: "/gay.pizza.stable.diffusion.ModelService/LoadModel", + path: "/gay.pizza.stable.diffusion.HostModelService/LoadModel", type: GRPCCallType.unary ) } @@ -287,22 +223,17 @@ public enum SdModelServiceClientMetadata { /// The model service, for management and loading of models. /// /// To build a server, implement a class that conforms to this protocol. -public protocol SdModelServiceProvider: CallHandlerProvider { - var interceptors: SdModelServiceServerInterceptorFactoryProtocol? { get } - - ///* - /// Lists the available models on the host. - /// This will return both models that are currently loaded, and models that are not yet loaded. - func listModels(request: SdListModelsRequest, context: StatusOnlyCallContext) -> EventLoopFuture +public protocol SdHostModelServiceProvider: CallHandlerProvider { + var interceptors: SdHostModelServiceServerInterceptorFactoryProtocol? { get } ///* /// Loads a model onto a compute unit. func loadModel(request: SdLoadModelRequest, context: StatusOnlyCallContext) -> EventLoopFuture } -extension SdModelServiceProvider { +extension SdHostModelServiceProvider { public var serviceName: Substring { - return SdModelServiceServerMetadata.serviceDescriptor.fullName[...] + return SdHostModelServiceServerMetadata.serviceDescriptor.fullName[...] } /// Determines, calls and returns the appropriate request handler, depending on the request's method. @@ -312,15 +243,6 @@ extension SdModelServiceProvider { context: CallHandlerContext ) -> GRPCServerHandlerProtocol? { switch name { - case "ListModels": - return UnaryServerHandler( - context: context, - requestDeserializer: ProtobufDeserializer(), - responseSerializer: ProtobufSerializer(), - interceptors: self.interceptors?.makeListModelsInterceptors() ?? [], - userFunction: self.listModels(request:context:) - ) - case "LoadModel": return UnaryServerHandler( context: context, @@ -343,17 +265,9 @@ extension SdModelServiceProvider { /// /// To implement a server, implement an object which conforms to this protocol. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -public protocol SdModelServiceAsyncProvider: CallHandlerProvider { +public protocol SdHostModelServiceAsyncProvider: CallHandlerProvider { static var serviceDescriptor: GRPCServiceDescriptor { get } - var interceptors: SdModelServiceServerInterceptorFactoryProtocol? { get } - - ///* - /// Lists the available models on the host. - /// This will return both models that are currently loaded, and models that are not yet loaded. - @Sendable func listModels( - request: SdListModelsRequest, - context: GRPCAsyncServerCallContext - ) async throws -> SdListModelsResponse + var interceptors: SdHostModelServiceServerInterceptorFactoryProtocol? { get } ///* /// Loads a model onto a compute unit. @@ -364,16 +278,16 @@ public protocol SdModelServiceAsyncProvider: CallHandlerProvider { } @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -extension SdModelServiceAsyncProvider { +extension SdHostModelServiceAsyncProvider { public static var serviceDescriptor: GRPCServiceDescriptor { - return SdModelServiceServerMetadata.serviceDescriptor + return SdHostModelServiceServerMetadata.serviceDescriptor } public var serviceName: Substring { - return SdModelServiceServerMetadata.serviceDescriptor.fullName[...] + return SdHostModelServiceServerMetadata.serviceDescriptor.fullName[...] } - public var interceptors: SdModelServiceServerInterceptorFactoryProtocol? { + public var interceptors: SdHostModelServiceServerInterceptorFactoryProtocol? { return nil } @@ -382,15 +296,6 @@ extension SdModelServiceAsyncProvider { context: CallHandlerContext ) -> GRPCServerHandlerProtocol? { switch name { - case "ListModels": - return GRPCAsyncServerHandler( - context: context, - requestDeserializer: ProtobufDeserializer(), - responseSerializer: ProtobufSerializer(), - interceptors: self.interceptors?.makeListModelsInterceptors() ?? [], - wrapping: self.listModels(request:context:) - ) - case "LoadModel": return GRPCAsyncServerHandler( context: context, @@ -408,37 +313,26 @@ extension SdModelServiceAsyncProvider { #endif // compiler(>=5.6) -public protocol SdModelServiceServerInterceptorFactoryProtocol { - - /// - Returns: Interceptors to use when handling 'listModels'. - /// Defaults to calling `self.makeInterceptors()`. - func makeListModelsInterceptors() -> [ServerInterceptor] +public protocol SdHostModelServiceServerInterceptorFactoryProtocol { /// - Returns: Interceptors to use when handling 'loadModel'. /// Defaults to calling `self.makeInterceptors()`. func makeLoadModelInterceptors() -> [ServerInterceptor] } -public enum SdModelServiceServerMetadata { +public enum SdHostModelServiceServerMetadata { public static let serviceDescriptor = GRPCServiceDescriptor( - name: "ModelService", - fullName: "gay.pizza.stable.diffusion.ModelService", + name: "HostModelService", + fullName: "gay.pizza.stable.diffusion.HostModelService", methods: [ - SdModelServiceServerMetadata.Methods.listModels, - SdModelServiceServerMetadata.Methods.loadModel, + SdHostModelServiceServerMetadata.Methods.loadModel, ] ) public enum Methods { - public static let listModels = GRPCMethodDescriptor( - name: "ListModels", - path: "/gay.pizza.stable.diffusion.ModelService/ListModels", - type: GRPCCallType.unary - ) - public static let loadModel = GRPCMethodDescriptor( name: "LoadModel", - path: "/gay.pizza.stable.diffusion.ModelService/LoadModel", + path: "/gay.pizza.stable.diffusion.HostModelService/LoadModel", type: GRPCCallType.unary ) } diff --git a/Sources/StableDiffusionProtos/host.pb.swift b/Sources/StableDiffusionProtos/host.pb.swift index 6518060..b50c8fb 100644 --- a/Sources/StableDiffusionProtos/host.pb.swift +++ b/Sources/StableDiffusionProtos/host.pb.swift @@ -8,7 +8,7 @@ // https://github.com/apple/swift-protobuf/ ///* -/// Host messages and services for the Stable Diffusion RPC service. +/// Host management for the Stable Diffusion RPC service. import Foundation import SwiftProtobuf @@ -23,34 +23,6 @@ fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAP typealias Version = _2 } -///* -/// Represents a request to list the models available on the host. -public struct SdListModelsRequest { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -///* -/// Represents a response to listing the models available on the host. -public struct SdListModelsResponse { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - ///* - /// The available models on the Stable Diffusion server. - public var availableModels: [SdModelInfo] = [] - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - ///* /// Represents a request to load a model into a specified compute unit. public struct SdLoadModelRequest { @@ -84,8 +56,6 @@ public struct SdLoadModelResponse { } #if swift(>=5.5) && canImport(_Concurrency) -extension SdListModelsRequest: @unchecked Sendable {} -extension SdListModelsResponse: @unchecked Sendable {} extension SdLoadModelRequest: @unchecked Sendable {} extension SdLoadModelResponse: @unchecked Sendable {} #endif // swift(>=5.5) && canImport(_Concurrency) @@ -94,57 +64,6 @@ extension SdLoadModelResponse: @unchecked Sendable {} fileprivate let _protobuf_package = "gay.pizza.stable.diffusion" -extension SdListModelsRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ListModelsRequest" - public static let _protobuf_nameMap = SwiftProtobuf._NameMap() - - public mutating func decodeMessage(decoder: inout D) throws { - while let _ = try decoder.nextFieldNumber() { - } - } - - public func traverse(visitor: inout V) throws { - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: SdListModelsRequest, rhs: SdListModelsRequest) -> Bool { - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension SdListModelsResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ListModelsResponse" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "available_models"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeRepeatedMessageField(value: &self.availableModels) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.availableModels.isEmpty { - try visitor.visitRepeatedMessageField(value: self.availableModels, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: SdListModelsResponse, rhs: SdListModelsResponse) -> Bool { - if lhs.availableModels != rhs.availableModels {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - extension SdLoadModelRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { public static let protoMessageName: String = _protobuf_package + ".LoadModelRequest" public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ diff --git a/Sources/StableDiffusionProtos/jobs.pb.swift b/Sources/StableDiffusionProtos/jobs.pb.swift index f0c3130..6de9e31 100644 --- a/Sources/StableDiffusionProtos/jobs.pb.swift +++ b/Sources/StableDiffusionProtos/jobs.pb.swift @@ -8,7 +8,7 @@ // https://github.com/apple/swift-protobuf/ ///* -/// Stable Diffusion RPC service for Apple Platforms. +/// Job management for the Stable Diffusion RPC service. import Foundation import SwiftProtobuf @@ -30,7 +30,7 @@ public enum SdJobState: SwiftProtobuf.Enum { ///* /// The job is in an unknown state. - case unknown // = 0 + case unknownState // = 0 ///* /// The job is queued. It has not started the work. @@ -50,12 +50,12 @@ public enum SdJobState: SwiftProtobuf.Enum { case UNRECOGNIZED(Int) public init() { - self = .unknown + self = .unknownState } public init?(rawValue: Int) { switch rawValue { - case 0: self = .unknown + case 0: self = .unknownState case 1: self = .queued case 2: self = .running case 3: self = .completed @@ -66,7 +66,7 @@ public enum SdJobState: SwiftProtobuf.Enum { public var rawValue: Int { switch self { - case .unknown: return 0 + case .unknownState: return 0 case .queued: return 1 case .running: return 2 case .completed: return 3 @@ -82,7 +82,7 @@ public enum SdJobState: SwiftProtobuf.Enum { extension SdJobState: CaseIterable { // The compiler won't synthesize support with the UNRECOGNIZED case. public static var allCases: [SdJobState] = [ - .unknown, + .unknownState, .queued, .running, .completed, @@ -109,7 +109,7 @@ public struct SdJob { ///* /// The current state of the job. - public var state: SdJobState = .unknown + public var state: SdJobState = .unknownState ///* /// The percentage of completion for the entire job. @@ -248,7 +248,7 @@ fileprivate let _protobuf_package = "gay.pizza.stable.diffusion" extension SdJobState: SwiftProtobuf._ProtoNameProviding { public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 0: .same(proto: "unknown"), + 0: .same(proto: "unknown_state"), 1: .same(proto: "queued"), 2: .same(proto: "running"), 3: .same(proto: "completed"), @@ -287,7 +287,7 @@ extension SdJob: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase if self.host != 0 { try visitor.visitSingularUInt64Field(value: self.host, fieldNumber: 2) } - if self.state != .unknown { + if self.state != .unknownState { try visitor.visitSingularEnumField(value: self.state, fieldNumber: 3) } if self.overallPercentageComplete != 0 { diff --git a/Sources/StableDiffusionProtos/metadata.grpc.swift b/Sources/StableDiffusionProtos/metadata.grpc.swift new file mode 100644 index 0000000..4e888bf --- /dev/null +++ b/Sources/StableDiffusionProtos/metadata.grpc.swift @@ -0,0 +1,323 @@ +// +// DO NOT EDIT. +// +// Generated by the protocol buffer compiler. +// Source: metadata.proto +// + +// +// Copyright 2018, gRPC Authors All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +import GRPC +import NIO +import NIOConcurrencyHelpers +import SwiftProtobuf + + +/// Usage: instantiate `SdServerMetadataServiceClient`, then call methods of this protocol to make API calls. +public protocol SdServerMetadataServiceClientProtocol: GRPCClient { + var serviceName: String { get } + var interceptors: SdServerMetadataServiceClientInterceptorFactoryProtocol? { get } + + func getServerMetadata( + _ request: SdGetServerMetadataRequest, + callOptions: CallOptions? + ) -> UnaryCall +} + +extension SdServerMetadataServiceClientProtocol { + public var serviceName: String { + return "gay.pizza.stable.diffusion.ServerMetadataService" + } + + /// Unary call to GetServerMetadata + /// + /// - Parameters: + /// - request: Request to send to GetServerMetadata. + /// - callOptions: Call options. + /// - Returns: A `UnaryCall` with futures for the metadata, status and response. + public func getServerMetadata( + _ request: SdGetServerMetadataRequest, + callOptions: CallOptions? = nil + ) -> UnaryCall { + return self.makeUnaryCall( + path: SdServerMetadataServiceClientMetadata.Methods.getServerMetadata.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeGetServerMetadataInterceptors() ?? [] + ) + } +} + +#if compiler(>=5.6) +@available(*, deprecated) +extension SdServerMetadataServiceClient: @unchecked Sendable {} +#endif // compiler(>=5.6) + +@available(*, deprecated, renamed: "SdServerMetadataServiceNIOClient") +public final class SdServerMetadataServiceClient: SdServerMetadataServiceClientProtocol { + private let lock = Lock() + private var _defaultCallOptions: CallOptions + private var _interceptors: SdServerMetadataServiceClientInterceptorFactoryProtocol? + public let channel: GRPCChannel + public var defaultCallOptions: CallOptions { + get { self.lock.withLock { return self._defaultCallOptions } } + set { self.lock.withLockVoid { self._defaultCallOptions = newValue } } + } + public var interceptors: SdServerMetadataServiceClientInterceptorFactoryProtocol? { + get { self.lock.withLock { return self._interceptors } } + set { self.lock.withLockVoid { self._interceptors = newValue } } + } + + /// Creates a client for the gay.pizza.stable.diffusion.ServerMetadataService service. + /// + /// - Parameters: + /// - channel: `GRPCChannel` to the service host. + /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them. + /// - interceptors: A factory providing interceptors for each RPC. + public init( + channel: GRPCChannel, + defaultCallOptions: CallOptions = CallOptions(), + interceptors: SdServerMetadataServiceClientInterceptorFactoryProtocol? = nil + ) { + self.channel = channel + self._defaultCallOptions = defaultCallOptions + self._interceptors = interceptors + } +} + +public struct SdServerMetadataServiceNIOClient: SdServerMetadataServiceClientProtocol { + public var channel: GRPCChannel + public var defaultCallOptions: CallOptions + public var interceptors: SdServerMetadataServiceClientInterceptorFactoryProtocol? + + /// Creates a client for the gay.pizza.stable.diffusion.ServerMetadataService service. + /// + /// - Parameters: + /// - channel: `GRPCChannel` to the service host. + /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them. + /// - interceptors: A factory providing interceptors for each RPC. + public init( + channel: GRPCChannel, + defaultCallOptions: CallOptions = CallOptions(), + interceptors: SdServerMetadataServiceClientInterceptorFactoryProtocol? = nil + ) { + self.channel = channel + self.defaultCallOptions = defaultCallOptions + self.interceptors = interceptors + } +} + +#if compiler(>=5.6) +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +public protocol SdServerMetadataServiceAsyncClientProtocol: GRPCClient { + static var serviceDescriptor: GRPCServiceDescriptor { get } + var interceptors: SdServerMetadataServiceClientInterceptorFactoryProtocol? { get } + + func makeGetServerMetadataCall( + _ request: SdGetServerMetadataRequest, + callOptions: CallOptions? + ) -> GRPCAsyncUnaryCall +} + +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +extension SdServerMetadataServiceAsyncClientProtocol { + public static var serviceDescriptor: GRPCServiceDescriptor { + return SdServerMetadataServiceClientMetadata.serviceDescriptor + } + + public var interceptors: SdServerMetadataServiceClientInterceptorFactoryProtocol? { + return nil + } + + public func makeGetServerMetadataCall( + _ request: SdGetServerMetadataRequest, + callOptions: CallOptions? = nil + ) -> GRPCAsyncUnaryCall { + return self.makeAsyncUnaryCall( + path: SdServerMetadataServiceClientMetadata.Methods.getServerMetadata.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeGetServerMetadataInterceptors() ?? [] + ) + } +} + +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +extension SdServerMetadataServiceAsyncClientProtocol { + public func getServerMetadata( + _ request: SdGetServerMetadataRequest, + callOptions: CallOptions? = nil + ) async throws -> SdGetServerMetadataResponse { + return try await self.performAsyncUnaryCall( + path: SdServerMetadataServiceClientMetadata.Methods.getServerMetadata.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeGetServerMetadataInterceptors() ?? [] + ) + } +} + +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +public struct SdServerMetadataServiceAsyncClient: SdServerMetadataServiceAsyncClientProtocol { + public var channel: GRPCChannel + public var defaultCallOptions: CallOptions + public var interceptors: SdServerMetadataServiceClientInterceptorFactoryProtocol? + + public init( + channel: GRPCChannel, + defaultCallOptions: CallOptions = CallOptions(), + interceptors: SdServerMetadataServiceClientInterceptorFactoryProtocol? = nil + ) { + self.channel = channel + self.defaultCallOptions = defaultCallOptions + self.interceptors = interceptors + } +} + +#endif // compiler(>=5.6) + +public protocol SdServerMetadataServiceClientInterceptorFactoryProtocol: GRPCSendable { + + /// - Returns: Interceptors to use when invoking 'getServerMetadata'. + func makeGetServerMetadataInterceptors() -> [ClientInterceptor] +} + +public enum SdServerMetadataServiceClientMetadata { + public static let serviceDescriptor = GRPCServiceDescriptor( + name: "ServerMetadataService", + fullName: "gay.pizza.stable.diffusion.ServerMetadataService", + methods: [ + SdServerMetadataServiceClientMetadata.Methods.getServerMetadata, + ] + ) + + public enum Methods { + public static let getServerMetadata = GRPCMethodDescriptor( + name: "GetServerMetadata", + path: "/gay.pizza.stable.diffusion.ServerMetadataService/GetServerMetadata", + type: GRPCCallType.unary + ) + } +} + +/// To build a server, implement a class that conforms to this protocol. +public protocol SdServerMetadataServiceProvider: CallHandlerProvider { + var interceptors: SdServerMetadataServiceServerInterceptorFactoryProtocol? { get } + + func getServerMetadata(request: SdGetServerMetadataRequest, context: StatusOnlyCallContext) -> EventLoopFuture +} + +extension SdServerMetadataServiceProvider { + public var serviceName: Substring { + return SdServerMetadataServiceServerMetadata.serviceDescriptor.fullName[...] + } + + /// Determines, calls and returns the appropriate request handler, depending on the request's method. + /// Returns nil for methods not handled by this service. + public func handle( + method name: Substring, + context: CallHandlerContext + ) -> GRPCServerHandlerProtocol? { + switch name { + case "GetServerMetadata": + return UnaryServerHandler( + context: context, + requestDeserializer: ProtobufDeserializer(), + responseSerializer: ProtobufSerializer(), + interceptors: self.interceptors?.makeGetServerMetadataInterceptors() ?? [], + userFunction: self.getServerMetadata(request:context:) + ) + + default: + return nil + } + } +} + +#if compiler(>=5.6) + +/// To implement a server, implement an object which conforms to this protocol. +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +public protocol SdServerMetadataServiceAsyncProvider: CallHandlerProvider { + static var serviceDescriptor: GRPCServiceDescriptor { get } + var interceptors: SdServerMetadataServiceServerInterceptorFactoryProtocol? { get } + + @Sendable func getServerMetadata( + request: SdGetServerMetadataRequest, + context: GRPCAsyncServerCallContext + ) async throws -> SdGetServerMetadataResponse +} + +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +extension SdServerMetadataServiceAsyncProvider { + public static var serviceDescriptor: GRPCServiceDescriptor { + return SdServerMetadataServiceServerMetadata.serviceDescriptor + } + + public var serviceName: Substring { + return SdServerMetadataServiceServerMetadata.serviceDescriptor.fullName[...] + } + + public var interceptors: SdServerMetadataServiceServerInterceptorFactoryProtocol? { + return nil + } + + public func handle( + method name: Substring, + context: CallHandlerContext + ) -> GRPCServerHandlerProtocol? { + switch name { + case "GetServerMetadata": + return GRPCAsyncServerHandler( + context: context, + requestDeserializer: ProtobufDeserializer(), + responseSerializer: ProtobufSerializer(), + interceptors: self.interceptors?.makeGetServerMetadataInterceptors() ?? [], + wrapping: self.getServerMetadata(request:context:) + ) + + default: + return nil + } + } +} + +#endif // compiler(>=5.6) + +public protocol SdServerMetadataServiceServerInterceptorFactoryProtocol { + + /// - Returns: Interceptors to use when handling 'getServerMetadata'. + /// Defaults to calling `self.makeInterceptors()`. + func makeGetServerMetadataInterceptors() -> [ServerInterceptor] +} + +public enum SdServerMetadataServiceServerMetadata { + public static let serviceDescriptor = GRPCServiceDescriptor( + name: "ServerMetadataService", + fullName: "gay.pizza.stable.diffusion.ServerMetadataService", + methods: [ + SdServerMetadataServiceServerMetadata.Methods.getServerMetadata, + ] + ) + + public enum Methods { + public static let getServerMetadata = GRPCMethodDescriptor( + name: "GetServerMetadata", + path: "/gay.pizza.stable.diffusion.ServerMetadataService/GetServerMetadata", + type: GRPCCallType.unary + ) + } +} diff --git a/Sources/StableDiffusionProtos/metadata.pb.swift b/Sources/StableDiffusionProtos/metadata.pb.swift new file mode 100644 index 0000000..c534600 --- /dev/null +++ b/Sources/StableDiffusionProtos/metadata.pb.swift @@ -0,0 +1,217 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: metadata.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +///* +/// Server metadata for the Stable Diffusion RPC service. + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +public enum SdServerRole: SwiftProtobuf.Enum { + public typealias RawValue = Int + case unknownRole // = 0 + case node // = 1 + case coordinator // = 2 + case UNRECOGNIZED(Int) + + public init() { + self = .unknownRole + } + + public init?(rawValue: Int) { + switch rawValue { + case 0: self = .unknownRole + case 1: self = .node + case 2: self = .coordinator + default: self = .UNRECOGNIZED(rawValue) + } + } + + public var rawValue: Int { + switch self { + case .unknownRole: return 0 + case .node: return 1 + case .coordinator: return 2 + case .UNRECOGNIZED(let i): return i + } + } + +} + +#if swift(>=4.2) + +extension SdServerRole: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + public static var allCases: [SdServerRole] = [ + .unknownRole, + .node, + .coordinator, + ] +} + +#endif // swift(>=4.2) + +public struct SdServerMetadata { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var role: SdServerRole = .unknownRole + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct SdGetServerMetadataRequest { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct SdGetServerMetadataResponse { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var metadata: SdServerMetadata { + get {return _metadata ?? SdServerMetadata()} + set {_metadata = newValue} + } + /// Returns true if `metadata` has been explicitly set. + public var hasMetadata: Bool {return self._metadata != nil} + /// Clears the value of `metadata`. Subsequent reads from it will return its default value. + public mutating func clearMetadata() {self._metadata = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _metadata: SdServerMetadata? = nil +} + +#if swift(>=5.5) && canImport(_Concurrency) +extension SdServerRole: @unchecked Sendable {} +extension SdServerMetadata: @unchecked Sendable {} +extension SdGetServerMetadataRequest: @unchecked Sendable {} +extension SdGetServerMetadataResponse: @unchecked Sendable {} +#endif // swift(>=5.5) && canImport(_Concurrency) + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "gay.pizza.stable.diffusion" + +extension SdServerRole: SwiftProtobuf._ProtoNameProviding { + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 0: .same(proto: "unknown_role"), + 1: .same(proto: "node"), + 2: .same(proto: "coordinator"), + ] +} + +extension SdServerMetadata: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ServerMetadata" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "role"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularEnumField(value: &self.role) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.role != .unknownRole { + try visitor.visitSingularEnumField(value: self.role, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: SdServerMetadata, rhs: SdServerMetadata) -> Bool { + if lhs.role != rhs.role {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension SdGetServerMetadataRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".GetServerMetadataRequest" + public static let _protobuf_nameMap = SwiftProtobuf._NameMap() + + public mutating func decodeMessage(decoder: inout D) throws { + while let _ = try decoder.nextFieldNumber() { + } + } + + public func traverse(visitor: inout V) throws { + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: SdGetServerMetadataRequest, rhs: SdGetServerMetadataRequest) -> Bool { + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension SdGetServerMetadataResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".GetServerMetadataResponse" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "metadata"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._metadata) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._metadata { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: SdGetServerMetadataResponse, rhs: SdGetServerMetadataResponse) -> Bool { + if lhs._metadata != rhs._metadata {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/StableDiffusionProtos/model.grpc.swift b/Sources/StableDiffusionProtos/model.grpc.swift new file mode 100644 index 0000000..d752fa1 --- /dev/null +++ b/Sources/StableDiffusionProtos/model.grpc.swift @@ -0,0 +1,342 @@ +// +// DO NOT EDIT. +// +// Generated by the protocol buffer compiler. +// Source: model.proto +// + +// +// Copyright 2018, gRPC Authors All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +import GRPC +import NIO +import NIOConcurrencyHelpers +import SwiftProtobuf + + +///* +/// The model service, for management and loading of models. +/// +/// Usage: instantiate `SdModelServiceClient`, then call methods of this protocol to make API calls. +public protocol SdModelServiceClientProtocol: GRPCClient { + var serviceName: String { get } + var interceptors: SdModelServiceClientInterceptorFactoryProtocol? { get } + + func listModels( + _ request: SdListModelsRequest, + callOptions: CallOptions? + ) -> UnaryCall +} + +extension SdModelServiceClientProtocol { + public var serviceName: String { + return "gay.pizza.stable.diffusion.ModelService" + } + + ///* + /// Lists the available models on the host. + /// This will return both models that are currently loaded, and models that are not yet loaded. + /// + /// - Parameters: + /// - request: Request to send to ListModels. + /// - callOptions: Call options. + /// - Returns: A `UnaryCall` with futures for the metadata, status and response. + public func listModels( + _ request: SdListModelsRequest, + callOptions: CallOptions? = nil + ) -> UnaryCall { + return self.makeUnaryCall( + path: SdModelServiceClientMetadata.Methods.listModels.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeListModelsInterceptors() ?? [] + ) + } +} + +#if compiler(>=5.6) +@available(*, deprecated) +extension SdModelServiceClient: @unchecked Sendable {} +#endif // compiler(>=5.6) + +@available(*, deprecated, renamed: "SdModelServiceNIOClient") +public final class SdModelServiceClient: SdModelServiceClientProtocol { + private let lock = Lock() + private var _defaultCallOptions: CallOptions + private var _interceptors: SdModelServiceClientInterceptorFactoryProtocol? + public let channel: GRPCChannel + public var defaultCallOptions: CallOptions { + get { self.lock.withLock { return self._defaultCallOptions } } + set { self.lock.withLockVoid { self._defaultCallOptions = newValue } } + } + public var interceptors: SdModelServiceClientInterceptorFactoryProtocol? { + get { self.lock.withLock { return self._interceptors } } + set { self.lock.withLockVoid { self._interceptors = newValue } } + } + + /// Creates a client for the gay.pizza.stable.diffusion.ModelService service. + /// + /// - Parameters: + /// - channel: `GRPCChannel` to the service host. + /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them. + /// - interceptors: A factory providing interceptors for each RPC. + public init( + channel: GRPCChannel, + defaultCallOptions: CallOptions = CallOptions(), + interceptors: SdModelServiceClientInterceptorFactoryProtocol? = nil + ) { + self.channel = channel + self._defaultCallOptions = defaultCallOptions + self._interceptors = interceptors + } +} + +public struct SdModelServiceNIOClient: SdModelServiceClientProtocol { + public var channel: GRPCChannel + public var defaultCallOptions: CallOptions + public var interceptors: SdModelServiceClientInterceptorFactoryProtocol? + + /// Creates a client for the gay.pizza.stable.diffusion.ModelService service. + /// + /// - Parameters: + /// - channel: `GRPCChannel` to the service host. + /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them. + /// - interceptors: A factory providing interceptors for each RPC. + public init( + channel: GRPCChannel, + defaultCallOptions: CallOptions = CallOptions(), + interceptors: SdModelServiceClientInterceptorFactoryProtocol? = nil + ) { + self.channel = channel + self.defaultCallOptions = defaultCallOptions + self.interceptors = interceptors + } +} + +#if compiler(>=5.6) +///* +/// The model service, for management and loading of models. +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +public protocol SdModelServiceAsyncClientProtocol: GRPCClient { + static var serviceDescriptor: GRPCServiceDescriptor { get } + var interceptors: SdModelServiceClientInterceptorFactoryProtocol? { get } + + func makeListModelsCall( + _ request: SdListModelsRequest, + callOptions: CallOptions? + ) -> GRPCAsyncUnaryCall +} + +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +extension SdModelServiceAsyncClientProtocol { + public static var serviceDescriptor: GRPCServiceDescriptor { + return SdModelServiceClientMetadata.serviceDescriptor + } + + public var interceptors: SdModelServiceClientInterceptorFactoryProtocol? { + return nil + } + + public func makeListModelsCall( + _ request: SdListModelsRequest, + callOptions: CallOptions? = nil + ) -> GRPCAsyncUnaryCall { + return self.makeAsyncUnaryCall( + path: SdModelServiceClientMetadata.Methods.listModels.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeListModelsInterceptors() ?? [] + ) + } +} + +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +extension SdModelServiceAsyncClientProtocol { + public func listModels( + _ request: SdListModelsRequest, + callOptions: CallOptions? = nil + ) async throws -> SdListModelsResponse { + return try await self.performAsyncUnaryCall( + path: SdModelServiceClientMetadata.Methods.listModels.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeListModelsInterceptors() ?? [] + ) + } +} + +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +public struct SdModelServiceAsyncClient: SdModelServiceAsyncClientProtocol { + public var channel: GRPCChannel + public var defaultCallOptions: CallOptions + public var interceptors: SdModelServiceClientInterceptorFactoryProtocol? + + public init( + channel: GRPCChannel, + defaultCallOptions: CallOptions = CallOptions(), + interceptors: SdModelServiceClientInterceptorFactoryProtocol? = nil + ) { + self.channel = channel + self.defaultCallOptions = defaultCallOptions + self.interceptors = interceptors + } +} + +#endif // compiler(>=5.6) + +public protocol SdModelServiceClientInterceptorFactoryProtocol: GRPCSendable { + + /// - Returns: Interceptors to use when invoking 'listModels'. + func makeListModelsInterceptors() -> [ClientInterceptor] +} + +public enum SdModelServiceClientMetadata { + public static let serviceDescriptor = GRPCServiceDescriptor( + name: "ModelService", + fullName: "gay.pizza.stable.diffusion.ModelService", + methods: [ + SdModelServiceClientMetadata.Methods.listModels, + ] + ) + + public enum Methods { + public static let listModels = GRPCMethodDescriptor( + name: "ListModels", + path: "/gay.pizza.stable.diffusion.ModelService/ListModels", + type: GRPCCallType.unary + ) + } +} + +///* +/// The model service, for management and loading of models. +/// +/// To build a server, implement a class that conforms to this protocol. +public protocol SdModelServiceProvider: CallHandlerProvider { + var interceptors: SdModelServiceServerInterceptorFactoryProtocol? { get } + + ///* + /// Lists the available models on the host. + /// This will return both models that are currently loaded, and models that are not yet loaded. + func listModels(request: SdListModelsRequest, context: StatusOnlyCallContext) -> EventLoopFuture +} + +extension SdModelServiceProvider { + public var serviceName: Substring { + return SdModelServiceServerMetadata.serviceDescriptor.fullName[...] + } + + /// Determines, calls and returns the appropriate request handler, depending on the request's method. + /// Returns nil for methods not handled by this service. + public func handle( + method name: Substring, + context: CallHandlerContext + ) -> GRPCServerHandlerProtocol? { + switch name { + case "ListModels": + return UnaryServerHandler( + context: context, + requestDeserializer: ProtobufDeserializer(), + responseSerializer: ProtobufSerializer(), + interceptors: self.interceptors?.makeListModelsInterceptors() ?? [], + userFunction: self.listModels(request:context:) + ) + + default: + return nil + } + } +} + +#if compiler(>=5.6) + +///* +/// The model service, for management and loading of models. +/// +/// To implement a server, implement an object which conforms to this protocol. +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +public protocol SdModelServiceAsyncProvider: CallHandlerProvider { + static var serviceDescriptor: GRPCServiceDescriptor { get } + var interceptors: SdModelServiceServerInterceptorFactoryProtocol? { get } + + ///* + /// Lists the available models on the host. + /// This will return both models that are currently loaded, and models that are not yet loaded. + @Sendable func listModels( + request: SdListModelsRequest, + context: GRPCAsyncServerCallContext + ) async throws -> SdListModelsResponse +} + +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +extension SdModelServiceAsyncProvider { + public static var serviceDescriptor: GRPCServiceDescriptor { + return SdModelServiceServerMetadata.serviceDescriptor + } + + public var serviceName: Substring { + return SdModelServiceServerMetadata.serviceDescriptor.fullName[...] + } + + public var interceptors: SdModelServiceServerInterceptorFactoryProtocol? { + return nil + } + + public func handle( + method name: Substring, + context: CallHandlerContext + ) -> GRPCServerHandlerProtocol? { + switch name { + case "ListModels": + return GRPCAsyncServerHandler( + context: context, + requestDeserializer: ProtobufDeserializer(), + responseSerializer: ProtobufSerializer(), + interceptors: self.interceptors?.makeListModelsInterceptors() ?? [], + wrapping: self.listModels(request:context:) + ) + + default: + return nil + } + } +} + +#endif // compiler(>=5.6) + +public protocol SdModelServiceServerInterceptorFactoryProtocol { + + /// - Returns: Interceptors to use when handling 'listModels'. + /// Defaults to calling `self.makeInterceptors()`. + func makeListModelsInterceptors() -> [ServerInterceptor] +} + +public enum SdModelServiceServerMetadata { + public static let serviceDescriptor = GRPCServiceDescriptor( + name: "ModelService", + fullName: "gay.pizza.stable.diffusion.ModelService", + methods: [ + SdModelServiceServerMetadata.Methods.listModels, + ] + ) + + public enum Methods { + public static let listModels = GRPCMethodDescriptor( + name: "ListModels", + path: "/gay.pizza.stable.diffusion.ModelService/ListModels", + type: GRPCCallType.unary + ) + } +} diff --git a/Sources/StableDiffusionProtos/model.pb.swift b/Sources/StableDiffusionProtos/model.pb.swift new file mode 100644 index 0000000..7255862 --- /dev/null +++ b/Sources/StableDiffusionProtos/model.pb.swift @@ -0,0 +1,112 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: model.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +///* +/// Host management for the Stable Diffusion RPC service. + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +///* +/// Represents a request to list the models available on the host. +public struct SdListModelsRequest { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +///* +/// Represents a response to listing the models available on the host. +public struct SdListModelsResponse { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + ///* + /// The available models on the Stable Diffusion server. + public var availableModels: [SdModelInfo] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +#if swift(>=5.5) && canImport(_Concurrency) +extension SdListModelsRequest: @unchecked Sendable {} +extension SdListModelsResponse: @unchecked Sendable {} +#endif // swift(>=5.5) && canImport(_Concurrency) + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "gay.pizza.stable.diffusion" + +extension SdListModelsRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ListModelsRequest" + public static let _protobuf_nameMap = SwiftProtobuf._NameMap() + + public mutating func decodeMessage(decoder: inout D) throws { + while let _ = try decoder.nextFieldNumber() { + } + } + + public func traverse(visitor: inout V) throws { + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: SdListModelsRequest, rhs: SdListModelsRequest) -> Bool { + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension SdListModelsResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ListModelsResponse" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "available_models"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.availableModels) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.availableModels.isEmpty { + try visitor.visitRepeatedMessageField(value: self.availableModels, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: SdListModelsResponse, rhs: SdListModelsResponse) -> Bool { + if lhs.availableModels != rhs.availableModels {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/StableDiffusionProtos/shared.pb.swift b/Sources/StableDiffusionProtos/shared.pb.swift index 62d0c12..746f194 100644 --- a/Sources/StableDiffusionProtos/shared.pb.swift +++ b/Sources/StableDiffusionProtos/shared.pb.swift @@ -224,6 +224,26 @@ extension SdImageFormat: CaseIterable { #endif // swift(>=4.2) +///* +/// Represents a 128-bit UUID value. +public struct SdUniqueIdentifier { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + ///* + /// The upper bits of the UUID. + public var upperBits: UInt64 = 0 + + ///* + /// The lower bits of the UUID. + public var lowerBits: UInt64 = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + ///* /// Represents information about an available model. /// The primary key of a model is it's 'name' field. @@ -233,9 +253,7 @@ public struct SdModelInfo { // methods supported on all messages. ///* - /// The name of the available model. Note that within the context of a single RPC server, - /// the name of a model is a unique identifier. This may not be true when utilizing a cluster or - /// load balanced server, so keep that in mind. + /// The name of the available model. Note that a model name is considered a unique identifier. public var name: String = String() ///* @@ -243,15 +261,6 @@ public struct SdModelInfo { /// load the model and make predictions. public var attention: SdModelAttention = .original - ///* - /// Whether the model is currently loaded onto an available compute unit. - public var isLoaded: Bool = false - - ///* - /// The compute unit that the model is currently loaded into, if it is loaded to one at all. - /// When is_loaded is false, the value of this field should be null. - public var loadedComputeUnits: SdComputeUnits = .cpu - ///* /// The compute units that this model supports using. public var supportedComputeUnits: [SdComputeUnits] = [] @@ -288,6 +297,7 @@ extension SdModelAttention: @unchecked Sendable {} extension SdScheduler: @unchecked Sendable {} extension SdComputeUnits: @unchecked Sendable {} extension SdImageFormat: @unchecked Sendable {} +extension SdUniqueIdentifier: @unchecked Sendable {} extension SdModelInfo: @unchecked Sendable {} extension SdImage: @unchecked Sendable {} #endif // swift(>=5.5) && canImport(_Concurrency) @@ -325,13 +335,49 @@ extension SdImageFormat: SwiftProtobuf._ProtoNameProviding { ] } +extension SdUniqueIdentifier: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".UniqueIdentifier" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "upper_bits"), + 2: .standard(proto: "lower_bits"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularUInt64Field(value: &self.upperBits) }() + case 2: try { try decoder.decodeSingularUInt64Field(value: &self.lowerBits) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.upperBits != 0 { + try visitor.visitSingularUInt64Field(value: self.upperBits, fieldNumber: 1) + } + if self.lowerBits != 0 { + try visitor.visitSingularUInt64Field(value: self.lowerBits, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: SdUniqueIdentifier, rhs: SdUniqueIdentifier) -> Bool { + if lhs.upperBits != rhs.upperBits {return false} + if lhs.lowerBits != rhs.lowerBits {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + extension SdModelInfo: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { public static let protoMessageName: String = _protobuf_package + ".ModelInfo" public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ 1: .same(proto: "name"), 2: .same(proto: "attention"), - 3: .standard(proto: "is_loaded"), - 4: .standard(proto: "loaded_compute_units"), 5: .standard(proto: "supported_compute_units"), ] @@ -343,8 +389,6 @@ extension SdModelInfo: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementati switch fieldNumber { case 1: try { try decoder.decodeSingularStringField(value: &self.name) }() case 2: try { try decoder.decodeSingularEnumField(value: &self.attention) }() - case 3: try { try decoder.decodeSingularBoolField(value: &self.isLoaded) }() - case 4: try { try decoder.decodeSingularEnumField(value: &self.loadedComputeUnits) }() case 5: try { try decoder.decodeRepeatedEnumField(value: &self.supportedComputeUnits) }() default: break } @@ -358,12 +402,6 @@ extension SdModelInfo: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementati if self.attention != .original { try visitor.visitSingularEnumField(value: self.attention, fieldNumber: 2) } - if self.isLoaded != false { - try visitor.visitSingularBoolField(value: self.isLoaded, fieldNumber: 3) - } - if self.loadedComputeUnits != .cpu { - try visitor.visitSingularEnumField(value: self.loadedComputeUnits, fieldNumber: 4) - } if !self.supportedComputeUnits.isEmpty { try visitor.visitPackedEnumField(value: self.supportedComputeUnits, fieldNumber: 5) } @@ -373,8 +411,6 @@ extension SdModelInfo: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementati public static func ==(lhs: SdModelInfo, rhs: SdModelInfo) -> Bool { if lhs.name != rhs.name {return false} if lhs.attention != rhs.attention {return false} - if lhs.isLoaded != rhs.isLoaded {return false} - if lhs.loadedComputeUnits != rhs.loadedComputeUnits {return false} if lhs.supportedComputeUnits != rhs.supportedComputeUnits {return false} if lhs.unknownFields != rhs.unknownFields {return false} return true diff --git a/Sources/StableDiffusionProtos/tokenizer.pb.swift b/Sources/StableDiffusionProtos/tokenizer.pb.swift index 47ef182..df4566e 100644 --- a/Sources/StableDiffusionProtos/tokenizer.pb.swift +++ b/Sources/StableDiffusionProtos/tokenizer.pb.swift @@ -8,7 +8,7 @@ // https://github.com/apple/swift-protobuf/ ///* -/// Stable Diffusion RPC service for Apple Platforms. +/// Tokenization for the Stable Diffusion RPC service. import Foundation import SwiftProtobuf