Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
----