Skip to content

Latest commit

 

History

History
44 lines (36 loc) · 1.07 KB

python-openai.md

File metadata and controls

44 lines (36 loc) · 1.07 KB

Official OpenAI Python SDK Integration

Any Python application utilizing the official openai package can connect to NOVA V2 by setting base_url.

1. Installation

pip install openai

2. Synchronous & Streaming Example

from openai import OpenAI

# Point client to local or cluster NOVA V2 daemon
client = OpenAI(
    base_url="http://127.0.0.1:3001/v1",
    api_key="secret-nova-key"
)

# 1. Non-streaming completion
completion = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": "You are a concise engineering assistant."},
        {"role": "user", "content": "Explain Tokio's work-stealing scheduler."}
    ]
)
print("Sync Response:\n", completion.choices[0].message.content)

# 2. Streaming completion
stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Count from 1 to 5."}],
    stream=True
)
print("\nStreaming Response:")
for chunk in stream:
    delta = chunk.choices[0].delta.content or ""
    print(delta, end="", flush=True)
print()