Skip to content

[Bug]: Undefined array key "choices" in CreateStreamedResponse.php when using createStreamed() #717

@advanced03

Description

@advanced03

Description

When using createStreamed() in an environment using Symfony 6.4 and PHP 8.2.27, the iterator fails with:

Warning: Undefined array key "choices"
in vendor/openai-php/client/src/Responses/Chat/CreateStreamedResponse.php on line 45

This seems to happen even with valid requests, because AFAIK streamed SSE responses also include non-message events (e.g. [DONE], empty lines, or keep-alive comments) that don't contain a choices key.

CreateStreamedResponse::from() unconditionally accesses $attributes['choices'], causing a PHP warning.

Steps To Reproduce

Try to get a streamed response with createStreamed() using a locally running Ollama server with Open-AI compatible endpoints.

OpenAI PHP Client Version

v0.18.0

PHP Version

v8.2.27

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions