-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace the generated file to the generated folder
Signed-off-by: Aisuko <[email protected]>
- Loading branch information
Showing
14 changed files
with
155 additions
and
100 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ resolver = "2" | |
members = [ | ||
"bunker", | ||
"burn", | ||
"codegen", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# default are fmt and then check | ||
.DEFAULT_GOAL := all | ||
|
||
.PHONY: all | ||
all: fmt check | ||
|
||
.PHONY: fmt | ||
fmt: | ||
@echo "Formatting code..." | ||
@cargo fmt --all -- --check | ||
|
||
.PHONY: build | ||
build: | ||
@echo "Building..." | ||
@cargo build --release | ||
|
||
.PHONY: test | ||
test: | ||
@echo "Testing..." | ||
@cargo test --all | ||
|
||
.PHONY: check | ||
check: | ||
@echo "Checking..." | ||
@cargo check --all | ||
|
||
.PHONY: clean | ||
clean: | ||
@echo "Cleaning..." | ||
@cargo clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod service; | ||
/// Import the code() backend.rs was generated from backend.proto | ||
pub mod pb { | ||
include!("../generated/backend.rs"); | ||
} | ||
|
||
pub mod pb{ | ||
include!("backend.rs"); | ||
} | ||
pub mod service; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,43 @@ | ||
use crate::pb::{HealthMessage, PredictOptions,Reply,ModelOptions, EmbeddingResult, GenerateImageRequest,TranscriptRequest,TranscriptResult,TtsRequest,TokenizationResponse,StatusResponse}; | ||
//! Contains the service trait for the bunker service. | ||
|
||
use crate::pb::Result as PbResult; | ||
use tonic::{Request, Response, Status}; | ||
use tokio_stream::wrappers::ReceiverStream; | ||
use crate::pb::{ | ||
EmbeddingResult, GenerateImageRequest, HealthMessage, ModelOptions, PredictOptions, Reply, | ||
StatusResponse, TokenizationResponse, TranscriptRequest, TranscriptResult, TtsRequest, | ||
}; | ||
use async_trait::async_trait; | ||
|
||
use tokio_stream::wrappers::ReceiverStream; | ||
use tonic::{Request, Response, Status}; | ||
|
||
#[async_trait] | ||
pub trait BackendService<T = ReceiverStream<Result<Reply, Status>>>{ | ||
async fn health(&self, request: Request<HealthMessage>) -> Result<Response<Reply>,Status>; | ||
async fn predict(&self, request: Request<PredictOptions>) -> Result<Response<Reply>,Status>; | ||
async fn load_model(&self, request: Request<ModelOptions>) -> Result<Response<PbResult>,Status>; | ||
async fn predict_stream(&self, request: Request<PredictOptions>) -> Result<Response<T>,Status>; // https://github.com/rust-lang/rust/issues/29661 | ||
async fn embedding(&self, request: Request<PredictOptions>) -> Result<Response<EmbeddingResult>,Status>; | ||
async fn generate_image(&self, request: Request<GenerateImageRequest>) -> Result<Response<PbResult>,Status>; | ||
async fn audio_transcription(&self, request: Request<TranscriptRequest>) -> Result<Response<TranscriptResult>,Status>; | ||
async fn tts(&self, request: Request<TtsRequest>) -> Result<Response<PbResult>,Status>; | ||
async fn tokenize_string(&self, request: Request<PredictOptions>) -> Result<Response<TokenizationResponse>,Status>; | ||
async fn status(&self, request: Request<HealthMessage>) -> Result<Response<StatusResponse>,Status>; | ||
|
||
} | ||
pub trait BackendService<T = ReceiverStream<Result<Reply, Status>>> { | ||
async fn health(&self, request: Request<HealthMessage>) -> Result<Response<Reply>, Status>; | ||
async fn predict(&self, request: Request<PredictOptions>) -> Result<Response<Reply>, Status>; | ||
async fn load_model( | ||
&self, | ||
request: Request<ModelOptions>, | ||
) -> Result<Response<PbResult>, Status>; | ||
async fn predict_stream(&self, request: Request<PredictOptions>) | ||
-> Result<Response<T>, Status>; // https://github.com/rust-lang/rust/issues/29661 | ||
async fn embedding( | ||
&self, | ||
request: Request<PredictOptions>, | ||
) -> Result<Response<EmbeddingResult>, Status>; | ||
async fn generate_image( | ||
&self, | ||
request: Request<GenerateImageRequest>, | ||
) -> Result<Response<PbResult>, Status>; | ||
async fn audio_transcription( | ||
&self, | ||
request: Request<TranscriptRequest>, | ||
) -> Result<Response<TranscriptResult>, Status>; | ||
async fn tts(&self, request: Request<TtsRequest>) -> Result<Response<PbResult>, Status>; | ||
async fn tokenize_string( | ||
&self, | ||
request: Request<PredictOptions>, | ||
) -> Result<Response<TokenizationResponse>, Status>; | ||
async fn status( | ||
&self, | ||
request: Request<HealthMessage>, | ||
) -> Result<Response<StatusResponse>, Status>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,88 @@ | ||
use tokio_stream::wrappers::ReceiverStream; | ||
use tonic::transport::Server; | ||
use tonic::{async_trait, Request, Response, Status}; | ||
use tracing; | ||
use tracing_subscriber; | ||
use bunker::pb::{EmbeddingResult, GenerateImageRequest, HealthMessage, ModelOptions, PredictOptions, Reply, StatusResponse, TokenizationResponse, TranscriptRequest, TranscriptResult, TtsRequest}; | ||
use bunker::pb::Result as PbResult; | ||
use bunker::pb::{ | ||
EmbeddingResult, GenerateImageRequest, HealthMessage, ModelOptions, PredictOptions, Reply, | ||
StatusResponse, TokenizationResponse, TranscriptRequest, TranscriptResult, TtsRequest, | ||
}; | ||
use bunker::service::BackendService; | ||
use tokio_stream::wrappers::ReceiverStream; | ||
use tonic::{Request, Response, Status}; | ||
|
||
use async_trait::async_trait; | ||
|
||
// implement BackendService trait in bunker | ||
|
||
struct BurnBackend; | ||
|
||
#[async_trait] | ||
impl BackendService<ReceiverStream<Result<Reply, Status>>> for BurnBackend{ | ||
|
||
async fn health(&self, request: Request<HealthMessage>) -> Result<Response<Reply>,Status> { | ||
impl BackendService<ReceiverStream<Result<Reply, Status>>> for BurnBackend { | ||
async fn health(&self, request: Request<HealthMessage>) -> Result<Response<Reply>, Status> { | ||
// return a Result<Response<Reply>,Status> | ||
let reply = Reply { | ||
message: "OK".into(), | ||
}; | ||
let res=Response::new(reply); | ||
let res = Response::new(reply); | ||
Ok(res) | ||
} | ||
|
||
async fn predict(&self, request: Request<PredictOptions>) -> Result<Response<Reply>,Status> { | ||
async fn predict(&self, request: Request<PredictOptions>) -> Result<Response<Reply>, Status> { | ||
todo!() | ||
} | ||
|
||
async fn load_model(&self, request: Request<ModelOptions>) -> Result<Response<PbResult>, Status> { | ||
async fn load_model( | ||
&self, | ||
request: Request<ModelOptions>, | ||
) -> Result<Response<PbResult>, Status> { | ||
todo!() | ||
} | ||
|
||
async fn predict_stream(&self, request: Request<PredictOptions>) -> Result<Response<ReceiverStream<Result<Reply,Status>>>, Status> { | ||
async fn predict_stream( | ||
&self, | ||
request: Request<PredictOptions>, | ||
) -> Result<Response<ReceiverStream<Result<Reply, Status>>>, Status> { | ||
todo!() | ||
} | ||
|
||
async fn embedding(&self, request: Request<PredictOptions>) -> Result<Response<EmbeddingResult>, Status> { | ||
async fn embedding( | ||
&self, | ||
request: Request<PredictOptions>, | ||
) -> Result<Response<EmbeddingResult>, Status> { | ||
todo!() | ||
} | ||
|
||
async fn generate_image(&self, request: Request<GenerateImageRequest>) -> Result<Response<PbResult>, Status> { | ||
async fn generate_image( | ||
&self, | ||
request: Request<GenerateImageRequest>, | ||
) -> Result<Response<PbResult>, Status> { | ||
todo!() | ||
} | ||
|
||
async fn audio_transcription(&self, request: Request<TranscriptRequest>) -> Result<Response<TranscriptResult>, Status> { | ||
async fn audio_transcription( | ||
&self, | ||
request: Request<TranscriptRequest>, | ||
) -> Result<Response<TranscriptResult>, Status> { | ||
todo!() | ||
} | ||
|
||
async fn tts(&self, request: Request<TtsRequest>) -> Result<Response<PbResult>, Status> { | ||
todo!() | ||
} | ||
|
||
async fn tokenize_string(&self, request: Request<PredictOptions>) -> Result<Response<TokenizationResponse>, Status> { | ||
async fn tokenize_string( | ||
&self, | ||
request: Request<PredictOptions>, | ||
) -> Result<Response<TokenizationResponse>, Status> { | ||
todo!() | ||
} | ||
|
||
async fn status(&self, request: Request<HealthMessage>) -> Result<Response<StatusResponse>, Status> { | ||
async fn status( | ||
&self, | ||
request: Request<HealthMessage>, | ||
) -> Result<Response<StatusResponse>, Status> { | ||
todo!() | ||
} | ||
|
||
} | ||
|
||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
|
||
let subscriber = tracing_subscriber::fmt() | ||
.compact() | ||
.with_file(true) | ||
.with_line_number(true) | ||
.with_target(true) | ||
.with_level(true) | ||
.finish(); | ||
|
||
tracing::subscriber::set_global_default(subscriber) | ||
.expect("setting default subscriber failed"); | ||
|
||
let addr = "[::1]:50052".parse().unwrap(); | ||
|
||
let backend = BackendService {}; | ||
|
||
let svc = BurnBackend::new(backend); | ||
|
||
Server::builder().add_service(svc).serve(addr).await?; | ||
|
||
Ok(()) | ||
todo!() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "codegen" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[build-dependencies] | ||
tonic-build = "0.10" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
fn main() { | ||
tonic_build::configure() | ||
.out_dir("../bunker/generated") | ||
.build_server(true) | ||
.build_client(false) | ||
.compile( | ||
&["../../../pkg/grpc/proto/backend.proto"], | ||
&["../../../pkg/grpc/proto"], | ||
) | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|