Skip to content
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

openai.beta.chat.completions.stream(chatRequest).finalChatCompletion() throws missing finish_reason error for gpt-4o-audio-preview streaming. #1206

Open
1 task done
davit-b opened this issue Nov 27, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@davit-b
Copy link

davit-b commented Nov 27, 2024

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

Describe the bug

gpt-4o-audio-preview streamed final return chunk doesn't contain finish_reason and the finalizeChatCompletion method cannot handle it properly


data: {"id":"chatcmpl-123456","object":"chat.completion.chunk","created":1730764995,"model":"gpt-4o-audio-preview-2024-10-01","system_fingerprint":"fp_6e2d124157","choices":[{"index":0,"delta":{"audio":{"transcript":"!"}},"finish_reason":null}]}

data: {"id":"chatcmpl-123456","object":"chat.completion.chunk","created":1730764995,"model":"gpt-4o-audio-preview-2024-10-01","system_fingerprint":"fp_6e2d124157","choices":[{"index":0,"delta":{"role":"assistant","content":null,"refusal":null,"audio":{"id":"audio_672960c3a3e48190aed70377a7d6c941","data":"CAAIAAkACgAPABEAEQARABMAEAANAAgAAwD9//v/+f/3//L/8v/w//L/8"}},"finish_reason":null}]}

data: {"id":"chatcmpl-123456","object":"chat.completion.chunk","created":1730764995,"model":"gpt-4o-audio-preview-2024-10-01","system_fingerprint":"fp_6e2d124157","choices":[{"index":0,"delta":{"audio":{"data":"lBNbDTYZdhycFrgTxg6NBT8BavhC85LyNu/j9Yv8DvqAAuA"}},"finish_reason":null}]}

data: {"id":"chatcmpl-123456","object":"chat.completion.chunk","created":1730764995,"model":"gpt-4o-audio-preview-2024-10-01","system_fingerprint":"fp_6e2d124157","choices":[{"index":0,"delta":{"audio":{"data":"J/6d/nsAkAE3/xv7U/jp9ur0bPRY+DH//v//v8IAAcAEgALABsAFAANAAsA//8IAP//8//y//T/7//3//v/+v8TABsADgAdACIAPAACAPn//f/j/zAAIQATADIAQgBbAAwA+f/z/wgA/v8YABkAOAAjANn/"}},"finish_reason":null}]}

data: {"id":"chatcmpl-123456","object":"chat.completion.chunk","created":1730764995,"model":"gpt-4o-audio-preview-2024-10-01","system_fingerprint":"fp_6e2d124157","choices":[{"index":0,"delta":{"audio":{"expires_at":1730768595}}}]}

See how the final only has an expires_at and doesn't have a finish_reason

To Reproduce

const chatRequest = {
                messages: chatRequestMessageList,
                model: "gpt-4o-audio-preview",
                modalities: ["text", "audio"],
                audio: { voice: "alloy", format: "pcm16" },
                max_tokens: COMPLETION_RESPONSE_SETTING,
                temperature: 0.7,
                top_p: 1,
                stream: true,
                tools: request.body.tools,
                tool_choice: request.body.toolChoice,
            }
const stream = openai.beta.chat.completions.stream(chatRequest)
...
const finalChatCompletion = await stream.finalChatCompletion();

throw error

Error in the streaming of response: OpenAIError: missing finish_reason for choice... at finalizeChatCompletion ... at ChatCompletionStream._ChatCompletionStream_endRequest.....at ChatCompletionStream._createChatCompletion.... at process.processTicksAndRejections..... at async ChatCompletionStream._runChatCompletion....node_modules/openai/lib/AbstractChatCompletionRunner.js:135:16

Code snippets

No response

OS

macOS

Node version

node 18

Library version

4.73.1

@davit-b davit-b added the bug Something isn't working label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant