Skip to content

Commit c80dc08

Browse files
author
Nico Hiort af Ornäs
committed
[Platform][VertexAI] Add support for API key authentication
1 parent da3c61a commit c80dc08

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/platform/src/Bridge/VertexAi/Embeddings/ModelClient.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function __construct(
2626
private readonly HttpClientInterface $httpClient,
2727
private readonly string $location,
2828
private readonly string $projectId,
29+
private readonly ?string $apiKey = null,
2930
) {
3031
}
3132

@@ -47,6 +48,10 @@ public function request(BaseModel $model, array|string $payload, array $options
4748
'predict',
4849
);
4950

51+
if (null !== $this->apiKey) {
52+
$url .= '?key=' . $this->apiKey;
53+
}
54+
5055
$modelOptions = $model->getOptions();
5156

5257
$payload = [

src/platform/src/Bridge/VertexAi/Gemini/ModelClient.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function __construct(
3030
HttpClientInterface $httpClient,
3131
private readonly string $location,
3232
private readonly string $projectId,
33+
private readonly ?string $apiKey = null,
3334
) {
3435
$this->httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
3536
}
@@ -52,6 +53,10 @@ public function request(BaseModel $model, array|string $payload, array $options
5253
$options['stream'] ?? false ? 'streamGenerateContent' : 'generateContent',
5354
);
5455

56+
if (null !== $this->apiKey) {
57+
$url .= '?key=' . $this->apiKey;
58+
}
59+
5560
if (isset($options[PlatformSubscriber::RESPONSE_FORMAT]['json_schema']['schema'])) {
5661
$options['generationConfig']['responseMimeType'] = 'application/json';
5762
$options['generationConfig']['responseSchema'] = $options[PlatformSubscriber::RESPONSE_FORMAT]['json_schema']['schema'];

src/platform/src/Bridge/VertexAi/PlatformFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ final class PlatformFactory
3333
public static function create(
3434
string $location,
3535
string $projectId,
36+
?string $apiKey = null,
3637
?HttpClientInterface $httpClient = null,
3738
ModelCatalogInterface $modelCatalog = new ModelCatalog(),
3839
?Contract $contract = null,
@@ -45,7 +46,7 @@ public static function create(
4546
$httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
4647

4748
return new Platform(
48-
[new GeminiModelClient($httpClient, $location, $projectId), new EmbeddingsModelClient($httpClient, $location, $projectId)],
49+
[new GeminiModelClient($httpClient, $location, $projectId, $apiKey), new EmbeddingsModelClient($httpClient, $location, $projectId, $apiKey)],
4950
[new GeminiResultConverter(), new EmbeddingsResultConverter()],
5051
$modelCatalog,
5152
$contract ?? GeminiContract::create(),

0 commit comments

Comments
 (0)