Skip to content

Commit

Permalink
Create Rust-based openai api proxy server in node hub (#678)
Browse files Browse the repository at this point in the history
This is a Rust-based version of #676
based on
https://github.com/LlamaEdge/LlamaEdge/tree/main/llama-api-server . It
includes `serde` structs to fully deserialize chat completion requests.

The server replies to requests asynchronously, which makes it possible
to serve multiple clients at the same time. Note that replies are mapped
to requests purely based on their order right now. So the first reply is
assigned to the first request and so on. If the order of replies is
different (e.g. because some completions take longer), some form of ID
needs to be added to the code to enable a proper `request<->reply`
mapping.

Like #676, this PR only implements basic chat completion requests. You
can try it through these steps:

```bash
cd examples/openai-server
dora build dataflow-rust.yml
dora start dataflow-rust.yml

# In a separate terminal
python openai_api_client.py
```

I didn't implement the `/v1/models` endpoint, so the _"Testing API
endpoints..."_ part of `openai_api_client.py` is expected to fail with
_"Error listing models: 404"_.
  • Loading branch information
phil-opp authored Oct 7, 2024
2 parents 0299f4b + b7ae767 commit c8a890a
Show file tree
Hide file tree
Showing 7 changed files with 1,609 additions and 36 deletions.
109 changes: 73 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ members = [
"node-hub/dora-record",
"node-hub/dora-rerun",
"node-hub/terminal-print",
"node-hub/openai-proxy-server",
"libraries/extensions/ros2-bridge",
"libraries/extensions/ros2-bridge/msg-gen",
"libraries/extensions/ros2-bridge/python",
Expand Down
16 changes: 16 additions & 0 deletions examples/openai-server/dataflow-rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
nodes:
- id: dora-openai-server
build: cargo build -p dora-openai-proxy-server --release
path: ../../target/release/dora-openai-proxy-server
outputs:
- chat_completion_request
inputs:
completion_reply: dora-echo/echo

- id: dora-echo
build: pip install -e ../../node-hub/dora-echo
path: dora-echo
inputs:
echo: dora-openai-server/chat_completion_request
outputs:
- echo
27 changes: 27 additions & 0 deletions node-hub/openai-proxy-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "dora-openai-proxy-server"
version.workspace = true
edition = "2021"
documentation.workspace = true
description.workspace = true
license.workspace = true
repository.workspace = true

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

[dependencies]
tokio = { version = "1.36.0", features = ["full"] }
dora-node-api = { workspace = true, features = ["tracing"] }
eyre = "0.6.8"
chrono = "0.4.31"
tracing = "0.1.27"
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0.68"
url = "2.2.2"
indexmap = { version = "2.6.0", features = ["serde"] }
hyper = { version = "0.14", features = ["full"] }
thiserror = "1.0.37"
uuid = { version = "1.10", features = ["v4"] }
mime_guess = "2.0.4"
futures = "0.3.31"
tokio-stream = "0.1.11"
Loading

0 comments on commit c8a890a

Please sign in to comment.