33 lines
918 B
PHP
33 lines
918 B
PHP
|
|
<?php
|
||
|
|
// Test script for Google Vertex AI Embedding API
|
||
|
|
$apiKeyPath = '../apikey/google_vertex_api.txt';
|
||
|
|
if (!file_exists($apiKeyPath)) {
|
||
|
|
die("API Key file not found");
|
||
|
|
}
|
||
|
|
$apiKey = trim(file_get_contents($apiKeyPath));
|
||
|
|
|
||
|
|
$url = "https://generativelanguage.googleapis.com/v1beta/models/text-embedding-004:embedContent?key=" . $apiKey;
|
||
|
|
|
||
|
|
$data = [
|
||
|
|
'model' => 'models/text-embedding-004',
|
||
|
|
'content' => [
|
||
|
|
'parts' => [
|
||
|
|
['text' => 'Hello, this is a test for embedding.']
|
||
|
|
]
|
||
|
|
]
|
||
|
|
];
|
||
|
|
|
||
|
|
$ch = curl_init($url);
|
||
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
||
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
||
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
|
||
|
|
|
||
|
|
$response = curl_exec($ch);
|
||
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||
|
|
curl_close($ch);
|
||
|
|
|
||
|
|
echo "HTTP Code: $httpCode\n";
|
||
|
|
echo "Response: $response\n";
|
||
|
|
?>
|