Files
sam-kd/chatbot/test_embedding.php
hskwon aca1767eb9 초기 커밋: 5130 레거시 시스템
- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경
- DB 연결 하드코딩 → .env 기반으로 변경
- MySQL strict mode DATE 오류 수정
2025-12-10 20:14:31 +09:00

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";
?>