Azure OpenAI | Intermittent RestError: read ECONNRESET Error when Sending Messages to OpenAI Deployment
I am facing an intermittent issue with the @azure/openai@1.0.0-beta.2
library using the Node.js@18.15.0
. While attempting to send messages to an OpenAI deployment, I sporadically encounter the ECONNRESET error. Despite multiple attempts, this problem persists. Below is my code snippet along with the error message:
code :
for (let attempt = 0, keyIdx = 0; attempt < retries; attempt++, keyIdx++) {
const openai = await this.createAPI();
const messages = [
{
role: 'system',
content: prompt,
},
{ role: 'user', content: content },
];
try {
let res = '';
const result = await openai.getChatCompletions(
OPENAI_DEPLOYMENT_ID,
messages,
);
for (const choice of result.choices) {
console.log(choice.message.content);
res += choice.message.content;
}
return res;
} catch (error) {
if (attempt === retries - 1) {
console.log('Failed after maximum attempts', error);
throw error;
}
}
}
Error Message:
Failed after maximum attempts RestError: read ECONNRESET
{
"name": "RestError",
"code": "ECONNRESET",
"request": {
"url": "https://[xxx].openai.azure.com/openai/deployments/[openai-model]/chat/completions?api-version=2023-08-01-preview",
"headers": {
// Request headers
},
"method": "POST",
"timeout": 0,
"disableKeepAlive": false,
// ...
},
"message": "read ECONNRESET"
}
Expected Resolution: I am seeking assistance in resolving the intermittent ECONNRESET error, which is impeding my ability to consistently send messages to the OpenAI deployment. I need help identifying the root cause of this issue and obtaining a solution.
Additional Information:
- I am using Node.js v18.15.0.
- The version of the
@azure/openai
library I am using is 1.0.0-beta.2.
Thank you for your support!