2
0

(openai) Retry OpenAI call if status code is 503

Closes #529
This commit is contained in:
Baptiste Arnaud
2023-06-16 19:31:28 +02:00
parent 524f1565d8
commit dcdf870308
4 changed files with 14 additions and 3 deletions

View File

@@ -42,6 +42,17 @@ export const executeChatCompletionOpenAIRequest = async ({
return { response, logs }
} catch (error) {
if (error instanceof HTTPError) {
if (error.response.statusCode === 503) {
console.log('OpenAI API error - 503, retrying in 3 seconds')
await new Promise((resolve) => setTimeout(resolve, 3000))
return executeChatCompletionOpenAIRequest({
apiKey,
model,
messages,
temperature,
currentLogs: logs,
})
}
if (error.response.statusCode === 400) {
const log = {
status: 'info',