Abstract API for AI model clients

* An abstract API for AI model clients
 * Providing portable client request options while still allowing vendor specific options when required.  Implemented only for StabilityAI/OpenAI ImageClient
 * Support for text->image for openai and stabilityai.

  Partial fix for #27 :  Text To Image and Fixes #266 and Fixes #261
This commit is contained in:
Mark Pollack
2024-01-15 00:06:24 -05:00
committed by Christian Tzolov
parent 08fa0e393c
commit 243cef976c
162 changed files with 3691 additions and 630 deletions

View File

@@ -56,7 +56,7 @@ public class ResourceCacheService {
private List<String> excludedUriSchemas = new ArrayList<>(List.of("file", "classpath"));
public ResourceCacheService() {
this(new File(System.getProperty("java.io.tmpdir"), "spring-ai-onnx-model").getAbsolutePath());
this(new File(System.getProperty("java.io.tmpdir"), "spring-ai-onnx-generative").getAbsolutePath());
}
public ResourceCacheService(String rootCacheDirectory) {

View File

@@ -41,10 +41,10 @@ public class TransformersEmbeddingClient extends AbstractEmbeddingClient impleme
private static final Log logger = LogFactory.getLog(TransformersEmbeddingClient.class);
// ONNX tokenizer for the all-MiniLM-L6-v2 model
// ONNX tokenizer for the all-MiniLM-L6-v2 generative
public final static String DEFAULT_ONNX_TOKENIZER_URI = "https://raw.githubusercontent.com/spring-projects/spring-ai/main/models/spring-ai-transformers/src/main/resources/onnx/all-MiniLM-L6-v2/tokenizer.json";
// ONNX model for all-MiniLM-L6-v2 pre-trained transformer:
// ONNX generative for all-MiniLM-L6-v2 pre-trained transformer:
// https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2
public final static String DEFAULT_ONNX_MODEL_URI = "https://github.com/spring-projects/spring-ai/raw/main/models/spring-ai-transformers/src/main/resources/onnx/all-MiniLM-L6-v2/model.onnx";
@@ -70,7 +70,7 @@ public class TransformersEmbeddingClient extends AbstractEmbeddingClient impleme
private OrtEnvironment environment;
/**
* Runtime session that wraps the ONNX model and enables inference calls.
* Runtime session that wraps the ONNX generative and enables inference calls.
*/
private OrtSession session;
@@ -181,7 +181,7 @@ public class TransformersEmbeddingClient extends AbstractEmbeddingClient impleme
logger.info("Model output names: " + onnxModelOutputs.stream().collect(Collectors.joining(", ")));
Assert.isTrue(onnxModelOutputs.contains(this.modelOutputName),
"The model output names doesn't contain expected: " + this.modelOutputName);
"The generative output names doesn't contain expected: " + this.modelOutputName);
}
private Resource getCachedResource(Resource resource) {

View File

@@ -58,7 +58,7 @@ public class ONNXSample {
public static void main(String[] args) throws Exception {
String TOKENIZER_URI = "classpath:/onnx/tokenizer.json";
String MODEL_URI = "classpath:/onnx/model.onnx";
String MODEL_URI = "classpath:/onnx/generative.onnx";
var tokenizerResource = new DefaultResourceLoader().getResource(TOKENIZER_URI);
var modelResource = new DefaultResourceLoader().getResource(MODEL_URI);