openai-php / client

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

[Bug]: GPT-4-Vision-Preview Warning - Undefined array key "finish_reason" in .../Responses/Chat/CreateResponseChoice.php on line 24. #290

Closed stevebauman closed 9 months ago

stevebauman commented 9 months ago

Description

It appears the gpt-4-vision-preview model has a different response structure in $attributes here:

https://github.com/openai-php/client/blob/759196cb9eb5550c16c7d1b15364a925a3b8d3e3/src/Responses/Chat/CreateResponseChoice.php#L16-L26

array [
    'message' => [    
        'role' => 'assistant',
        'content' => '...',
    ],
    'finish_details' => [    
        'type' => 'stop',
        'stop' => '<|fim_suffix|>',
    ],
    'index' => 0,
]

Steps To Reproduce

// Undefined array key "finish_reason" in .../Responses/Chat/CreateResponseChoice.php on line 24.
OpenAI::chat()->create([
    'model' => 'gpt-4-vision-preview',
    'messages' => [
        [
            'role' => 'system',
            'content' => 'Analyze this image',
        ],
        [
            'role' => 'user',
            'content' => [
                [
                    'type' => 'image_url',
                    'image_url' => [
                        'url' => 'https://en.wikipedia.org/static/images/icons/wikipedia.png',
                    ],
                ]
            ],
        ],
    ]
]);

OpenAI PHP Client Version

v0.6.4

PHP Version

8.1.22

Notes

No response

stevebauman commented 9 months ago

Had to update, my mistake 🙏