The API reference states:
For example, we emit thread.run.created
when a new run is created, thread.run.completed
when a run completes, and so on.
But the example code doesn’t show that.
const run = openai.beta.threads.runs.stream(thread.id, {
assistant_id: assistant.id
})
.on('textCreated', (text) => process.stdout.write('\nassistant > '))
I have tried to listen for events like this
run.on('messageCreated', async (message) => {
console.log(message)
});
Nothing is logged.
I also tried this
run. On('thread.message.completed', async (message) => {
console.log(message)
});
Nothing is logged.
I have also tried this
run.on('event', (event) => {
console.log('event', event);
})
And I can see an event named thread.message.completed.
Where is the list of events to listen for please?
This also got me in the wrong track when I was tinkering around streaming. The main problem is you are mixing the example code and the one in the reference page.
To get thread.run.created
, etc., use the generic Run function with streaming not the one using createAndStream
SDK helper
const stream = await openai.beta.threads.runs.create(
thread_id,
{
assistant_id,
stream: true
}
for await (const event of stream) {
/*
event = {
event: 'thread.run.created',
data: {
..
}
}
*/
}
Ah right, that is super helpful, thanks. I will give that a go.
Olyray
April 27, 2024, 8:06pm
4
I checked the npm openai documentation and it had a link to the helpers.md on github, which lists all the helpers for the node SDK.
I think that was what you were originally looking for, because it was what I was also looking for the events that applied to the stream helper method.
I tried posting the link, but apparently I can’t because I’m a new user or something like that.
Thanks, I did find it in the end but it’s all very confusing still. The examples in the documentation are not great.
1 Like
There are even errors in the docs. I just suffered through an encounter with the uploadAndPoll method for vectorStores.