Skip to content

Commit b3e7efd

Browse files
garethjevanstzolov
authored andcommitted
feat: allow vertex embedding connection settings to be configurable
1 parent 382fbac commit b3e7efd

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/VertexAiEmbeddingConnectionDetails.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,14 @@ public class VertexAiEmbeddingConnectionDetails {
5858

5959
private final String publisher;
6060

61-
private PredictionServiceSettings predictionServiceSettings;
61+
private final PredictionServiceSettings predictionServiceSettings;
6262

63-
public VertexAiEmbeddingConnectionDetails(String endpoint, String projectId, String location, String publisher) {
63+
public VertexAiEmbeddingConnectionDetails(String projectId, String location, String publisher,
64+
PredictionServiceSettings predictionServiceSettings) {
6465
this.projectId = projectId;
6566
this.location = location;
6667
this.publisher = publisher;
67-
68-
try {
69-
this.predictionServiceSettings = PredictionServiceSettings.newBuilder().setEndpoint(endpoint).build();
70-
}
71-
catch (IOException e) {
72-
throw new RuntimeException(e);
73-
}
68+
this.predictionServiceSettings = predictionServiceSettings;
7469
}
7570

7671
public static Builder builder() {
@@ -125,6 +120,11 @@ public static class Builder {
125120
*/
126121
private String publisher;
127122

123+
/**
124+
* Allows the connection settings to be customised
125+
*/
126+
private PredictionServiceSettings predictionServiceSettings;
127+
128128
public Builder withApiEndpoint(String endpoint) {
129129
this.endpoint = endpoint;
130130
return this;
@@ -145,6 +145,11 @@ public Builder withPublisher(String publisher) {
145145
return this;
146146
}
147147

148+
public Builder withPredictionServiceSettings(PredictionServiceSettings predictionServiceSettings) {
149+
this.predictionServiceSettings = predictionServiceSettings;
150+
return this;
151+
}
152+
148153
public VertexAiEmbeddingConnectionDetails build() {
149154
if (!StringUtils.hasText(this.endpoint)) {
150155
if (!StringUtils.hasText(this.location)) {
@@ -160,7 +165,19 @@ public VertexAiEmbeddingConnectionDetails build() {
160165
this.publisher = DEFAULT_PUBLISHER;
161166
}
162167

163-
return new VertexAiEmbeddingConnectionDetails(this.endpoint, this.projectId, this.location, this.publisher);
168+
if (this.predictionServiceSettings == null) {
169+
try {
170+
this.predictionServiceSettings = PredictionServiceSettings.newBuilder()
171+
.setEndpoint(endpoint)
172+
.build();
173+
}
174+
catch (IOException e) {
175+
throw new RuntimeException(e);
176+
}
177+
}
178+
179+
return new VertexAiEmbeddingConnectionDetails(this.projectId, this.location, this.publisher,
180+
this.predictionServiceSettings);
164181
}
165182

166183
}

0 commit comments

Comments
 (0)