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

GPT-4-VISION-PREVIEW streaming in Laravel backend is not working #264

Closed ivanuccle closed 10 months ago

ivanuccle commented 10 months ago
        try {
            $result = $client->chat()->createStreamed([
                'model' => "gpt-4-vision-preview",//$openai_model,
                'messages' => $messages
            ]);

            foreach ($result as $response) {
                error_log(json_encode(['message' => $response]));
                echo "event: data\n";
                echo "data: " . json_encode(['message' => $response->choices[0]->delta->content]) . "\n\n";
                flush();
            }

            echo "event: stop\n";
            echo "data: stopped\n\n";
        } catch (Exception $e) {
            error_log($e->getMessage());
        }

This code is working with gpt-4-1106-preview but not working gpt-4-vision-preview. Error: Undefined array key "finish_reason". Please help me asap.

gehrisandro commented 10 months ago

Hi @prosedev

You are probably not using the latest version of the library. Please update.

If this does not solve your problem, please let me know.

ivanuccle commented 10 months ago

Thanks.

Message ID: @.*** com>