mirror of
https://github.com/GayPizzaSpecifications/stable-diffusion-rpc.git
synced 2025-08-05 14:31:32 +00:00
Add support for BPE tokenization.
This commit is contained in:
19
Sources/StableDiffusionServer/TokenizerService.swift
Normal file
19
Sources/StableDiffusionServer/TokenizerService.swift
Normal file
@ -0,0 +1,19 @@
|
||||
import Foundation
|
||||
import GRPC
|
||||
import StableDiffusionCore
|
||||
import StableDiffusionProtos
|
||||
|
||||
class TokenizerServiceProvider: SdTokenizerServiceAsyncProvider {
|
||||
private let modelManager: ModelManager
|
||||
|
||||
init(modelManager: ModelManager) {
|
||||
self.modelManager = modelManager
|
||||
}
|
||||
|
||||
func tokenize(request: SdTokenizeRequest, context _: GRPCAsyncServerCallContext) async throws -> SdTokenizeResponse {
|
||||
guard let state = await modelManager.getModelState(name: request.modelName) else {
|
||||
throw SdCoreError.modelNotFound
|
||||
}
|
||||
return try await state.tokenize(request)
|
||||
}
|
||||
}
|
@ -34,7 +34,8 @@ struct ServerCommand: ParsableCommand {
|
||||
_ = Server.insecure(group: group)
|
||||
.withServiceProviders([
|
||||
ModelServiceProvider(modelManager: modelManager),
|
||||
ImageGenerationServiceProvider(modelManager: modelManager)
|
||||
ImageGenerationServiceProvider(modelManager: modelManager),
|
||||
TokenizerServiceProvider(modelManager: modelManager)
|
||||
])
|
||||
.bind(host: bindHost, port: bindPort)
|
||||
|
||||
|
Reference in New Issue
Block a user