Azure OpenAI stream get ChunkEncodingError

Cooltruster 0 Reputation points
2023-09-01T03:11:43.2133333+00:00

Hi I have always been using OpenAI and recently switched to using Azure OpenAI.

In OpenAI I have always been able to stream responses but when I switched over to using Azure, I get ChunkEncodingError. For reference this is my code below.

import openai

openai.api_type = "azure"
openai.api_base = os.getenv("OPENAI_API_BASE")
openai.api_version = "2023-08-01-preview"
openai.api_key = os.getenv("AZURE_OPENAI_API_KEY")

response = openai.ChatCompletion.create(
	engine="gpt-4",
	temperature=0,
	messages=[
		{"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hi there"}
    ],
    stream=True,
)
for chunk in response:    
	print(chunk)

This is the error message that I get. Would be appreciative to anyone who can explain to be what I did wrong.

Screenshot 2023-09-01 at 11.09.49 AM

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,942 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.