Skip to content

Commit fb2a446

Browse files
committed
Add audio, moderations, and tokenize support
Register previously missing OpenAI-compatible routes so they are proxied to backends instead of being rejected with 404: - /v1/audio/transcriptions and /v1/audio/translations (multipart/form-data) - /v1/audio/speech (JSON) - /v1/moderations - /tokenize and /detokenize (vLLM extension) Add BackendModeAudio and a dedicated handleAudioInference handler that parses the model field from multipart form data rather than a JSON body. vLLM (Linux and Metal) passes audio requests through natively; llama.cpp returns a descriptive error directing users to use chat completions with an input_audio content part instead. Signed-off-by: Eric Curtin <eric.curtin@docker.com>
1 parent 1304519 commit fb2a446

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3025
-700
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ jobs:
5353
go mod tidy
5454
git diff --exit-code go.mod go.sum
5555
56+
- name: Install Rust toolchain
57+
uses: dtolnay/rust-toolchain@stable
58+
59+
- name: Cache Rust build artifacts
60+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
61+
with:
62+
path: |
63+
~/.cargo/registry
64+
~/.cargo/git
65+
target/
66+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
67+
restore-keys: ${{ runner.os }}-cargo-
68+
69+
- name: Build Rust router library
70+
run: make build-router-lib
71+
5672
- name: Run tests with race detection
5773
run: go test -race ./...
5874

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ llamacpp/install
1515
vllm-metal-macos-arm64-*.tar.gz
1616

1717
.DS_Store
18+
19+
# Cargo workspace build output
20+
/target/
21+
/Cargo.lock

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[workspace]
2+
members = [
3+
"dmr-common",
4+
"model-cli",
5+
"router",
6+
]
7+
resolver = "2"
8+
9+
[profile.release]
10+
lto = true

Dockerfile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,31 @@ FROM docker.io/library/golang:${GO_VERSION}-bookworm AS builder
1515

1616
ARG VERSION
1717

18-
# Install git for go mod download if needed
19-
RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*
18+
# Install git and the Rust toolchain (needed to build libdmr_router.a via CGo).
19+
RUN apt-get update && apt-get install -y --no-install-recommends git curl && rm -rf /var/lib/apt/lists/*
20+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable
21+
ENV PATH="/root/.cargo/bin:${PATH}"
2022

2123
WORKDIR /app
2224

2325
# Copy go mod/sum first for better caching
2426
COPY --link go.mod go.sum ./
2527

26-
# Download dependencies (with cache mounts)
28+
# Download Go dependencies (with cache mounts)
2729
RUN --mount=type=cache,target=/go/pkg/mod \
2830
--mount=type=cache,target=/root/.cache/go-build \
2931
go mod download
3032

3133
# Copy the rest of the source code
3234
COPY --link . .
3335

34-
# Build the Go binary (static build)
35-
RUN --mount=type=cache,target=/go/pkg/mod \
36+
# Build the Rust dmr-router static library, then the Go binary.
37+
# Both steps share a single RUN so the Rust output is available to the linker.
38+
RUN --mount=type=cache,target=/root/.cargo/registry \
39+
--mount=type=cache,target=/root/.cargo/git \
3640
--mount=type=cache,target=/root/.cache/go-build \
41+
--mount=type=cache,target=/go/pkg/mod \
42+
cargo build --release --manifest-path router/Cargo.toml && \
3743
CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w -X main.Version=${VERSION}" -o model-runner .
3844

3945
# Build the Go binary for SGLang (without vLLM)

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,24 @@ DOCKER_BUILD_ARGS := \
2323
-t $(DOCKER_IMAGE)
2424

2525
# Phony targets grouped by category
26-
.PHONY: build build-cli build-dmr build-llamacpp install-cli run clean test integration-tests e2e
26+
.PHONY: build build-cli build-dmr build-llamacpp build-router-lib install-cli run clean test integration-tests e2e
2727
.PHONY: validate validate-all lint help
2828
.PHONY: docker-build docker-build-multiplatform docker-run docker-run-impl
2929
.PHONY: docker-build-vllm docker-run-vllm docker-build-sglang docker-run-sglang
3030
.PHONY: test-docker-ce-installation
3131
.PHONY: vllm-metal-build vllm-metal-install vllm-metal-dev vllm-metal-clean
3232
.PHONY: diffusers-build diffusers-install diffusers-dev diffusers-clean
33+
3334
# Default target: build server, CLI plugin, and dmr convenience wrapper
3435
.DEFAULT_GOAL := build
3536

3637
build: build-server build-cli build-dmr
3738

38-
build-server:
39+
# Build the Rust dmr-router static library.
40+
build-router-lib:
41+
cargo build --release --manifest-path router/Cargo.toml
42+
43+
build-server: build-router-lib
3944
CGO_ENABLED=1 go build -ldflags="-s -w -X main.Version=$(shell git describe --tags --always --dirty --match 'v*')" -o $(APP_NAME) .
4045

4146
build-cli:
@@ -68,6 +73,7 @@ clean:
6873
rm -f $(APP_NAME)
6974
rm -f dmr
7075
rm -f model-runner.sock
76+
cargo clean --manifest-path router/Cargo.toml
7177

7278
# Run tests
7379
test:

cmd/cli/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ build-gateway:
2020
@echo "Building gateway static library (Rust)..."
2121
@mkdir -p $(GATEWAY_LIB_DIR)
2222
cargo build --release --manifest-path $(GATEWAY_RUST_DIR)/Cargo.toml
23-
@cp $(GATEWAY_RUST_DIR)/target/release/libmodel_cli_gateway.a $(GATEWAY_LIB_DIR)/libgateway.a
23+
@cp ../../target/release/libmodel_cli_gateway.a $(GATEWAY_LIB_DIR)/libgateway.a
2424
@echo "Gateway library staged at $(GATEWAY_LIB_DIR)/libgateway.a"
2525

2626
build: build-gateway

dmr-common/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "dmr-common"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "Shared utilities for Docker Model Runner Rust crates"
6+
7+
[dependencies]
8+
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

dmr-common/src/lib.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//! Shared utilities for Docker Model Runner Rust crates.
2+
3+
/// Return the current time as seconds since the Unix epoch.
4+
///
5+
/// Used when constructing OpenAI-format response objects that require a
6+
/// `created` timestamp. Returns 0 on the (extremely unlikely) event that
7+
/// the system clock predates 1970.
8+
pub fn unix_now_secs() -> u64 {
9+
std::time::SystemTime::now()
10+
.duration_since(std::time::UNIX_EPOCH)
11+
.unwrap_or_default()
12+
.as_secs()
13+
}
14+
15+
/// Initialise the global tracing subscriber.
16+
///
17+
/// Reads `RUST_LOG` from the environment; falls back to `fallback` if unset
18+
/// or invalid. Silently ignores subsequent calls (e.g. when called from both
19+
/// a library entry point and a binary entry point in the same process).
20+
///
21+
/// # Arguments
22+
/// * `fallback` – default filter string, e.g. `"info"` or `"myapp=debug"`.
23+
pub fn init_tracing(fallback: &str) {
24+
let _ = tracing_subscriber::fmt()
25+
.with_env_filter(
26+
tracing_subscriber::EnvFilter::try_from_default_env()
27+
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new(fallback)),
28+
)
29+
.try_init();
30+
}

0 commit comments

Comments
 (0)