Files
qorona/README.md
T

184 lines
6.2 KiB
Markdown
Raw Normal View History

2026-08-27 14:19:52 +03:00
# Qorona
2026-08-27 13:54:10 +03:00
2026-08-27 14:19:52 +03:00
Free, standalone, zero-dependency OpenAI-compatible proxy gateway in Go for the **Qwen 3.8 Max** model (`Qwen/Qwen3.8-Max`) hosted on Hugging Face Spaces.
2026-08-27 13:54:10 +03:00
2026-08-27 14:19:52 +03:00
## About
2026-08-27 13:54:10 +03:00
2026-08-27 14:19:52 +03:00
Qorona reverse-engineers the FiftyOne plugin backend operator interface of the Hugging Face space and transforms it into a standard, production-ready OpenAI API endpoint (`/v1/chat/completions` and `/v1/models`).
The name comes from Qwen + the default image of Corona Extra beer bottles that the target demo space passes to the model unless any other file is specified.
2026-08-27 13:54:10 +03:00
### Features
2026-08-27 14:19:52 +03:00
- **OpenAI Standard Compatibility**: Full drop-in replacement for OpenAI API clients (Curl, Python `openai`, LangChain, Open-WebUI).
2026-08-27 13:54:10 +03:00
- **Zero External Dependencies**: Pure standard library Go implementation (`net/http`, `encoding/json`, `crypto/rand`, `time`).
- **Fully Headless & Browserless**: No Chromium, Playwright, or X11 required. Runs directly on bare servers, containers, or embedded systems.
2026-08-27 13:54:10 +03:00
- **Live Streaming SSE & Reasoning**: Streams real-time tokens with separation of reasoning content (`delta.reasoning_content`) and message content (`delta.content`).
- **Function / Tool Calling Interception**: Supports OpenAI `tools` specification, system prompt tool schema injection, and stateful streaming interception of tool calls (`delta.tool_calls` and `finish_reason: "tool_calls"`).
- **Session Lifecycle Management**: Thread-safe automatic session creation (`/__session/start`), periodic background heartbeats (`/__session/heartbeat`), and auto-reconnect recovery.
- **Fibonacci Backoff Retry**: Resilient against network hiccups and transient timeouts.
2026-08-27 14:19:52 +03:00
## Architecture & upstream protocol
2026-08-27 13:54:10 +03:00
```
+---------------------------+ OpenAI HTTP / SSE +------------------------+
| Client (Python / Curl / | ===========================> | qorona Gateway |
2026-08-27 13:54:10 +03:00
| OpenAI SDK / Open-WebUI) | | (localhost:8080) |
+---------------------------+ +------------------------+
|
| FiftyOne Session &
| Operator API
v
+------------------------+
| HuggingFace Space |
| FiftyOne Backend |
| (Qwen 3.8 Max Model) |
+------------------------+
```
2026-08-27 14:19:52 +03:00
### Upstream flow
2026-08-27 13:54:10 +03:00
1. `POST /__session/start` -> Allocates an ephemeral session token `X-FiftyOne-Session` and dataset clone.
2. `POST /operators/execute` -> Dispatches the `@harpreetsahota/qwen38-max/qwen38_chat` operator with method `"ask"`.
3. Polling Loops:
- `get_thinking_chunk`: Extracts newly generated reasoning tokens in real-time.
- `get_stream_chunk`: Extracts newly generated message content tokens in real-time.
2026-08-27 14:22:06 +03:00
## Installation
```bash
go install code.luxferre.top/luxferre/qorona@latest
```
### Building from source
2026-08-27 13:54:10 +03:00
```bash
make qorona
2026-08-27 13:54:10 +03:00
```
Binary is output to `bin/qorona`.
2026-08-27 13:54:10 +03:00
2026-08-27 14:22:06 +03:00
## Running
2026-08-27 13:54:10 +03:00
```bash
./bin/qorona -port 8080
2026-08-27 13:54:10 +03:00
```
2026-08-27 14:19:52 +03:00
### CLI flags
2026-08-27 13:54:10 +03:00
| Flag | Default | Description |
|------|---------|-------------|
| `-port` | `8080` | Port to listen on |
| `-space-url` | `https://harpreetsahota-qwen38-max-openlogo-demo.hf.space` | Upstream Hugging Face Space URL |
| `-sample-path` | `/home/user/datasets/openlogo/data/data_0/logos32plus_002359.jpg` | Container image sample path |
| `-model` | `qwen-3.8-max` | Default model identifier |
| `-timeout` | `300` | Upstream timeout in seconds |
| `-user-agent` / `-ua` | `""` | Custom User-Agent header |
| `-hf-token` | `""` | Optional Hugging Face token |
2026-08-27 14:19:52 +03:00
## API usage examples
2026-08-27 13:54:10 +03:00
2026-08-27 14:19:52 +03:00
### 1. List models
2026-08-27 13:54:10 +03:00
```bash
curl http://localhost:8080/v1/models
```
2026-08-27 14:19:52 +03:00
### 2. Non-streaming chat completion
2026-08-27 13:54:10 +03:00
```bash
curl -X POST http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "qorona",
2026-08-27 13:54:10 +03:00
"messages": [
{"role": "user", "content": "What is the capital of Germany? Answer in 1 word."}
],
"reasoning_effort": "none",
"max_tokens": 50
}'
```
2026-08-27 14:19:52 +03:00
### 3. Streaming chat completion with reasoning
2026-08-27 13:54:10 +03:00
```bash
curl -N -X POST http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "qorona",
2026-08-27 13:54:10 +03:00
"messages": [
{"role": "user", "content": "Calculate 25 * 25 and explain in one sentence."}
],
"stream": true,
"reasoning_effort": "medium",
"max_tokens": 150
}'
```
2026-08-27 14:19:52 +03:00
### 4. Function / tool calling
2026-08-27 13:54:10 +03:00
```bash
curl -X POST http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "qorona",
2026-08-27 13:54:10 +03:00
"messages": [
{"role": "user", "content": "What is the weather in Berlin?"}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"}
},
"required": ["location"]
}
}
}
],
"reasoning_effort": "none"
}'
```
2026-08-27 14:19:52 +03:00
### 5. Python OpenAI client example
2026-08-27 13:54:10 +03:00
```python
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8080/v1",
api_key="none"
)
response = client.chat.completions.create(
model="qorona",
2026-08-27 13:54:10 +03:00
messages=[
{"role": "user", "content": "Write a short haiku about computers."}
],
stream=True
)
for chunk in response:
delta = chunk.choices[0].delta
if hasattr(delta, "reasoning_content") and delta.reasoning_content:
print(f"[Thinking] {delta.reasoning_content}", end="", flush=True)
if delta.content:
print(delta.content, end="", flush=True)
print()
```
## Testing
Run unit tests:
```bash
make test
```
Run end-to-end integration tests:
```bash
./xtest.sh 8080
```
2026-08-27 14:19:52 +03:00
## Credits
2026-08-27 13:54:10 +03:00
2026-08-27 14:19:52 +03:00
Created by Luxferre in 2026, released into the public domain with no warranties.