Add vertex ai autoconfig and spring boot
- Add Vertex AI Autoconfigurations for chat and embedding clients. - Factor out the embeding client dimensions() computation into an abstract parent AbstractEmbeddingClient. - Add ITs - Vertex dos.
This commit is contained in:
@@ -5,7 +5,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import ai.djl.huggingface.tokenizers.Encoding;
|
||||
@@ -35,7 +34,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Christian Tzolov
|
||||
*/
|
||||
public class TransformersEmbeddingClient implements EmbeddingClient, InitializingBean {
|
||||
public class TransformersEmbeddingClient extends AbstractEmbeddingClient implements InitializingBean {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TransformersEmbeddingClient.class);
|
||||
|
||||
@@ -72,8 +71,6 @@ public class TransformersEmbeddingClient implements EmbeddingClient, Initializin
|
||||
*/
|
||||
private OrtSession session;
|
||||
|
||||
private final AtomicInteger embeddingDimensions = new AtomicInteger(-1);
|
||||
|
||||
/**
|
||||
* Specifies what parts of the {@link Document}'s content and metadata will be used
|
||||
* for computing the embeddings. Applicable for the {@link #embed(Document)} method
|
||||
@@ -148,10 +145,6 @@ public class TransformersEmbeddingClient implements EmbeddingClient, Initializin
|
||||
this.modelResource = toResource(modelResourceUri);
|
||||
}
|
||||
|
||||
public void setEmbeddingDimensions(int dimension) {
|
||||
this.embeddingDimensions.set(dimension);
|
||||
}
|
||||
|
||||
public void setModelOutputName(String modelOutputName) {
|
||||
this.modelOutputName = modelOutputName;
|
||||
}
|
||||
@@ -325,14 +318,6 @@ public class TransformersEmbeddingClient implements EmbeddingClient, Initializin
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int dimensions() {
|
||||
if (this.embeddingDimensions.get() < 0) {
|
||||
this.embeddingDimensions.set(EmbeddingUtil.dimensions(this, "Test"));
|
||||
}
|
||||
return this.embeddingDimensions.get();
|
||||
}
|
||||
|
||||
private static Resource toResource(String uri) {
|
||||
return new DefaultResourceLoader().getResource(uri);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user