openai-php / client

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

How to use vision ? #245

Closed gofortiss closed 8 months ago

gofortiss commented 8 months ago

Hello !

Can you update the doc to add gpt-4-vision-preview ?

gofortiss commented 8 months ago

something like this : $binaryData = file_get_contents($imagePath);

    $base64EncodedImage = base64_encode($binaryData);

    $openaiResponse = OpenAI::chat()->create([
        'model' => 'gpt-4-vision-preview',
        "messages" => [
            [
                "role" => "user",
                "content" => [
                    ["type" => "text", "text" => "What’s in this image?"],
                    [
                        "type" => "image_url",
                        "image_url" => "data:image/jpeg;base64,{$base64EncodedImage}"
                    ],
                ],
            ]
        ],
        "max_tokens" => 300
    ]);
gehrisandro commented 8 months ago

Thanky @gofortiss, this should work.

As an alternative you can pass an URL for the image like "https://example.com/image.jpg".

More details in the official OpenAI docs: https://platform.openai.com/docs/guides/vision/quick-start