-
Notifications
You must be signed in to change notification settings - Fork 876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
createChatCompletion seems to ignore the abort signal #134
Comments
I have tried both By the way, I tried using frequency and presence penalty, but I think those penalty scores cause the bot to compensate with incorrect substitute tokens in things like long JSON responses. |
I am having the same issue. Perhaps it related to the version of axios that they are using (0.X.X) which may not support cancellation of a streaming response. It may be the case that cancellation of a streaming response was added in 1.X of axios here: axios/axios#4772 |
I ran into the same issue trying both, seems to be a bug. Your mileage may vary, but as a workaround I was able to successfully stop completions by calling |
same issue here, any solutions? |
I had some luck using const data = {
messages,
model,
stream : true,
temperature : 0,
};
const abortController = new AbortController ();
fetch (
"https://api.openai.com/v1/chat/completions",
{
method : "POST",
headers : {
"Authorization" : `Bearer ${ openaiKey }`,
"Content-Type" : "application/json",
},
body : JSON.stringify ( data ),
signal : abortController.signal,
}
) |
It appears that destroying the stream is the only necessary action. |
Thanks for the report! Our upcoming version v4.0.0 should properly support the abort signal; please give it a try and share your feedback in the thread! |
openai sdk v3 is using axios v0.26.1, which is unable to stop stream under node environment |
Please give openai sdk v4 a try:
|
Hey @rattrayalex I use [email protected] in my NestJS app like this: const abortController = new AbortController();
const stream = await openai.chat.completions.create(
{
model: 'gpt-4',
messages: [{ role: 'user', content: 'test prompt' }],
stream: true
},
{ signal: abortController.signal }
);
setTimeout(() => {
// stream.controller.abort();
abortController.abort();
}, 1000); But when I try to make a production build of the project, I get Uncaught ReferenceError: AbortController is not defined exception raised in node_modules/openai/_shims/agent.node.js // node_modules/openai/_shims/agent.node.js
if (typeof AbortController === 'undefined') {
AbortController = abort_controller_1.AbortController;
} Could you help me figure this out? |
@and-zverev can you open a new issue with this information, and also include your package.json, tsconfig, and similar files? |
I just double-checked everything and found that I worked on [email protected] |
Describe the bug
Sending an 'abort' signal to the
createChatCompletion
does not raise an error nor stop the completion.It makes me believe that this discussion on the openai community is true https://community.openai.com/t/cancelling-openai-apis-request/99754, but I would like to verify it isn't a bug in this library.
To Reproduce
Here's my code
Expectation: I should see output like this, and then an error should be raised:
Actual: I see output like this that never stops:
Code snippets
No response
OS
macOS
Node version
v19.8.1
Library version
openai v3.2.1
The text was updated successfully, but these errors were encountered: