Split out worker related things to a separate service definition.

This commit is contained in:
2023-05-08 22:12:24 -07:00
parent ace2c07aa1
commit 2e5a37ea4b
28 changed files with 1271 additions and 359 deletions

View File

@ -1,25 +1,11 @@
#include "host.grpc.pb.h" #include "host.grpc.pb.h"
#include "model.grpc.pb.h"
#include "image_generation.grpc.pb.h" #include "image_generation.grpc.pb.h"
#include <grpc++/grpc++.h> #include <grpc++/grpc++.h>
using namespace gay::pizza::stable::diffusion; 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() { int main() {
auto channel = grpc::CreateChannel("localhost:4546", grpc::InsecureChannelCredentials()); auto channel = grpc::CreateChannel("localhost:4546", grpc::InsecureChannelCredentials());
auto modelService = ModelService::NewStub(channel); auto modelService = ModelService::NewStub(channel);
@ -34,9 +20,5 @@ int main() {
for (const auto &item: models) { for (const auto &item: models) {
std::cout << "Model Name: " << item.name() << std::endl; 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; return 0;
} }

View File

@ -49,8 +49,7 @@ fun main(args: Array<String>) {
} }
println("available models:") println("available models:")
for (model in modelListResponse.availableModelsList) { for (model in modelListResponse.availableModelsList) {
val maybeLoadedComputeUnits = if (model.isLoaded) " loaded_compute_units=${model.loadedComputeUnits.name}" else "" println(" model ${model.name} attention=${model.attention}")
println(" model ${model.name} attention=${model.attention} loaded=${model.isLoaded}${maybeLoadedComputeUnits}")
} }
val model = if (chosenModelName == null) { val model = if (chosenModelName == null) {
@ -59,15 +58,11 @@ fun main(args: Array<String>) {
modelListResponse.availableModelsList.first { it.name == chosenModelName } modelListResponse.availableModelsList.first { it.name == chosenModelName }
} }
if (!model.isLoaded) { println("loading model ${model.name}...")
println("loading model ${model.name}...") client.hostModelServiceBlocking.loadModel(LoadModelRequest.newBuilder().apply {
client.modelServiceBlocking.loadModel(LoadModelRequest.newBuilder().apply { modelName = model.name
modelName = model.name computeUnits = model.supportedComputeUnitsList.first()
computeUnits = model.supportedComputeUnitsList.first() }.build())
}.build())
} else {
println("using model ${model.name}...")
}
println("tokenizing prompts...") println("tokenizing prompts...")

View File

@ -20,6 +20,22 @@ class StableDiffusionRpcClient(val channel: Channel) {
ModelServiceGrpcKt.ModelServiceCoroutineStub(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 { val imageGenerationService: ImageGenerationServiceGrpc.ImageGenerationServiceStub by lazy {
ImageGenerationServiceGrpc.newStub(channel) ImageGenerationServiceGrpc.newStub(channel)
} }

View File

@ -11,21 +11,6 @@ import "shared.proto";
option swift_prefix = "Sd"; option swift_prefix = "Sd";
option java_multiple_files = true; 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. * 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. * The model service, for management and loading of models.
*/ */
service ModelService { service HostModelService {
/**
* 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);
/** /**
* Loads a model onto a compute unit. * Loads a model onto a compute unit.
*/ */

View File

@ -17,7 +17,7 @@ enum JobState {
/** /**
* The job is in an unknown state. * The job is in an unknown state.
*/ */
unknown = 0; unknown_state = 0;
/** /**
* The job is queued. It has not started the work. * The job is queued. It has not started the work.

30
Common/metadata.proto Normal file
View File

@ -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);
}

38
Common/model.proto Normal file
View File

@ -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);
}

View File

@ -10,6 +10,21 @@ package gay.pizza.stable.diffusion;
option swift_prefix = "Sd"; option swift_prefix = "Sd";
option java_multiple_files = true; 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 * 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. * can determine what compute units are able to support a particular model.
@ -73,9 +88,7 @@ enum ComputeUnits {
*/ */
message ModelInfo { message ModelInfo {
/** /**
* The name of the available model. Note that within the context of a single RPC server, * The name of the available model. Note that a model name is considered a unique identifier.
* 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.
*/ */
string name = 1; string name = 1;
@ -85,17 +98,6 @@ message ModelInfo {
*/ */
ModelAttention attention = 2; 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. * The compute units that this model supports using.
*/ */

View File

@ -5,7 +5,7 @@ let package = Package(
name: "stable-diffusion-rpc", name: "stable-diffusion-rpc",
platforms: [.macOS("13.1"), .iOS("16.2")], platforms: [.macOS("13.1"), .iOS("16.2")],
products: [ products: [
.executable(name: "stable-diffusion-rpc", targets: ["StableDiffusionServer"]), .executable(name: "stable-diffusion-rpc", targets: ["StableDiffusionNode"]),
.library(name: "StableDiffusionProtos", targets: ["StableDiffusionProtos"]), .library(name: "StableDiffusionProtos", targets: ["StableDiffusionProtos"]),
.executable(name: "stable-diffusion-ctl", targets: ["StableDiffusionControl"]) .executable(name: "stable-diffusion-ctl", targets: ["StableDiffusionControl"])
], ],
@ -24,7 +24,7 @@ let package = Package(
.product(name: "StableDiffusion", package: "ml-stable-diffusion"), .product(name: "StableDiffusion", package: "ml-stable-diffusion"),
.target(name: "StableDiffusionProtos") .target(name: "StableDiffusionProtos")
]), ]),
.executableTarget(name: "StableDiffusionServer", dependencies: [ .executableTarget(name: "StableDiffusionNode", dependencies: [
.product(name: "StableDiffusion", package: "ml-stable-diffusion"), .product(name: "StableDiffusion", package: "ml-stable-diffusion"),
.product(name: "SwiftProtobuf", package: "swift-protobuf"), .product(name: "SwiftProtobuf", package: "swift-protobuf"),
.product(name: "GRPC", package: "grpc-swift"), .product(name: "GRPC", package: "grpc-swift"),

View File

@ -9,7 +9,11 @@ struct StableDiffusionClient {
let channel: GRPCChannel let channel: GRPCChannel
let modelService: SdModelServiceAsyncClient let modelService: SdModelServiceAsyncClient
let hostModelService: SdHostModelServiceAsyncClient
let imageGenerationService: SdImageGenerationServiceAsyncClient let imageGenerationService: SdImageGenerationServiceAsyncClient
let tokenizerService: SdTokenizerServiceAsyncClient
let jobService: SdJobServiceAsyncClient
let serverMetadataService: SdServerMetadataServiceAsyncClient
init(connectionTarget: ConnectionTarget, transportSecurity: GRPCChannelPool.Configuration.TransportSecurity) throws { init(connectionTarget: ConnectionTarget, transportSecurity: GRPCChannelPool.Configuration.TransportSecurity) throws {
group = PlatformSupport.makeEventLoopGroup(loopCount: 1) group = PlatformSupport.makeEventLoopGroup(loopCount: 1)
@ -21,7 +25,11 @@ struct StableDiffusionClient {
) )
modelService = SdModelServiceAsyncClient(channel: channel) modelService = SdModelServiceAsyncClient(channel: channel)
hostModelService = SdHostModelServiceAsyncClient(channel: channel)
imageGenerationService = SdImageGenerationServiceAsyncClient(channel: channel) imageGenerationService = SdImageGenerationServiceAsyncClient(channel: channel)
tokenizerService = SdTokenizerServiceAsyncClient(channel: channel)
jobService = SdJobServiceAsyncClient(channel: channel)
serverMetadataService = SdServerMetadataServiceAsyncClient(channel: channel)
} }
func close() async throws { func close() async throws {

View File

@ -11,7 +11,7 @@ Task { @MainActor in
let modelListResponse = try await client.modelService.listModels(.init()) let modelListResponse = try await client.modelService.listModels(.init())
print("Loading random model...") print("Loading random model...")
let modelInfo = modelListResponse.availableModels.randomElement()! 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 request.modelName = modelInfo.name
}) })
print("Loaded random model.") print("Loaded random model.")

View File

@ -32,15 +32,6 @@ public actor ModelManager {
var results: [SdModelInfo] = [] var results: [SdModelInfo] = []
for simpleInfo in modelInfos.values { for simpleInfo in modelInfos.values {
var info = try SdModelInfo(jsonString: simpleInfo.jsonString()) 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 { if info.attention == .splitEinSum {
info.supportedComputeUnits = [ info.supportedComputeUnits = [

View File

@ -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()
}
}

View File

@ -16,10 +16,4 @@ class ModelServiceProvider: SdModelServiceAsyncProvider {
response.availableModels.append(contentsOf: models) response.availableModels.append(contentsOf: models)
return response 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()
}
} }

View File

@ -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
}
}
}
}

View File

@ -35,13 +35,15 @@ struct ServerCommand: ParsableCommand {
_ = Server.insecure(group: group) _ = Server.insecure(group: group)
.withServiceProviders([ .withServiceProviders([
ModelServiceProvider(modelManager: modelManager), ModelServiceProvider(modelManager: modelManager),
HostModelServiceProvider(modelManager: modelManager),
ImageGenerationServiceProvider(jobManager: jobManager, modelManager: modelManager), ImageGenerationServiceProvider(jobManager: jobManager, modelManager: modelManager),
TokenizerServiceProvider(modelManager: modelManager), TokenizerServiceProvider(modelManager: modelManager),
JobServiceProvider(jobManager: jobManager) JobServiceProvider(jobManager: jobManager),
ServerMetadataServiceProvider()
]) ])
.bind(host: bindHost, port: bindPort) .bind(host: bindHost, port: bindPort)
print("Stable Diffusion RPC running on \(bindHost):\(bindPort)") print("Stable Diffusion RPC node running on \(bindHost):\(bindPort)")
dispatchMain() dispatchMain()
} }

View File

@ -29,15 +29,10 @@ import SwiftProtobuf
///* ///*
/// The model service, for management and loading of models. /// The model service, for management and loading of models.
/// ///
/// Usage: instantiate `SdModelServiceClient`, then call methods of this protocol to make API calls. /// Usage: instantiate `SdHostModelServiceClient`, then call methods of this protocol to make API calls.
public protocol SdModelServiceClientProtocol: GRPCClient { public protocol SdHostModelServiceClientProtocol: GRPCClient {
var serviceName: String { get } var serviceName: String { get }
var interceptors: SdModelServiceClientInterceptorFactoryProtocol? { get } var interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? { get }
func listModels(
_ request: SdListModelsRequest,
callOptions: CallOptions?
) -> UnaryCall<SdListModelsRequest, SdListModelsResponse>
func loadModel( func loadModel(
_ request: SdLoadModelRequest, _ request: SdLoadModelRequest,
@ -45,29 +40,9 @@ public protocol SdModelServiceClientProtocol: GRPCClient {
) -> UnaryCall<SdLoadModelRequest, SdLoadModelResponse> ) -> UnaryCall<SdLoadModelRequest, SdLoadModelResponse>
} }
extension SdModelServiceClientProtocol { extension SdHostModelServiceClientProtocol {
public var serviceName: String { public var serviceName: String {
return "gay.pizza.stable.diffusion.ModelService" return "gay.pizza.stable.diffusion.HostModelService"
}
///*
/// 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<SdListModelsRequest, SdListModelsResponse> {
return self.makeUnaryCall(
path: SdModelServiceClientMetadata.Methods.listModels.path,
request: request,
callOptions: callOptions ?? self.defaultCallOptions,
interceptors: self.interceptors?.makeListModelsInterceptors() ?? []
)
} }
///* ///*
@ -82,7 +57,7 @@ extension SdModelServiceClientProtocol {
callOptions: CallOptions? = nil callOptions: CallOptions? = nil
) -> UnaryCall<SdLoadModelRequest, SdLoadModelResponse> { ) -> UnaryCall<SdLoadModelRequest, SdLoadModelResponse> {
return self.makeUnaryCall( return self.makeUnaryCall(
path: SdModelServiceClientMetadata.Methods.loadModel.path, path: SdHostModelServiceClientMetadata.Methods.loadModel.path,
request: request, request: request,
callOptions: callOptions ?? self.defaultCallOptions, callOptions: callOptions ?? self.defaultCallOptions,
interceptors: self.interceptors?.makeLoadModelInterceptors() ?? [] interceptors: self.interceptors?.makeLoadModelInterceptors() ?? []
@ -92,25 +67,25 @@ extension SdModelServiceClientProtocol {
#if compiler(>=5.6) #if compiler(>=5.6)
@available(*, deprecated) @available(*, deprecated)
extension SdModelServiceClient: @unchecked Sendable {} extension SdHostModelServiceClient: @unchecked Sendable {}
#endif // compiler(>=5.6) #endif // compiler(>=5.6)
@available(*, deprecated, renamed: "SdModelServiceNIOClient") @available(*, deprecated, renamed: "SdHostModelServiceNIOClient")
public final class SdModelServiceClient: SdModelServiceClientProtocol { public final class SdHostModelServiceClient: SdHostModelServiceClientProtocol {
private let lock = Lock() private let lock = Lock()
private var _defaultCallOptions: CallOptions private var _defaultCallOptions: CallOptions
private var _interceptors: SdModelServiceClientInterceptorFactoryProtocol? private var _interceptors: SdHostModelServiceClientInterceptorFactoryProtocol?
public let channel: GRPCChannel public let channel: GRPCChannel
public var defaultCallOptions: CallOptions { public var defaultCallOptions: CallOptions {
get { self.lock.withLock { return self._defaultCallOptions } } get { self.lock.withLock { return self._defaultCallOptions } }
set { self.lock.withLockVoid { self._defaultCallOptions = newValue } } set { self.lock.withLockVoid { self._defaultCallOptions = newValue } }
} }
public var interceptors: SdModelServiceClientInterceptorFactoryProtocol? { public var interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? {
get { self.lock.withLock { return self._interceptors } } get { self.lock.withLock { return self._interceptors } }
set { self.lock.withLockVoid { self._interceptors = newValue } } 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: /// - Parameters:
/// - channel: `GRPCChannel` to the service host. /// - channel: `GRPCChannel` to the service host.
@ -119,7 +94,7 @@ public final class SdModelServiceClient: SdModelServiceClientProtocol {
public init( public init(
channel: GRPCChannel, channel: GRPCChannel,
defaultCallOptions: CallOptions = CallOptions(), defaultCallOptions: CallOptions = CallOptions(),
interceptors: SdModelServiceClientInterceptorFactoryProtocol? = nil interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? = nil
) { ) {
self.channel = channel self.channel = channel
self._defaultCallOptions = defaultCallOptions 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 channel: GRPCChannel
public var defaultCallOptions: CallOptions 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: /// - Parameters:
/// - channel: `GRPCChannel` to the service host. /// - channel: `GRPCChannel` to the service host.
@ -141,7 +116,7 @@ public struct SdModelServiceNIOClient: SdModelServiceClientProtocol {
public init( public init(
channel: GRPCChannel, channel: GRPCChannel,
defaultCallOptions: CallOptions = CallOptions(), defaultCallOptions: CallOptions = CallOptions(),
interceptors: SdModelServiceClientInterceptorFactoryProtocol? = nil interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? = nil
) { ) {
self.channel = channel self.channel = channel
self.defaultCallOptions = defaultCallOptions self.defaultCallOptions = defaultCallOptions
@ -153,14 +128,9 @@ public struct SdModelServiceNIOClient: SdModelServiceClientProtocol {
///* ///*
/// The model service, for management and loading of models. /// The model service, for management and loading of models.
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public protocol SdModelServiceAsyncClientProtocol: GRPCClient { public protocol SdHostModelServiceAsyncClientProtocol: GRPCClient {
static var serviceDescriptor: GRPCServiceDescriptor { get } static var serviceDescriptor: GRPCServiceDescriptor { get }
var interceptors: SdModelServiceClientInterceptorFactoryProtocol? { get } var interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? { get }
func makeListModelsCall(
_ request: SdListModelsRequest,
callOptions: CallOptions?
) -> GRPCAsyncUnaryCall<SdListModelsRequest, SdListModelsResponse>
func makeLoadModelCall( func makeLoadModelCall(
_ request: SdLoadModelRequest, _ request: SdLoadModelRequest,
@ -169,33 +139,21 @@ public protocol SdModelServiceAsyncClientProtocol: GRPCClient {
} }
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension SdModelServiceAsyncClientProtocol { extension SdHostModelServiceAsyncClientProtocol {
public static var serviceDescriptor: GRPCServiceDescriptor { public static var serviceDescriptor: GRPCServiceDescriptor {
return SdModelServiceClientMetadata.serviceDescriptor return SdHostModelServiceClientMetadata.serviceDescriptor
} }
public var interceptors: SdModelServiceClientInterceptorFactoryProtocol? { public var interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? {
return nil return nil
} }
public func makeListModelsCall(
_ request: SdListModelsRequest,
callOptions: CallOptions? = nil
) -> GRPCAsyncUnaryCall<SdListModelsRequest, SdListModelsResponse> {
return self.makeAsyncUnaryCall(
path: SdModelServiceClientMetadata.Methods.listModels.path,
request: request,
callOptions: callOptions ?? self.defaultCallOptions,
interceptors: self.interceptors?.makeListModelsInterceptors() ?? []
)
}
public func makeLoadModelCall( public func makeLoadModelCall(
_ request: SdLoadModelRequest, _ request: SdLoadModelRequest,
callOptions: CallOptions? = nil callOptions: CallOptions? = nil
) -> GRPCAsyncUnaryCall<SdLoadModelRequest, SdLoadModelResponse> { ) -> GRPCAsyncUnaryCall<SdLoadModelRequest, SdLoadModelResponse> {
return self.makeAsyncUnaryCall( return self.makeAsyncUnaryCall(
path: SdModelServiceClientMetadata.Methods.loadModel.path, path: SdHostModelServiceClientMetadata.Methods.loadModel.path,
request: request, request: request,
callOptions: callOptions ?? self.defaultCallOptions, callOptions: callOptions ?? self.defaultCallOptions,
interceptors: self.interceptors?.makeLoadModelInterceptors() ?? [] interceptors: self.interceptors?.makeLoadModelInterceptors() ?? []
@ -204,25 +162,13 @@ extension SdModelServiceAsyncClientProtocol {
} }
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension SdModelServiceAsyncClientProtocol { extension SdHostModelServiceAsyncClientProtocol {
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() ?? []
)
}
public func loadModel( public func loadModel(
_ request: SdLoadModelRequest, _ request: SdLoadModelRequest,
callOptions: CallOptions? = nil callOptions: CallOptions? = nil
) async throws -> SdLoadModelResponse { ) async throws -> SdLoadModelResponse {
return try await self.performAsyncUnaryCall( return try await self.performAsyncUnaryCall(
path: SdModelServiceClientMetadata.Methods.loadModel.path, path: SdHostModelServiceClientMetadata.Methods.loadModel.path,
request: request, request: request,
callOptions: callOptions ?? self.defaultCallOptions, callOptions: callOptions ?? self.defaultCallOptions,
interceptors: self.interceptors?.makeLoadModelInterceptors() ?? [] interceptors: self.interceptors?.makeLoadModelInterceptors() ?? []
@ -231,15 +177,15 @@ extension SdModelServiceAsyncClientProtocol {
} }
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public struct SdModelServiceAsyncClient: SdModelServiceAsyncClientProtocol { public struct SdHostModelServiceAsyncClient: SdHostModelServiceAsyncClientProtocol {
public var channel: GRPCChannel public var channel: GRPCChannel
public var defaultCallOptions: CallOptions public var defaultCallOptions: CallOptions
public var interceptors: SdModelServiceClientInterceptorFactoryProtocol? public var interceptors: SdHostModelServiceClientInterceptorFactoryProtocol?
public init( public init(
channel: GRPCChannel, channel: GRPCChannel,
defaultCallOptions: CallOptions = CallOptions(), defaultCallOptions: CallOptions = CallOptions(),
interceptors: SdModelServiceClientInterceptorFactoryProtocol? = nil interceptors: SdHostModelServiceClientInterceptorFactoryProtocol? = nil
) { ) {
self.channel = channel self.channel = channel
self.defaultCallOptions = defaultCallOptions self.defaultCallOptions = defaultCallOptions
@ -249,35 +195,25 @@ public struct SdModelServiceAsyncClient: SdModelServiceAsyncClientProtocol {
#endif // compiler(>=5.6) #endif // compiler(>=5.6)
public protocol SdModelServiceClientInterceptorFactoryProtocol: GRPCSendable { public protocol SdHostModelServiceClientInterceptorFactoryProtocol: GRPCSendable {
/// - Returns: Interceptors to use when invoking 'listModels'.
func makeListModelsInterceptors() -> [ClientInterceptor<SdListModelsRequest, SdListModelsResponse>]
/// - Returns: Interceptors to use when invoking 'loadModel'. /// - Returns: Interceptors to use when invoking 'loadModel'.
func makeLoadModelInterceptors() -> [ClientInterceptor<SdLoadModelRequest, SdLoadModelResponse>] func makeLoadModelInterceptors() -> [ClientInterceptor<SdLoadModelRequest, SdLoadModelResponse>]
} }
public enum SdModelServiceClientMetadata { public enum SdHostModelServiceClientMetadata {
public static let serviceDescriptor = GRPCServiceDescriptor( public static let serviceDescriptor = GRPCServiceDescriptor(
name: "ModelService", name: "HostModelService",
fullName: "gay.pizza.stable.diffusion.ModelService", fullName: "gay.pizza.stable.diffusion.HostModelService",
methods: [ methods: [
SdModelServiceClientMetadata.Methods.listModels, SdHostModelServiceClientMetadata.Methods.loadModel,
SdModelServiceClientMetadata.Methods.loadModel,
] ]
) )
public enum Methods { 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( public static let loadModel = GRPCMethodDescriptor(
name: "LoadModel", name: "LoadModel",
path: "/gay.pizza.stable.diffusion.ModelService/LoadModel", path: "/gay.pizza.stable.diffusion.HostModelService/LoadModel",
type: GRPCCallType.unary type: GRPCCallType.unary
) )
} }
@ -287,22 +223,17 @@ public enum SdModelServiceClientMetadata {
/// The model service, for management and loading of models. /// The model service, for management and loading of models.
/// ///
/// To build a server, implement a class that conforms to this protocol. /// To build a server, implement a class that conforms to this protocol.
public protocol SdModelServiceProvider: CallHandlerProvider { public protocol SdHostModelServiceProvider: CallHandlerProvider {
var interceptors: SdModelServiceServerInterceptorFactoryProtocol? { get } var interceptors: SdHostModelServiceServerInterceptorFactoryProtocol? { 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<SdListModelsResponse>
///* ///*
/// Loads a model onto a compute unit. /// Loads a model onto a compute unit.
func loadModel(request: SdLoadModelRequest, context: StatusOnlyCallContext) -> EventLoopFuture<SdLoadModelResponse> func loadModel(request: SdLoadModelRequest, context: StatusOnlyCallContext) -> EventLoopFuture<SdLoadModelResponse>
} }
extension SdModelServiceProvider { extension SdHostModelServiceProvider {
public var serviceName: Substring { 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. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
@ -312,15 +243,6 @@ extension SdModelServiceProvider {
context: CallHandlerContext context: CallHandlerContext
) -> GRPCServerHandlerProtocol? { ) -> GRPCServerHandlerProtocol? {
switch name { switch name {
case "ListModels":
return UnaryServerHandler(
context: context,
requestDeserializer: ProtobufDeserializer<SdListModelsRequest>(),
responseSerializer: ProtobufSerializer<SdListModelsResponse>(),
interceptors: self.interceptors?.makeListModelsInterceptors() ?? [],
userFunction: self.listModels(request:context:)
)
case "LoadModel": case "LoadModel":
return UnaryServerHandler( return UnaryServerHandler(
context: context, context: context,
@ -343,17 +265,9 @@ extension SdModelServiceProvider {
/// ///
/// To implement a server, implement an object which conforms to this protocol. /// To implement a server, implement an object which conforms to this protocol.
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public protocol SdModelServiceAsyncProvider: CallHandlerProvider { public protocol SdHostModelServiceAsyncProvider: CallHandlerProvider {
static var serviceDescriptor: GRPCServiceDescriptor { get } static var serviceDescriptor: GRPCServiceDescriptor { get }
var interceptors: SdModelServiceServerInterceptorFactoryProtocol? { get } var interceptors: SdHostModelServiceServerInterceptorFactoryProtocol? { 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
///* ///*
/// Loads a model onto a compute unit. /// 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, *) @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension SdModelServiceAsyncProvider { extension SdHostModelServiceAsyncProvider {
public static var serviceDescriptor: GRPCServiceDescriptor { public static var serviceDescriptor: GRPCServiceDescriptor {
return SdModelServiceServerMetadata.serviceDescriptor return SdHostModelServiceServerMetadata.serviceDescriptor
} }
public var serviceName: Substring { public var serviceName: Substring {
return SdModelServiceServerMetadata.serviceDescriptor.fullName[...] return SdHostModelServiceServerMetadata.serviceDescriptor.fullName[...]
} }
public var interceptors: SdModelServiceServerInterceptorFactoryProtocol? { public var interceptors: SdHostModelServiceServerInterceptorFactoryProtocol? {
return nil return nil
} }
@ -382,15 +296,6 @@ extension SdModelServiceAsyncProvider {
context: CallHandlerContext context: CallHandlerContext
) -> GRPCServerHandlerProtocol? { ) -> GRPCServerHandlerProtocol? {
switch name { switch name {
case "ListModels":
return GRPCAsyncServerHandler(
context: context,
requestDeserializer: ProtobufDeserializer<SdListModelsRequest>(),
responseSerializer: ProtobufSerializer<SdListModelsResponse>(),
interceptors: self.interceptors?.makeListModelsInterceptors() ?? [],
wrapping: self.listModels(request:context:)
)
case "LoadModel": case "LoadModel":
return GRPCAsyncServerHandler( return GRPCAsyncServerHandler(
context: context, context: context,
@ -408,37 +313,26 @@ extension SdModelServiceAsyncProvider {
#endif // compiler(>=5.6) #endif // compiler(>=5.6)
public protocol SdModelServiceServerInterceptorFactoryProtocol { public protocol SdHostModelServiceServerInterceptorFactoryProtocol {
/// - Returns: Interceptors to use when handling 'listModels'.
/// Defaults to calling `self.makeInterceptors()`.
func makeListModelsInterceptors() -> [ServerInterceptor<SdListModelsRequest, SdListModelsResponse>]
/// - Returns: Interceptors to use when handling 'loadModel'. /// - Returns: Interceptors to use when handling 'loadModel'.
/// Defaults to calling `self.makeInterceptors()`. /// Defaults to calling `self.makeInterceptors()`.
func makeLoadModelInterceptors() -> [ServerInterceptor<SdLoadModelRequest, SdLoadModelResponse>] func makeLoadModelInterceptors() -> [ServerInterceptor<SdLoadModelRequest, SdLoadModelResponse>]
} }
public enum SdModelServiceServerMetadata { public enum SdHostModelServiceServerMetadata {
public static let serviceDescriptor = GRPCServiceDescriptor( public static let serviceDescriptor = GRPCServiceDescriptor(
name: "ModelService", name: "HostModelService",
fullName: "gay.pizza.stable.diffusion.ModelService", fullName: "gay.pizza.stable.diffusion.HostModelService",
methods: [ methods: [
SdModelServiceServerMetadata.Methods.listModels, SdHostModelServiceServerMetadata.Methods.loadModel,
SdModelServiceServerMetadata.Methods.loadModel,
] ]
) )
public enum Methods { 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( public static let loadModel = GRPCMethodDescriptor(
name: "LoadModel", name: "LoadModel",
path: "/gay.pizza.stable.diffusion.ModelService/LoadModel", path: "/gay.pizza.stable.diffusion.HostModelService/LoadModel",
type: GRPCCallType.unary type: GRPCCallType.unary
) )
} }

View File

@ -8,7 +8,7 @@
// https://github.com/apple/swift-protobuf/ // 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 Foundation
import SwiftProtobuf import SwiftProtobuf
@ -23,34 +23,6 @@ fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAP
typealias Version = _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() {}
}
///* ///*
/// Represents a request to load a model into a specified compute unit. /// Represents a request to load a model into a specified compute unit.
public struct SdLoadModelRequest { public struct SdLoadModelRequest {
@ -84,8 +56,6 @@ public struct SdLoadModelResponse {
} }
#if swift(>=5.5) && canImport(_Concurrency) #if swift(>=5.5) && canImport(_Concurrency)
extension SdListModelsRequest: @unchecked Sendable {}
extension SdListModelsResponse: @unchecked Sendable {}
extension SdLoadModelRequest: @unchecked Sendable {} extension SdLoadModelRequest: @unchecked Sendable {}
extension SdLoadModelResponse: @unchecked Sendable {} extension SdLoadModelResponse: @unchecked Sendable {}
#endif // swift(>=5.5) && canImport(_Concurrency) #endif // swift(>=5.5) && canImport(_Concurrency)
@ -94,57 +64,6 @@ extension SdLoadModelResponse: @unchecked Sendable {}
fileprivate let _protobuf_package = "gay.pizza.stable.diffusion" 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<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
while let _ = try decoder.nextFieldNumber() {
}
}
public func traverse<V: SwiftProtobuf.Visitor>(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<D: SwiftProtobuf.Decoder>(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<V: SwiftProtobuf.Visitor>(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 { extension SdLoadModelRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
public static let protoMessageName: String = _protobuf_package + ".LoadModelRequest" public static let protoMessageName: String = _protobuf_package + ".LoadModelRequest"
public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [

View File

@ -8,7 +8,7 @@
// https://github.com/apple/swift-protobuf/ // https://github.com/apple/swift-protobuf/
///* ///*
/// Stable Diffusion RPC service for Apple Platforms. /// Job management for the Stable Diffusion RPC service.
import Foundation import Foundation
import SwiftProtobuf import SwiftProtobuf
@ -30,7 +30,7 @@ public enum SdJobState: SwiftProtobuf.Enum {
///* ///*
/// The job is in an unknown state. /// The job is in an unknown state.
case unknown // = 0 case unknownState // = 0
///* ///*
/// The job is queued. It has not started the work. /// The job is queued. It has not started the work.
@ -50,12 +50,12 @@ public enum SdJobState: SwiftProtobuf.Enum {
case UNRECOGNIZED(Int) case UNRECOGNIZED(Int)
public init() { public init() {
self = .unknown self = .unknownState
} }
public init?(rawValue: Int) { public init?(rawValue: Int) {
switch rawValue { switch rawValue {
case 0: self = .unknown case 0: self = .unknownState
case 1: self = .queued case 1: self = .queued
case 2: self = .running case 2: self = .running
case 3: self = .completed case 3: self = .completed
@ -66,7 +66,7 @@ public enum SdJobState: SwiftProtobuf.Enum {
public var rawValue: Int { public var rawValue: Int {
switch self { switch self {
case .unknown: return 0 case .unknownState: return 0
case .queued: return 1 case .queued: return 1
case .running: return 2 case .running: return 2
case .completed: return 3 case .completed: return 3
@ -82,7 +82,7 @@ public enum SdJobState: SwiftProtobuf.Enum {
extension SdJobState: CaseIterable { extension SdJobState: CaseIterable {
// The compiler won't synthesize support with the UNRECOGNIZED case. // The compiler won't synthesize support with the UNRECOGNIZED case.
public static var allCases: [SdJobState] = [ public static var allCases: [SdJobState] = [
.unknown, .unknownState,
.queued, .queued,
.running, .running,
.completed, .completed,
@ -109,7 +109,7 @@ public struct SdJob {
///* ///*
/// The current state of the job. /// The current state of the job.
public var state: SdJobState = .unknown public var state: SdJobState = .unknownState
///* ///*
/// The percentage of completion for the entire job. /// The percentage of completion for the entire job.
@ -248,7 +248,7 @@ fileprivate let _protobuf_package = "gay.pizza.stable.diffusion"
extension SdJobState: SwiftProtobuf._ProtoNameProviding { extension SdJobState: SwiftProtobuf._ProtoNameProviding {
public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
0: .same(proto: "unknown"), 0: .same(proto: "unknown_state"),
1: .same(proto: "queued"), 1: .same(proto: "queued"),
2: .same(proto: "running"), 2: .same(proto: "running"),
3: .same(proto: "completed"), 3: .same(proto: "completed"),
@ -287,7 +287,7 @@ extension SdJob: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase
if self.host != 0 { if self.host != 0 {
try visitor.visitSingularUInt64Field(value: self.host, fieldNumber: 2) try visitor.visitSingularUInt64Field(value: self.host, fieldNumber: 2)
} }
if self.state != .unknown { if self.state != .unknownState {
try visitor.visitSingularEnumField(value: self.state, fieldNumber: 3) try visitor.visitSingularEnumField(value: self.state, fieldNumber: 3)
} }
if self.overallPercentageComplete != 0 { if self.overallPercentageComplete != 0 {

View File

@ -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<SdGetServerMetadataRequest, SdGetServerMetadataResponse>
}
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<SdGetServerMetadataRequest, SdGetServerMetadataResponse> {
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<SdGetServerMetadataRequest, SdGetServerMetadataResponse>
}
@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<SdGetServerMetadataRequest, SdGetServerMetadataResponse> {
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<SdGetServerMetadataRequest, SdGetServerMetadataResponse>]
}
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<SdGetServerMetadataResponse>
}
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<SdGetServerMetadataRequest>(),
responseSerializer: ProtobufSerializer<SdGetServerMetadataResponse>(),
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<SdGetServerMetadataRequest>(),
responseSerializer: ProtobufSerializer<SdGetServerMetadataResponse>(),
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<SdGetServerMetadataRequest, SdGetServerMetadataResponse>]
}
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
)
}
}

View File

@ -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<D: SwiftProtobuf.Decoder>(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<V: SwiftProtobuf.Visitor>(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<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
while let _ = try decoder.nextFieldNumber() {
}
}
public func traverse<V: SwiftProtobuf.Visitor>(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<D: SwiftProtobuf.Decoder>(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<V: SwiftProtobuf.Visitor>(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
}
}

View File

@ -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<SdListModelsRequest, SdListModelsResponse>
}
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<SdListModelsRequest, SdListModelsResponse> {
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<SdListModelsRequest, SdListModelsResponse>
}
@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<SdListModelsRequest, SdListModelsResponse> {
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<SdListModelsRequest, SdListModelsResponse>]
}
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<SdListModelsResponse>
}
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<SdListModelsRequest>(),
responseSerializer: ProtobufSerializer<SdListModelsResponse>(),
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<SdListModelsRequest>(),
responseSerializer: ProtobufSerializer<SdListModelsResponse>(),
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<SdListModelsRequest, SdListModelsResponse>]
}
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
)
}
}

View File

@ -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<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
while let _ = try decoder.nextFieldNumber() {
}
}
public func traverse<V: SwiftProtobuf.Visitor>(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<D: SwiftProtobuf.Decoder>(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<V: SwiftProtobuf.Visitor>(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
}
}

View File

@ -224,6 +224,26 @@ extension SdImageFormat: CaseIterable {
#endif // swift(>=4.2) #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. /// Represents information about an available model.
/// The primary key of a model is it's 'name' field. /// The primary key of a model is it's 'name' field.
@ -233,9 +253,7 @@ public struct SdModelInfo {
// methods supported on all messages. // methods supported on all messages.
///* ///*
/// The name of the available model. Note that within the context of a single RPC server, /// The name of the available model. Note that a model name is considered a unique identifier.
/// 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.
public var name: String = String() public var name: String = String()
///* ///*
@ -243,15 +261,6 @@ public struct SdModelInfo {
/// load the model and make predictions. /// load the model and make predictions.
public var attention: SdModelAttention = .original 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. /// The compute units that this model supports using.
public var supportedComputeUnits: [SdComputeUnits] = [] public var supportedComputeUnits: [SdComputeUnits] = []
@ -288,6 +297,7 @@ extension SdModelAttention: @unchecked Sendable {}
extension SdScheduler: @unchecked Sendable {} extension SdScheduler: @unchecked Sendable {}
extension SdComputeUnits: @unchecked Sendable {} extension SdComputeUnits: @unchecked Sendable {}
extension SdImageFormat: @unchecked Sendable {} extension SdImageFormat: @unchecked Sendable {}
extension SdUniqueIdentifier: @unchecked Sendable {}
extension SdModelInfo: @unchecked Sendable {} extension SdModelInfo: @unchecked Sendable {}
extension SdImage: @unchecked Sendable {} extension SdImage: @unchecked Sendable {}
#endif // swift(>=5.5) && canImport(_Concurrency) #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<D: SwiftProtobuf.Decoder>(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<V: SwiftProtobuf.Visitor>(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 { extension SdModelInfo: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
public static let protoMessageName: String = _protobuf_package + ".ModelInfo" public static let protoMessageName: String = _protobuf_package + ".ModelInfo"
public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
1: .same(proto: "name"), 1: .same(proto: "name"),
2: .same(proto: "attention"), 2: .same(proto: "attention"),
3: .standard(proto: "is_loaded"),
4: .standard(proto: "loaded_compute_units"),
5: .standard(proto: "supported_compute_units"), 5: .standard(proto: "supported_compute_units"),
] ]
@ -343,8 +389,6 @@ extension SdModelInfo: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementati
switch fieldNumber { switch fieldNumber {
case 1: try { try decoder.decodeSingularStringField(value: &self.name) }() case 1: try { try decoder.decodeSingularStringField(value: &self.name) }()
case 2: try { try decoder.decodeSingularEnumField(value: &self.attention) }() 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) }() case 5: try { try decoder.decodeRepeatedEnumField(value: &self.supportedComputeUnits) }()
default: break default: break
} }
@ -358,12 +402,6 @@ extension SdModelInfo: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementati
if self.attention != .original { if self.attention != .original {
try visitor.visitSingularEnumField(value: self.attention, fieldNumber: 2) 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 { if !self.supportedComputeUnits.isEmpty {
try visitor.visitPackedEnumField(value: self.supportedComputeUnits, fieldNumber: 5) 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 { public static func ==(lhs: SdModelInfo, rhs: SdModelInfo) -> Bool {
if lhs.name != rhs.name {return false} if lhs.name != rhs.name {return false}
if lhs.attention != rhs.attention {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.supportedComputeUnits != rhs.supportedComputeUnits {return false}
if lhs.unknownFields != rhs.unknownFields {return false} if lhs.unknownFields != rhs.unknownFields {return false}
return true return true

View File

@ -8,7 +8,7 @@
// https://github.com/apple/swift-protobuf/ // https://github.com/apple/swift-protobuf/
///* ///*
/// Stable Diffusion RPC service for Apple Platforms. /// Tokenization for the Stable Diffusion RPC service.
import Foundation import Foundation
import SwiftProtobuf import SwiftProtobuf