fix:Vertex AI API 호출 시 role 필드 추가
- Vertex AI는 contents에 role: 'user' 필수 - Google AI Studio와 Vertex AI 분기 처리 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -53,7 +53,7 @@ private function callVertexAiApi(AiConfig $config, string $base64Image): array
|
||||
return $this->callGeminiApi($url, $base64Image, [
|
||||
'Authorization' => 'Bearer ' . $accessToken,
|
||||
'Content-Type' => 'application/json',
|
||||
]);
|
||||
], true); // Vertex AI
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,13 +69,13 @@ private function callGoogleAiStudioApi(AiConfig $config, string $base64Image): a
|
||||
|
||||
return $this->callGeminiApi($url, $base64Image, [
|
||||
'Content-Type' => 'application/json',
|
||||
]);
|
||||
], false); // Google AI Studio
|
||||
}
|
||||
|
||||
/**
|
||||
* Gemini API 공통 호출 로직
|
||||
*/
|
||||
private function callGeminiApi(string $url, string $base64Image, array $headers): array
|
||||
private function callGeminiApi(string $url, string $base64Image, array $headers, bool $isVertexAi = false): array
|
||||
{
|
||||
// Base64 데이터에서 prefix 제거
|
||||
$imageData = $base64Image;
|
||||
@@ -88,25 +88,30 @@ private function callGeminiApi(string $url, string $base64Image, array $headers)
|
||||
|
||||
$prompt = $this->buildPrompt();
|
||||
|
||||
// Vertex AI는 role 필드 필요
|
||||
$content = [
|
||||
'parts' => [
|
||||
[
|
||||
'inlineData' => [
|
||||
'mimeType' => $mimeType,
|
||||
'data' => $imageData,
|
||||
],
|
||||
],
|
||||
[
|
||||
'text' => $prompt,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
if ($isVertexAi) {
|
||||
$content['role'] = 'user';
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::timeout(30)
|
||||
->withHeaders($headers)
|
||||
->post($url, [
|
||||
'contents' => [
|
||||
[
|
||||
'parts' => [
|
||||
[
|
||||
'inlineData' => [
|
||||
'mimeType' => $mimeType,
|
||||
'data' => $imageData,
|
||||
],
|
||||
],
|
||||
[
|
||||
'text' => $prompt,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'contents' => [$content],
|
||||
'generationConfig' => [
|
||||
'temperature' => 0.1,
|
||||
'topK' => 40,
|
||||
|
||||
Reference in New Issue
Block a user