Azure-Samples / Azure-Samples/openai

Intermittent RestError: read ECONNRESET Error when Sending Messages to OpenAI Deployment

Open
#46 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
1.3k
Forks
455
Avg merge
16h 17m
Merged PRs (30d)
1

Description

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!

### This issue is for a: (mark with an `x`)
```
- [x ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)
```

### Minimal steps to reproduce
>

### Any log messages given by the failure
>

### Expected/desired behavior
>

### OS and Version?
> Windows 11 & macOS

### Versions
> 1.0.0-beta.2

### Mention any other details that might be useful

> ---------------------------------------------------------------
> Thanks! We'll be in touch soon.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.