openai-php / laravel

⚡️ OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with OpenAI API
MIT License
2.83k stars 189 forks source link

Send images to the api with model gpt-4-vision-preview to analyze the image #85

Closed ChristopherMassamba closed 10 months ago

ChristopherMassamba commented 11 months ago

well I’m looking to create a laravel app and the OpenAI API that will analyze documents and send me the descriptions of these documents how API cannot receive pdf I convert them to jpg and then send them to the api my problem is that my method to send images does not seems not to work :

` $imageUrl = asset('storage/Pdfs/images/' . $filejpgeg);

    $openaiResponse = OpenAI::completions()->create([
        'model' => 'gpt-4-vision-preview',
        'message' =>  [
            [
                'role' => 'user',
                'content' => [
                    ['type' => 'text', 'text' => 'What’s in this image?'],
                    [
                        'type' => 'image_url',
                        'image_url' => [
                            'url' => $imageUrl,
                        ],
                    ],
                ],
            ],
        ],
        'max_tokens' => 300,
    ]);

    return redirect()->back()->with([
        'success' => 'PDF uploaded and converted successfully.',
        'openaiResponse' => $openaiResponse,
        'imageUrl' => $imageUrl,
    ]);`
    I probably perform wrong manipulation if someone how to send images to the api 
gehrisandro commented 10 months ago

Hi @ChristopherMassamba

May the URL you create is not publicly available? Do you have an error message to share?

Feel free to reopen the issue.