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

Handle missing attributes for assistant streaming #392

Conversation

robbie-thompson
Copy link
Contributor

@robbie-thompson robbie-thompson commented May 16, 2024

What:

  • Bug Fix
  • New Feature

Description:

Fixes an error when OpenAI's API returns a delta object which has empty tool calls:

Undefined array key "id" {"exception":"[object] (ErrorException(code: 0): Undefined array key \"id\" at /var/www/html/vendor/openai-php/client/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunctionToolCall.php:41)

(
    [id] => step_voklimBxRmx023PqaIxX6hya
    [object] => thread.run.step.delta
    [delta] => Array
        (
            [step_details] => Array
                (
                    [type] => tool_calls
                    [tool_calls] => Array
                        (
                            [0] => Array
                                (
                                    [index] => 0
                                    [type] => function
                                    [function] => Array
                                        (
                                            [arguments] => {}
                                        )
                                )
                        )
                )
        )
)

This is happening to me for all streamed assistant responses that invoke function calls, the function itself appears in one delta, and the next delta then shows the empty function above.

The current implementation is expecting these delta objects to have ID and name fields, which it seems the empty functions don't have.

This is related to the assistants streaming functionality merged in earlier today: #367

@KaipiYann
Copy link

Thks @robbie-thompson !
I had the same problem...And your fix is working !

@gehrisandro gehrisandro merged commit fc9f672 into openai-php:main May 21, 2024
@gehrisandro
Copy link
Collaborator

Thanks @robbie-thompson for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants