I keep on getting
local.ERROR: Class “Google\Cloud\AIPlatform\V1\PredictionServiceClient” not found {“userId”:1,“exception”:"[object] (Error(code: 0): Class "Google\Cloud\AIPlatform\V1\PredictionServiceClient" not found
My code looks like this
use Illuminate\Http\Request;
use Google\Cloud\AIPlatform\V1\PredictionServiceClient;
use Google\Cloud\AIPlatform\V1\ModelName;
use Google\Cloud\AIPlatform\V1\PredictRequest;
use Google\Cloud\AIPlatform\V1\Content;
use Google\Cloud\AIPlatform\V1\ExampleBase;
use Google\ApiCore\ApiException;
use Google\Protobuf\Value;
private function callGeminiAPI($prompt)
{
try {
$client = new PredictionServiceClient([
'credentials' => json_decode(file_get_contents(env('GOOGLE_APPLICATION_CREDENTIALS')), true),
'apiEndpoint' => env('GOOGLE_LOCATION') . '-aiplatform.googleapis.com',
]);
$formattedEndpoint = $client->endpointName(
env('GOOGLE_PROJECT_ID'),
env('GOOGLE_LOCATION'),
'gemini-1.5-pro-001'
);
$instance = (new Value())
->setStructValue(['content' => $prompt]);
$parameters = (new Value())
->setStructValue([
'temperature' => 0.2,
'maxOutputTokens' => 1024,
'topP' => 0.8,
'topK' => 40
]);
$request = (new PredictRequest())
->setEndpoint($formattedEndpoint)
->setInstances([$instance])
->setParameters($parameters);
$response = $client->predict($request);
$predictions = $response->getPredictions();
if (count($predictions) > 0) {
$result = $predictions[0]->getStructValue()->getFieldsEntry('content')->getValue()->getStringValue();
return $result;
} else {
return "No prediction received from the API.";
}
} catch (\Exception $e) {
\Log::error('Error calling Gemini API: ' . $e->getMessage());
return "Error: " . $e->getMessage();
}
}
I already have cloud-ai-platform installed.
Anyone know how to use the Prediction Service Client.
I am new to this.