From 8c13e2cc092b12865c1e71c280f2295b34444497 Mon Sep 17 00:00:00 2001 From: Gareth Evans Date: Fri, 15 Nov 2024 13:15:43 +0000 Subject: [PATCH] docs: document how to programatically configure vertex embeddings to use a service account --- .../embeddings/vertexai-embeddings-text.adoc | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/vertexai-embeddings-text.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/vertexai-embeddings-text.adoc index 839319c52e5..2e1596f55ed 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/vertexai-embeddings-text.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/vertexai-embeddings-text.adoc @@ -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()) .withLocation(System.getenv()) .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() + .createScoped("https://www.googleapis.com/auth/cloud-platform"); +credentials.refreshIfExpired(); + +VertexAiEmbeddingConnectionDetails connectionDetails = + VertexAiEmbeddingConnectionDetails.builder() + .withProjectId(System.getenv()) + .withLocation(System.getenv()) + .withApiEndpoint(endpoint) + .withPredictionServiceSettings( + PredictionServiceSettings.newBuilder() + .setEndpoint(endpoint) + .setCredentialsProvider(FixedCredentialsProvider.create(credentials)) + .build()); +----