openai / openai-cookbook

Examples and guides for using the OpenAI API
https://cookbook.openai.com
MIT License
57.47k stars 9.07k forks source link

Update rate limit error detection criteria for Azure OpenAI API #1254

Open xingjian-zhang opened 2 weeks ago

xingjian-zhang commented 2 weeks ago

Summary

This PR updates the example of parallel requests to API to allow cool down for AzureOpenAI API.

Motivation

The current code supports both OpenAI and AzureOpenAI APIs, but the rate limit error will not be correctly detected when using AzureOpenAI due to the difference in error messages. An example of AzureOpenAI's rate limit error is:

{'code': '429', 'message': 'Requests to the Embeddings_Create Operation under Azure OpenAI API version 2023-12-01-preview have exceeded call rate limit of your current OpenAI S0 pricing tier. Please retry after 8 seconds. Please go here: https://aka.ms/oai/quotaincrease if you would like to further increase the default rate limit.'}

And this leads to the cool down code never activated.


For new content

When contributing new content, read through our contribution guidelines, and mark the following action items as completed:

We will rate each of these areas on a scale from 1 to 4, and will only accept contributions that score 3 or higher on all areas. Refer to our contribution guidelines for more details.