feat: add SSE streaming support (OpenAI-compatible)

- Token-by-token streaming via Server-Sent Events
- tokio::sync::mpsc channel + ReceiverStream for clean async
- OpenAI SSE format: role chunk → content chunks → finish chunk
- Non-streaming still works with the same code path
- Uses spawn_blocking pattern for CPU-bound inference
This commit is contained in:
Asep Haryana
2026-07-25 11:33:59 +07:00
parent 6edf6cee5d
commit e1f5195407
3 changed files with 294 additions and 92 deletions
+2
View File
@@ -10,6 +10,7 @@ llama-cpp-2 = "0.1"
# HTTP server
axum = { version = "0.8", features = ["json"] }
tokio = { version = "1", features = ["full"] }
tokio-stream = "0.1"
tower-http = { version = "0.6", features = ["cors", "trace"] }
# Serialization
@@ -22,3 +23,4 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
anyhow = "1"
uuid = { version = "1", features = ["v4"] }
chrono = { version = "0.4", features = ["serde"] }
futures = "0.3"