Skip to content

[Bug]: Undefined array key "input" when streaming with files attached #410

Closed
@arturspon

Description

@arturspon

Description

This bug started happening after #406.

When sending a message with a file and using streaming, it raises an exception with the following message: "Undefined array key "input".

Modifying the line 48 of the file src/Responses/Threads/Runs/Steps/Delta/ThreadRunStepDeltaObject.php to $attributes['input'] ?? '' made it work.

Stacktrace:

ErrorException: Undefined array key "input"
#15 /vendor/openai-php/client/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreter.php(48): Illuminate\Foundation\Bootstrap\HandleExceptions::handleError
#14 /vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(256): Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap\{closure}
#13 /vendor/openai-php/client/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreter.php(48): OpenAI\Responses\Threads\Runs\Steps\ThreadRunStepResponseCodeInterpreter::from
#12 /vendor/openai-php/client/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeToolCall.php(43): OpenAI\Responses\Threads\Runs\Steps\ThreadRunStepResponseCodeToolCall::from
#11 /vendor/openai-php/client/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseToolCallsStepDetails.php(42): OpenAI\Responses\Threads\Runs\Steps\ThreadRunStepResponseToolCallsStepDetails::OpenAI\Responses\Threads\Runs\Steps\{closure}
#10 [internal](0): array_map
#9 /vendor/openai-php/client/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseToolCallsStepDetails.php(40): OpenAI\Responses\Threads\Runs\Steps\ThreadRunStepResponseToolCallsStepDetails::from
#8 /vendor/openai-php/client/src/Responses/Threads/Runs/Steps/Delta/ThreadRunStepDeltaObject.php(39): OpenAI\Responses\Threads\Runs\Steps\Delta\ThreadRunStepDeltaObject::from
#7 /vendor/openai-php/client/src/Responses/Threads/Runs/Steps/Delta/ThreadRunStepDeltaResponse.php(40): OpenAI\Responses\Threads\Runs\Steps\Delta\ThreadRunStepDeltaResponse::from
#6 /vendor/openai-php/client/src/Responses/Threads/Runs/ThreadRunStreamResponse.php(63): OpenAI\Responses\Threads\Runs\ThreadRunStreamResponse::from
#5 /vendor/openai-php/client/src/Responses/StreamResponse.php(68): OpenAI\Responses\StreamResponse::getIterator
#4 /app/Http/Controllers/ChatController.php(54): App\Http\Controllers\ChatController::App\Http\Controllers\{closure}
#3 /vendor/symfony/http-foundation/StreamedResponse.php(106): Symfony\Component\HttpFoundation\StreamedResponse::sendContent
#2 /vendor/symfony/http-foundation/Response.php(398): Symfony\Component\HttpFoundation\Response::send
#1 /vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1172): Illuminate\Foundation\Application::handleRequest
#0 /public/index.php(17): null

Steps To Reproduce

  1. Create an assistant;
  2. Create a thread;
  3. Create a message in the thread and stream the response, like below:
OpenAI::threads()->messages()->create($chat->thread_id, [
    'role' => 'user',
    'content' => 'analyze this file and provide an overview for me',
    'file_ids' => {your_file_ids},
]);

$stream = OpenAI::threads()->runs()->createStreamed(
    threadId: {your_thread_id},
    parameters: [
         'assistant_id' => {your_assistant_id},
    ],
)

foreach ($stream as $chunk) {
    // code
}

OpenAI PHP Client Version

v0.9.0

PHP Version

8.3.6

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