Hi,
I have started to receive bad request yesterday which was was working before. After debugging the issue. It seems to be related to the number of stop words. The bad request response occurs if you have 4 stop words. While less than 4 stop words works fine. This is regardless of what the actual words are. The API documentation suggest that 4 stops should be fine.
{‘error’: {‘message’: “‘$.stop’ is invalid. Please check the API reference: https://platform.openai.com/docs/api-reference.”, ‘type’: None, ‘param’: None, ‘code’: None}}
Example request that fails:
from openai import OpenAI
client = OpenAI()
stream = client.chat.completions.create(
model="gpt-4-turbo",
messages=[{"role": "user", "content": "Say this is a test"}],
stop=["1", "2", "3", "4"],
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end="")
This works:
from openai import OpenAI
client = OpenAI()
stream = client.chat.completions.create(
model="gpt-4-turbo",
messages=[{"role": "user", "content": "Say this is a test"}],
stop=["1", "2", "3"],
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end="")