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

[Bug]: Undefined array key "file_id #456

Closed
ckefalianou opened this issue Jul 25, 2024 · 5 comments
Closed

[Bug]: Undefined array key "file_id #456

ckefalianou opened this issue Jul 25, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@ckefalianou
Copy link

ckefalianou commented Jul 25, 2024

Description

Undefined array key "file_id"

I did some digging, and found out that the issue is created in that file: openai-php/client/src/Responses/Threads/Messages/ThreadMessageResponseContentImageUrl.php

because it looks for file_id not url , which file_id doesn't exist in the content I sent.

Can you please resolve it or suggest a solution?
Thank you in advance!

Steps To Reproduce

I am using the library, sending a text and some image_url as content.
After retrieving the Assistant, creating a Thread, I create the following Message:

$openAI_message = $client->threads()->messages()->create($openAI_thread->id, [ 'role' => 'user', 'content' => [ [ 'type' => 'text', 'text' => $prompt['title'] ], [ 'type' => 'image_url', 'image_url' => [ 'url' => $photo[0]->large, 'detail' => 'high', ], ], [ 'type' => 'image_url', 'image_url' => [ 'url' => $photo[1]->large, 'detail' => 'high', ], ], ] ]);
After creating the Run I get the following issue: Undefined array key "file_id"

OpenAI PHP Client Version

^0.10.1

PHP Version

8.3

Notes

No response

@ckefalianou ckefalianou added the bug Something isn't working label Jul 25, 2024
@SergiuDihel
Copy link

SergiuDihel commented Jul 30, 2024

I have the same issue.

I am trying to do something like:

'thread' => [
    'messages' => [[
        'role' => 'user',
        'content' => [
            [ 'type' => 'text', 'text' => $description ],
            [ 'type' => 'image_url', 'image_url' => [ 'url' => 'https://example.com/image.jpg']],
        ],
    ]],
],

From what I can understand, the issue is originating inside src/Responses/Threads/Messages/ThreadMessageResponseContentImageUrlObject.php on line 41.

return new self(
    $attributes['type'],
    ThreadMessageResponseContentImageUrl::from($attributes['image_url']),
);

ThreadMessageResponseContentImageUrl::from($attributes['image_url']) is trying to send a string (probably) containing the URL of the image. But if you look inside the static from, in ThreadMessageResponseContentImageUrl, you'll see it expects an array of attributes:

public static function from(array $attributes): self
{
    return new self(
        $attributes['file_id'],
        $attributes['detail'] ?? null,
    );
}

So it fails.
Hope I'm correct on this, I haven't spent too much time going deeper than this. 🤞

@MaskowLabs
Copy link

Everyone having the same issue, this is the fix:

  1. Change the File /vendor/openai-php/client/src/Responses/Threads/Messages/ThreadMessageResponseContentImageUrl.php
private function __construct(
        public string $imageUrl,
        public ?string $detail,
    ) {
    }

    public static function from(array $attributes): self {
        return new self(
            $attributes['url'],
            $attributes['detail'] ?? null,
        );
    }
    public function toArray(): array {
        return array_filter([
            'url' => $this->imageUrl,
            'detail' => $this->detail,
        ], fn (?string $value): bool => $value !== null);
    }
  1. Change the file /vendor/openai-php/client/src/Responses/Threads/Messages/ThreadMessageResponseContentImageUrlObject.php
public static function from(array $attributes): self{
       return new self(
           $attributes['type'],
           ThreadMessageResponseContentImageUrl::from($attributes), 
       );
   }

@ckefalianou
Copy link
Author

ckefalianou commented Jul 31, 2024

@jumaskow @SergiuDihel thank you for your responses.

I did the same and I was about to send a PR but I found out that issue is fixed at https://github.com/openai-php/client/blob/main/src/Responses/Threads/Messages/ThreadMessageResponseContentImageUrl.php

but not released yet.

I just replaced the version with "dev-main" until there's a release.

Thank you again! :)

@SergiuDihel
Copy link

SergiuDihel commented Jul 31, 2024

Hey @ckefalianou!
Damn, we synced just now. I was about to comment on this myself since I also realized it just now. 😆

The commit fixing this issue is here:
62a09ae

It was merged on June 7, with this PR:
#422

But it is not yet released, as you've said. For time being, I also currently use the current latest commit on HEAD.
"openai-php/client": "dev-main#e9ca2886aa9c0bf60fb3b8df00ad9e5b876a0916"

UPDATE:
@jumaskow, I've also tested this and it works, so I don't think we need #459.

@gehrisandro
Copy link
Collaborator

Going to make a new release tomorrow. Sorry for the long waiting time.

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

4 participants