Skip to content

Enable streaming option in the OpenAI API server#480

Merged
loadams merged 7 commits into
mainfrom
adk9/oai-streaming
Sep 3, 2024
Merged

Enable streaming option in the OpenAI API server#480
loadams merged 7 commits into
mainfrom
adk9/oai-streaming

Conversation

@adk9

@adk9 adk9 commented May 16, 2024

Copy link
Copy Markdown
Contributor

Now that token streaming support has merged (#397), we can enable streaming response in the OpenAI RESTful API endpoint.

This PR

Running the Server

python -m mii.entrypoints.openai_api_server \
    --model "mistralai/Mistral-7B-Instruct-v0.1" \
    --port 3000 \
    --host 0.0.0.0

Client

from openai import OpenAI

client = OpenAI(
    base_url="http://ip:port/v1",
    api_key="test",
)

completion = client.chat.completions.create(
    model="mistralai/Mistral-7B-v0.1",
    messages=[
        {
            "role": "user",
            "content": "Tell me a joke.",
        },
    ],
    max_tokens=1024,
    stream=True
)

for chunk in completion:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="")

@adk9
adk9 requested review from awan-10 and mrwyattii as code owners May 16, 2024 18:54
Comment thread requirements/requirements.txt Outdated
Comment thread .github/workflows/nv-a6000-fastgen.yml
@loadams
loadams merged commit 3ed3aa2 into main Sep 3, 2024
@loadams
loadams deleted the adk9/oai-streaming branch September 3, 2024 20:21
loadams added a commit that referenced this pull request Feb 7, 2025
Co-authored-by: Logan Adams <114770087+loadams@users.noreply.github.com>
Co-authored-by: Logan Adams <loadams@microsoft.com>
Signed-off-by: Logan Adams <loadams@microsoft.com>
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.

Is openai compatible server still working?

2 participants