Skip to content

docs: polish sglang launch & add python request examples#16

Merged
zhaochenyang20 merged 1 commit intozhaochenyang20:mainfrom
alphabetc1:doc/example_optimize
Feb 22, 2026
Merged

docs: polish sglang launch & add python request examples#16
zhaochenyang20 merged 1 commit intozhaochenyang20:mainfrom
alphabetc1:doc/example_optimize

Conversation

@alphabetc1
Copy link
Copy Markdown
Collaborator

@alphabetc1 alphabetc1 commented Feb 22, 2026

to #11

  1. Optimize the sglang launch command(port 30001 is occupied by ZMQ, so the second worker is changed to 30002).
  2. Add python example scripts.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @alphabetc1, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the SGLang documentation by adjusting a worker port to prevent conflicts and enhance usability. Additionally, it introduces practical Python code examples, making it easier for developers to integrate and test the SGLang router's functionalities programmatically.

Highlights

  • SGLang Launch Command Optimization: The port for the second SGLang worker has been updated from 30001 to 30002 in the documentation, resolving a potential conflict with ZMQ.
  • Python Request Examples Added: New Python example scripts have been included in the documentation to demonstrate how to interact with the SGLang router API using the requests library for tasks like health checks, listing workers, and image/video generation.
Changelog
  • README.md
    • Updated the sglang serve command to use port 30002 instead of 30001 for the second worker.
    • Modified sglang-d-router commands to reflect the new worker port 30002.
    • Added a curl command example for dynamically adding the worker on port 30002 to the router.
    • Introduced a new section titled 'Python requests examples' with code snippets demonstrating API interactions for health checks, worker listing, and image/video generation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request effectively resolves a port conflict issue by shifting the second worker's port to 30002 and updates the documentation to reflect this change. It also introduces a Python example section. My feedback focuses on improving the Python examples by using the project's existing dependency (httpx) instead of adding a new one (requests), and adding basic error handling to make the examples more reliable for users.

Comment thread README.md
Comment on lines +129 to +167
import requests
import base64

ROUTER = "http://localhost:30081"

# Check router health
resp = requests.get(f"{ROUTER}/health")
print(resp.json())

# List registered workers
resp = requests.get(f"{ROUTER}/list_workers")
print(resp.json())

# Image generation request (returns base64-encoded image)
resp = requests.post(f"{ROUTER}/generate", json={
"model": "Qwen/Qwen-Image",
"prompt": "a cute cat",
"num_images": 1,
"response_format": "b64_json",
})
data = resp.json()
print(data)

# Decode and save the image locally
img = base64.b64decode(data["data"][0]["b64_json"])
with open("output.png", "wb") as f:
f.write(img)
print("Saved to output.png")

# Video generation request
resp = requests.post(f"{ROUTER}/generate_video", json={
"model": "Qwen/Qwen-Image",
"prompt": "a flowing river",
})
print(resp.json())

# Check per-worker health and load
resp = requests.get(f"{ROUTER}/health_workers")
print(resp.json())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The Python example currently uses the requests library, which is not a dependency of this project (the router uses httpx). Users following the installation guide will have httpx available, but might not have requests. Switching to httpx ensures the example works out-of-the-box. Additionally, incorporating resp.raise_for_status() provides better error handling for connection or API issues.

import httpx
import base64

ROUTER = "http://localhost:30081"

with httpx.Client(base_url=ROUTER) as client:
    # Check router health
    resp = client.get("/health")
    resp.raise_for_status()
    print(resp.json())

    # List registered workers
    resp = client.get("/list_workers")
    resp.raise_for_status()
    print(resp.json())

    # Image generation request (returns base64-encoded image)
    resp = client.post("/generate", json={
        "model": "Qwen/Qwen-Image",
        "prompt": "a cute cat",
        "num_images": 1,
        "response_format": "b64_json",
    })
    resp.raise_for_status()
    data = resp.json()
    print(data)

    # Decode and save the image locally
    img = base64.b64decode(data["data"][0]["b64_json"])
    with open("output.png", "wb") as f:
        f.write(img)
    print("Saved to output.png")

    # Video generation request
    resp = client.post("/generate_video", json={
        "model": "Qwen/Qwen-Image",
        "prompt": "a flowing river",
    })
    resp.raise_for_status()
    print(resp.json())

    # Check per-worker health and load
    resp = client.get("/health_workers")
    resp.raise_for_status()
    print(resp.json())

Copy link
Copy Markdown
Owner

@zhaochenyang20 zhaochenyang20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice done

@zhaochenyang20 zhaochenyang20 merged commit eef1d43 into zhaochenyang20:main Feb 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants