openai-php / client

⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.
MIT License
4.99k stars 523 forks source link

[Bug]: Modify thread message throws 'attachments' key exception #470

Closed datashaman closed 2 weeks ago

datashaman commented 3 months ago

Description

When modifying a thread message's metadata after creation, the call to do so fails with:

  ErrorException

  Undefined array key "attachments"

  at vendor/openai-php/client/src/Responses/Threads/Messages/ThreadMessageResponse.php:64
     60▕         );
     61▕
     62▕         $attachments = array_map(
     63▕             fn (array $attachment): ThreadMessageResponseAttachment => ThreadMessageResponseAttachment::from($attachment),
  ➜  64▕             $attributes['attachments']
     65▕         );
     66▕
     67▕         return new self(
     68▕             $attributes['id'],

Steps To Reproduce

$thread = $client->threads()->create([]);

$message = $client->threads()->messages()->create($thread->id, [
    'role' => 'user',
    'content' => 'Explain deep learning to a 5 year old.',
]);

$response = $client->threads()->messages()->modify(
    threadId: $thread->id,
    messageId: $message->id,
    parameters: [
        'metadata' => [
            'key' => 'value',
        ],
    ]
);

OpenAI PHP Client Version

dev-main

PHP Version

8.3.9

Notes

No response

misteryomi commented 2 months ago

I’ll be pushing a PR on this later today.