openai-php / laravel

⚡️ OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with OpenAI API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Streaming with GPT4 Turbo Vision Preview in Laravel

charlesdev2024 opened this issue · comments

            $result = $client->chat()->createStreamed([
                'model' => $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";

This code works with all models except gpt4 turbo vision preview model.

In case of gpt4 turbo vision preview model, it logs
Undefined array key 'finish_reason'

you can consult this link, which provides a good explanation of your problem.
openai-php/client#147 (comment)

gpt-4-vision-preview streaming works on frontend but not working backend when I'm using openai-php
How can I fix this?

@prosedev Please provide more information if you still have the problem.

Feel free to reopen the issue or create a new.