Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP feat:Init commit for rust backend #1180

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ release/
backend-assets/
prepare
/ggml-metal.metal
target/
Cargo.lock
model.bin
8 changes: 8 additions & 0 deletions backend/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[workspace]
resolver = "2"
members = [
"bunker",
"backend",
"codegen",
"models",
]
57 changes: 57 additions & 0 deletions backend/rust/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 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

.PHONY: burn
burn:
@echo "Burning..."
@cargo run --bin server --package backend-burn



############################################################################################################
# gRPC testing commands


.PHONY: list
list:
@echo "Burning..."
@grpcurl -plaintext -import-path ../../../pkg/grpc/proto -proto backend.proto list backend.Backend

.PHONY: health
health:
@echo "Burning..."
@grpcurl -plaintext -import-path ../../pkg/grpc/proto -proto backend.proto -d '{}' '[::1]:50051' backend.Backend/Health


.PHONY: status
status:
@echo "Burning..."
@grpcurl -plaintext -import-path ../../pkg/grpc/proto -proto backend.proto -d '{}' '[::1]:50051' backend.Backend/Status
54 changes: 54 additions & 0 deletions backend/rust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## Here is a backend written in Rust for the LocalAI project

Here are some rules for the Rust backend:
* Same proto file with the LocalAI's other backends, we should keep the same interface of the backend.
* `async` should be as the default way to write code.
* Streaming response should be supported.
* Only server side gRPC services are supported for current backend.
* The backend should also have metrics for monitoring.


### The information of the environment

* cargo 1.73.0 (9c4383fb5 2023-08-26)
* rustup 1.26.0 (5af9b9484 2023-04-05)
* rustc 1.73.0 (cc66ad468 2023-10-03)

## Build the development environment

#### Protocol Buffers compiler

Ubuntu or Debian

```
sudo apt update && sudo apt upgrade -y
sudo apt install -y protobuf-compiler libprotobuf-dev
```

macOS
```
brew install protobuf
```

### Cargo fmt all the code

```
cargo fmt --all --check
```

### Check the gRPC backend status

It will return base64 encoded string of the `OK`.


```bash
make burn

make test
```

```
{
"message": "T0s="
}
```
25 changes: 25 additions & 0 deletions backend/rust/backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "backend"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[[bin]]
name = "server"
path = "src/main.rs"

[dependencies]

# import bunker here
bunker = { path = "../bunker" }
models = { path = "../models" }

tokio = "1.33.0"
async-trait = "0.1.74"
tonic = "0.10.2"
tokio-stream = "0.1.14"

tracing = "0.1"
tracing-subscriber = "0.3"
nix = { version="0.27.1", features=["resource"]}
19 changes: 19 additions & 0 deletions backend/rust/backend/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY: check
check:
@echo "Checking..."
@cargo check

.PHONY: fmt
fmt:
@echo "Formatting code..."
@cargo fmt

.PHONY: build
build:
@echo "Building..."
@cargo build

.PHONY: doc
doc:
@echo "Documenting..."
@cargo doc --no-deps --document-private-items --open
Loading