Skip to content

Commit eef1d43

Browse files
Merge pull request #16 from alphabetc1/doc/example_optimize
docs: polish sglang launch & add python request examples
2 parents fc67cd0 + f298193 commit eef1d43

1 file changed

Lines changed: 48 additions & 3 deletions

File tree

README.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ CUDA_VISIBLE_DEVICES=1 sglang serve \
5151
--model-path Qwen/Qwen-Image \
5252
--num-gpus 1 \
5353
--host 127.0.0.1 \
54-
--port 30001
54+
--port 30002
5555
```
5656

5757
### Start the router
@@ -60,21 +60,22 @@ CUDA_VISIBLE_DEVICES=1 sglang serve \
6060

6161
```bash
6262
sglang-d-router --port 30081 \
63-
--worker-urls http://localhost:30000 http://localhost:30001
63+
--worker-urls http://localhost:30000 http://localhost:30002
6464
```
6565

6666
2. Module entry
6767

6868
```bash
6969
python -m sglang_diffusion_routing --port 30081 \
70-
--worker-urls http://localhost:30000 http://localhost:30001
70+
--worker-urls http://localhost:30000 http://localhost:30002
7171
```
7272

7373
3. Or start empty and add workers later:
7474

7575
```bash
7676
sglang-d-router --port 30081
7777
curl -X POST "http://localhost:30081/add_worker?url=http://localhost:30000"
78+
curl -X POST "http://localhost:30081/add_worker?url=http://localhost:30002"
7879
```
7980

8081
### Test the router
@@ -125,6 +126,50 @@ curl -X POST http://localhost:30081/generate_video \
125126
curl http://localhost:30081/health_workers
126127
```
127128

129+
### Python requests examples
130+
131+
```python
132+
import requests
133+
import base64
134+
135+
ROUTER = "http://localhost:30081"
136+
137+
# Check router health
138+
resp = requests.get(f"{ROUTER}/health")
139+
print(resp.json())
140+
141+
# List registered workers
142+
resp = requests.get(f"{ROUTER}/list_workers")
143+
print(resp.json())
144+
145+
# Image generation request (returns base64-encoded image)
146+
resp = requests.post(f"{ROUTER}/generate", json={
147+
"model": "Qwen/Qwen-Image",
148+
"prompt": "a cute cat",
149+
"num_images": 1,
150+
"response_format": "b64_json",
151+
})
152+
data = resp.json()
153+
print(data)
154+
155+
# Decode and save the image locally
156+
img = base64.b64decode(data["data"][0]["b64_json"])
157+
with open("output.png", "wb") as f:
158+
f.write(img)
159+
print("Saved to output.png")
160+
161+
# Video generation request
162+
resp = requests.post(f"{ROUTER}/generate_video", json={
163+
"model": "Qwen/Qwen-Image",
164+
"prompt": "a flowing river",
165+
})
166+
print(resp.json())
167+
168+
# Check per-worker health and load
169+
resp = requests.get(f"{ROUTER}/health_workers")
170+
print(resp.json())
171+
```
172+
128173
## Router API
129174

130175
- `POST /add_worker`: add worker via query (`?url=`) or JSON body.

0 commit comments

Comments
 (0)