You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looks like this code is a bit weak to handle the invalid stream
// HTTP 204 means "close the connection, no more data will be sent"
if (status === 204) {
onDisconnect()
close()
return
}
code to reproduce
async function main() {
const es = createEventSource({
url: 'https://api.openai.com/v1/chat/completions',
method: 'POST',
body: JSON.stringify({
model: 'gpt-4o-mini',
messages: [
{role: 'system', content: 'You are a helpful assistant.'},
{role: 'user', content: 'create some longest possible esseay on what is the purpose of life?'},
],
max_tokens: 5000,
temperature: 0.5,
stream: true,
}),
headers: {
'content-type': 'application/json',
authorization: 'Bearer ' + 'sk-xxx',
}
})
let seenMessages = 0
for await (const { data, event, id } of es) {
console.log(data)
}
// IMPORTANT: EventSource is _not_ closed automatically when breaking out of
// loop. You must manually call `close()` to close the connection.
es.close()
}
The text was updated successfully, but these errors were encountered:
The done value should be used to close the stream
Looks like this code is a bit weak to handle the invalid stream
code to reproduce
The text was updated successfully, but these errors were encountered: