Azure / Azure/fetch-event-source

CORS error while using open ai completions

Open
#64 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
2.9k
Forks
196
PR merge metrics
No merged PRs in 30d

Description

```js
fetchEventSource('https://api.openai.com/v1/chat/completions', {
method: 'POST',
headers: {
Accept: 'text/event-stream',
'Content-Type': 'application/json',
Authorization: 'Bearer ' + process.env.NEXT_PUBLIC_OPENAI_KEY,
},
body: raw,
signal: ctrl.signal,
onopen(res) {
console.log('onopen ', res);
},

onmessage(evt) {
console.log('msg.data', evt.data);
if (evt.data == '[DONE]') return;

},

onclose() {
console.log('onclose - server error');
},

onerror(err) {
console.log('onerror', err);
throw err;
},
```

![Screenshot 2023-11-25 at 7 30 25 PM](https://github.com/Azure/fetch-event-source/assets/2174170/59de84cb-7bcb-49e3-a805-1ffa26d2de03)

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.