Streaming
Unlocking Real-Time Interactions
# This code is for v1+ of the openai package https://pypi.org/project/openai/
from openai import OpenAI
client = OpenAI(
api_key= os.getenv("OPENAI_API_KEY"),
base_url = "https://turbo.gptboost.io/v1"
)
# Make a request to OpenAI API
stream = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "user", "content": "Tell me a story about a happy developer."}
],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "")curl --request 'https://turbo.gptboost.io/v1/chat/completions' \
--header 'Authorization: Bearer $OPENAI_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "Tell me an interesting fact about koalas!"
}
],
"stream": true
}'Last updated