docs: document how to programatically configure vertex embeddings to use a service account

This commit is contained in:
Gareth Evans
2024-11-15 13:15:43 +00:00
committed by Christian Tzolov
parent f9734a35aa
commit ea1871041c

View File

@@ -144,8 +144,8 @@ Next, create a `VertexAiTextEmbeddingModel` and use it for text generations:
[source,java]
----
VertexAiEmbeddigConnectionDetails connectionDetails =
VertexAiEmbeddigConnectionDetails.builder()
VertexAiEmbeddingConnectionDetails connectionDetails =
VertexAiEmbeddingConnectionDetails.builder()
.withProjectId(System.getenv(<VERTEX_AI_GEMINI_PROJECT_ID>))
.withLocation(System.getenv(<VERTEX_AI_GEMINI_LOCATION>))
.build();
@@ -160,3 +160,24 @@ EmbeddingResponse embeddingResponse = this.embeddingModel
.embedForResponse(List.of("Hello World", "World is big and salvation is near"));
----
=== Load credentials from a Google Service Account
To programmatically load the GoogleCredentials from a Service Account json file, you can use the following:
[source,java]
----
GoogleCredentials credentials = GoogleCredentials.fromStream(<INPUT_STREAM_TO_CREDENTIALS_JSON>)
.createScoped("https://www.googleapis.com/auth/cloud-platform");
credentials.refreshIfExpired();
VertexAiEmbeddingConnectionDetails connectionDetails =
VertexAiEmbeddingConnectionDetails.builder()
.withProjectId(System.getenv(<VERTEX_AI_GEMINI_PROJECT_ID>))
.withLocation(System.getenv(<VERTEX_AI_GEMINI_LOCATION>))
.withApiEndpoint(endpoint)
.withPredictionServiceSettings(
PredictionServiceSettings.newBuilder()
.setEndpoint(endpoint)
.setCredentialsProvider(FixedCredentialsProvider.create(credentials))
.build());
----