I am encountering a very strange behaviour using the API. It used to work perfectly fine but since a few days the API returns an empty message. I included a rstrip to remove any potential white spaces or \n at the end of the prompt.
Please help!!
This is the part of the script:
Remove any trailing whitespace or newline characters, this sometimes produces error for openai api
content = content.rstrip()
retry_limit = 5
response = None
for retry_count in range(retry_limit):
try:
response = self.call_openai_api(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": content}],
max_tokens=2500,
n=1,
stop=None,
temperature=0.0,
)
break # If the call was successful, break the loop
except RateLimitError as e:
print(f"OpenAI API request exceeded rate limit: {e}. Attempt {retry_count + 1} of {retry_limit}")
time.sleep(10) # sleep for a while before retrying
except APIError as e:
print(f"OpenAI API returned an API Error: {e}")
break
except APIConnectionError as e:
print(f"Failed to connect to OpenAI API: {e}")
break
except InvalidRequestError as e:
print(f"Invalid request: {e}")
break
except AuthenticationError as e:
print(f"Authentication error: {e}")
break
except ServiceUnavailableError as e:
print(f"Service is currently unavailable: {e}")
break
except Exception as e:
print(f"An unexpected error occurred: {e}")
break
else: # This part will execute if the for loop completed all iterations without a break statement.
print("Retry limit exceeded.")
And the response: Authentication error:
Using playground works perfectly fine. My API key is correct and working (when using a simple test prompt).