google-gemini-php / laravel

⚡️ Gemini PHP for Laravel is a community-maintained PHP API client that allows you to interact with the Gemini AI API.
MIT License
252 stars 29 forks source link

Unsupported operand types: string * int #3

Closed tarun-pixeleyez closed 4 months ago

tarun-pixeleyez commented 4 months ago

I am using Laravel 10 version or Gemini 1.0 version but getting this error.

 public function index()
    {
        $result = Gemini::geminiPro()->generateContent('Hello');

        $result->text();
    }
aydinfatih commented 4 months ago

Hello @tarun-pixeleyez,

Can you share the full error log?

tarun-pixeleyez commented 4 months ago

Hii @aydinfatih

I just recieved Unsupported operand types: string * int error, when i run my index method.

aydinfatih commented 4 months ago

When I try the same code, no error occurs. If you can share the trace logs here. We can catch something from these logs.

aydinfatih commented 4 months ago

I am closing this issue as there is no reply. You can add a reply if the problem persists.

jhoanborges commented 1 month ago

+1 image

use Gemini\Data\Blob;
use Gemini\Enums\MimeType;
use Gemini\Laravel\Facades\Gemini;
use Illuminate\Http\Request;

        $result = Gemini::geminiProVision()
            ->generateContent([
                'What is this picture?',
                new Blob(
                    mimeType: MimeType::IMAGE_JPEG,
                    data: base64_encode(
                        file_get_contents('https://storage.googleapis.com/generativeai-downloads/images/scones.jpg')
                    )
                ),
            ]);

        $result->text();

Loog says something about guzzle

[2024-05-27 00:22:41] local.ERROR: Unsupported operand types: string int {"exception":"[object] (TypeError(code: 0): Unsupported operand types: string int at /var/www/html/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:420) [stacktrace]

0 /var/www/html/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(59): GuzzleHttp\Handler\CurlFactory->applyHandlerOptions()

laravel.log Please clone my project here: https://github.com/jhoanborges/gemini-reader

jhoanborges commented 1 month ago

Found the solution. When the following variables are empty in the .env file it crash

GEMINI_BASE_URL=

GEMINI_REQUEST_TIMEOUT=

I commented them out and it's working. Hope it helps