gemini-api-php / client

Google Gemini API PHP Client allows you to use the Gemini AI model
MIT License
118 stars 23 forks source link

Error - TextPart Class #26

Closed CheungRCT closed 9 months ago

CheungRCT commented 9 months ago
$response = $client->geminiPro()->generateContent(
    new TextPart('PHP in less than 100 chars')
);

results in TextPart Class not found

When following the screenshot program instead (the screen shot example has a different syntax from your documentation example:

$response = $client->geminiPro()->generateContent(
    new GeminiAPI\Resources\Parts\TextPart('PHP in less than 100 chars')
);

It calls with the following error:

PHP Fatal error:  Uncaught RuntimeException: Gemini API operation failed: operation=models/gemini-pro:generateContent, status_code=400,  response={
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"{\"model\":\"models\\/gemini-pro\",\"contents\":[{\"parts\":[{\"text\":\"PHP in less than 100 chars\"}],\"role\":\"user\"}]}\": Cannot bind query parameter. Field '{\"model\":\"models\\/gemini-pro\",\"contents\":[{\"parts\":[{\"text\":\"PHP in less than 100 chars\"}],\"role\":\"user\"}]}' could not be found in request message.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "description": "Invalid JSON payload received. Unknown name \"{\"model\":\"models\\/gemini-pro\",\"contents\":[{\"parts\":[{\"text\":\"PHP in less than 100 chars\"}],\"role\":\"user\"}]}\": Cannot bind query parameter. Field '{\"model\":\"models\\/gemini-pro\",\"contents\":[{\"parts\":[{\"text\":\"PHP in less than 100 chars\"}],\"role\":\"user\"}]}' could not be found in request message."
          }
        ]
      }
    ]
  }
}
erdemkose commented 9 months ago

Can you please share which version of the library and PHP you are using?

erdemkose commented 9 months ago

The problem should be solved in v1.4.2. Can you please update the library and try again?

CheungRCT commented 9 months ago

Can you please share which version of the library and PHP you are using? Previously I was using PHP 8.2.14 and the library version that I used was 1.3