Skip to content

Commit

Permalink
Update to latest snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasVitale committed Dec 20, 2024
1 parent 01b95d1 commit 190ef46
Show file tree
Hide file tree
Showing 29 changed files with 47 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void main(String[] args) {

@Bean
VectorStore vectorStore(EmbeddingModel embeddingModel) {
return new SimpleVectorStore(embeddingModel);
return SimpleVectorStore.builder(embeddingModel).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void main(String[] args) {

@Bean
VectorStore vectorStore(EmbeddingModel embeddingModel) {
return new SimpleVectorStore(embeddingModel);
return SimpleVectorStore.builder(embeddingModel).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void main(String[] args) {

@Bean
VectorStore vectorStore(EmbeddingModel embeddingModel) {
return new SimpleVectorStore(embeddingModel);
return SimpleVectorStore.builder(embeddingModel).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void main(String[] args) {

@Bean
VectorStore vectorStore(EmbeddingModel embeddingModel) {
return new SimpleVectorStore(embeddingModel);
return SimpleVectorStore.builder(embeddingModel).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void main(String[] args) {

@Bean
VectorStore vectorStore(EmbeddingModel embeddingModel) {
return new SimpleVectorStore(embeddingModel);
return SimpleVectorStore.builder(embeddingModel).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void main(String[] args) {

@Bean
VectorStore vectorStore(EmbeddingModel embeddingModel) {
return new SimpleVectorStore(embeddingModel);
return SimpleVectorStore.builder(embeddingModel).build();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void main(String[] args) {

@Bean
VectorStore vectorStore(EmbeddingModel embeddingModel) {
return new SimpleVectorStore(embeddingModel);
return SimpleVectorStore.builder(embeddingModel).build();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ String speech(@Value("classpath:speech1.mp3") Resource audioFile) {
@GetMapping("/transcription/provider-options")
String speechProviderOptions(@Value("classpath:speech2.mp3") Resource audioFile) {
var transcriptionResponse = transcriptionModel.call(new AudioTranscriptionPrompt(audioFile, OpenAiAudioTranscriptionOptions.builder()
.withLanguage("en")
.withPrompt("Ask not this, but ask that")
.withTemperature(0f)
.withResponseFormat(OpenAiAudioApi.TranscriptResponseFormat.VTT)
.language("en")
.prompt("Ask not this, but ask that")
.temperature(0f)
.responseFormat(OpenAiAudioApi.TranscriptResponseFormat.VTT)
.build()));
return transcriptionResponse.getResult().getOutput();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ byte[] speech(String message) {
@GetMapping("/speech/provider-options")
byte[] speechProviderOptions(String message) {
var speechResponse = speechModel.call(new SpeechPrompt(message, OpenAiAudioSpeechOptions.builder()
.withModel("tts-1")
.withVoice(OpenAiAudioApi.SpeechRequest.Voice.ALLOY)
.withResponseFormat(OpenAiAudioApi.SpeechRequest.AudioResponseFormat.MP3)
.withSpeed(1.0f)
.model("tts-1")
.voice(OpenAiAudioApi.SpeechRequest.Voice.ALLOY)
.responseFormat(OpenAiAudioApi.SpeechRequest.AudioResponseFormat.MP3)
.speed(1.0f)
.build()));
return speechResponse.getResult().getOutput();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ String chatProviderOptions(String question) {
return chatClient
.prompt(question)
.options(MistralAiChatOptions.builder()
.withSafePrompt(true)
.safePrompt(true)
.build())
.call()
.content();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ String chatGenericOptions(String question) {
@GetMapping("/chat/provider-options")
String chatProviderOptions(String question) {
return chatModel.call(new Prompt(question, MistralAiChatOptions.builder()
.withSafePrompt(true)
.safePrompt(true)
.build()))
.getResult().getOutput().getText();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ String chatMistralAiOptions(String question) {
return mistralAichatClient
.prompt(question)
.options(MistralAiChatOptions.builder()
.withModel(MistralAiApi.ChatModel.OPEN_MIXTRAL_7B.getValue())
.withTemperature(1.0)
.model(MistralAiApi.ChatModel.OPEN_MIXTRAL_7B.getValue())
.temperature(1.0)
.build())
.call()
.content();
Expand All @@ -57,8 +57,8 @@ String chatOpenAiOptions(String question) {
return openAichatClient
.prompt(question)
.options(OpenAiChatOptions.builder()
.withModel(OpenAiApi.ChatModel.GPT_4_O_MINI.getValue())
.withTemperature(1.0)
.model(OpenAiApi.ChatModel.GPT_4_O_MINI.getValue())
.temperature(1.0)
.build())
.call()
.content();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ String chatOpenAi(String question) {
@GetMapping("/chat/mistral-ai-options")
String chatMistralAiOptions(String question) {
return mistralAiChatModel.call(new Prompt(question, MistralAiChatOptions.builder()
.withModel(MistralAiApi.ChatModel.OPEN_MIXTRAL_7B.getValue())
.withTemperature(1.0)
.model(MistralAiApi.ChatModel.OPEN_MIXTRAL_7B.getValue())
.temperature(1.0)
.build()))
.getResult().getOutput().getText();
}

@GetMapping("/chat/openai-options")
String chatOpenAiOptions(String question) {
return openAiChatModel.call(new Prompt(question, OpenAiChatOptions.builder()
.withModel(OpenAiApi.ChatModel.GPT_4_O_MINI.getValue())
.withTemperature(1.0)
.model(OpenAiApi.ChatModel.GPT_4_O_MINI.getValue())
.temperature(1.0)
.build()))
.getResult().getOutput().getText();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ String chatProviderOptions(String question) {
return chatClient
.prompt(question)
.options(OllamaOptions.builder()
.withRepeatPenalty(1.5)
.repeatPenalty(1.5)
.build())
.call()
.content();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ String chatProviderOptions(String question) {
return chatClient
.prompt(question)
.options(OpenAiChatOptions.builder()
.withLogprobs(true)
.logprobs(true)
.build())
.call()
.content();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ String chatGenericOptions(String question) {
@GetMapping("/chat/provider-options")
String chatProviderOptions(String question) {
return chatModel.call(new Prompt(question, OpenAiChatOptions.builder()
.withLogprobs(true)
.logprobs(true)
.build()))
.getResult().getOutput().getText();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ String embedGenericOptions(String query) {
@GetMapping("/embed/provider-options")
String embedProviderOptions(String query) {
var embeddings = embeddingModel.call(new EmbeddingRequest(List.of(query), OllamaOptions.builder()
.withLowVRAM(true)
.lowVRAM(true)
.build()))
.getResult().getOutput();
return "Size of the embedding vector: " + embeddings.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ String embedGenericOptions(String query) {
@GetMapping("/embed/provider-options")
String embedProviderOptions(String query) {
var embeddings = embeddingModel.call(new EmbeddingRequest(List.of(query), OpenAiEmbeddingOptions.builder()
.withEncodingFormat("float")
.encodingFormat("float")
.build()))
.getResult().getOutput();
return "Size of the embedding vector: " + embeddings.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class ImageController {
@GetMapping("/image")
String image(String message) {
var imageResponse = imageModel.call(new ImagePrompt(message, ImageOptionsBuilder.builder()
.withHeight(256)
.withWidth(256)
.height(256)
.width(256)
.build()));
return imageResponse.getResult().getOutput().getUrl();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ String chatProviderOptions(String question) {
return chatClient
.prompt(question)
.options(MistralAiChatOptions.builder()
.withSafePrompt(true)
.safePrompt(true)
.build())
.call()
.content();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ String chatProviderOptions(String question) {
return chatClient
.prompt(question)
.options(OllamaOptions.builder()
.withRepeatPenalty(1.5)
.repeatPenalty(1.5)
.build())
.call()
.content();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ String embedGenericOptions(String query) {
String embedProviderOptions(String query) {
logger.info("Embedding query with provider options: {}", query);
var embeddings = embeddingModel.call(new EmbeddingRequest(List.of(query), OllamaOptions.builder()
.withLowVRAM(true)
.lowVRAM(true)
.build()))
.getResult().getOutput();
return "Size of the embedding vector: " + embeddings.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ String chat(String authorName) {
""");
Map<String,Object> model = Map.of("author", authorName);
var prompt = userPromptTemplate.create(model, FunctionCallingOptions.builder()
.withFunctions(Set.of("booksByAuthor"))
.functions(Set.of("booksByAuthor"))
.build());

var chatResponse = chatModel.call(prompt);
Expand All @@ -49,7 +49,7 @@ String chatVariant(String authorName) {
""");
Map<String,Object> model = Map.of("author", authorName);
var prompt = userPromptTemplate.create(model, FunctionCallingOptions.builder()
.withFunctionCallbacks(List.of(
.functionCallbacks(List.of(
FunctionCallback.builder()
.function("BooksByAuthor", bookService::getBooksByAuthor)
.description("Get the list of books written by the given author available in the library")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ String chat(String authorName) {
""");
Map<String,Object> model = Map.of("author", authorName);
var prompt = userPromptTemplate.create(model, FunctionCallingOptions.builder()
.withFunctions(Set.of("booksByAuthor"))
.functions(Set.of("booksByAuthor"))
.build());

var chatResponse = chatModel.call(prompt);
Expand All @@ -49,7 +49,7 @@ String chatVariant(String authorName) {
""");
Map<String,Object> model = Map.of("author", authorName);
var prompt = userPromptTemplate.create(model, FunctionCallingOptions.builder()
.withFunctionCallbacks(List.of(
.functionCallbacks(List.of(
FunctionCallback.builder()
.function("BooksByAuthor", bookService::getBooksByAuthor)
.description("Get the list of books written by the given author available in the library")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ String chat(String authorName) {
""");
Map<String,Object> model = Map.of("author", authorName);
var prompt = userPromptTemplate.create(model, FunctionCallingOptions.builder()
.withFunctions(Set.of("booksByAuthor"))
.functions(Set.of("booksByAuthor"))
.build());

var chatResponse = chatModel.call(prompt);
Expand All @@ -49,7 +49,7 @@ String chatVariant(String authorName) {
""");
Map<String,Object> model = Map.of("author", authorName);
var prompt = userPromptTemplate.create(model, FunctionCallingOptions.builder()
.withFunctionCallbacks(List.of(
.functionCallbacks(List.of(
FunctionCallback.builder()
.function("BooksByAuthor", bookService::getBooksByAuthor)
.description("Get the list of books written by the given author available in the library")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ String chatAudioFile(String question) {
.media(MimeTypeUtils.parseMimeType("audio/mp3"), audio)
)
.options(OpenAiChatOptions.builder()
.withModel(OpenAiApi.ChatModel.GPT_4_O_AUDIO_PREVIEW.getValue())
.model(OpenAiApi.ChatModel.GPT_4_O_AUDIO_PREVIEW.getValue())
.build())
.call()
.content();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ String chatImageUrl(String question) throws MalformedURLException {
String chatAudioFile(String question) {
var userMessage = new UserMessage(question, new Media(MimeTypeUtils.parseMimeType("audio/mp3"), audio));
var prompt = new Prompt(userMessage, OpenAiChatOptions.builder()
.withModel(OpenAiApi.ChatModel.GPT_4_O_AUDIO_PREVIEW.getValue())
.model(OpenAiApi.ChatModel.GPT_4_O_AUDIO_PREVIEW.getValue())
.build());
var chatResponse = chatModel.call(prompt);
return chatResponse.getResult().getOutput().getText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ArtistInfo chatBeanOutput(@RequestBody MusicQuestion question) {
.param("instrument", question.instrument())
)
.options(OpenAiChatOptions.builder()
.withResponseFormat(new ResponseFormat(ResponseFormat.Type.JSON_OBJECT, null))
.responseFormat(new ResponseFormat(ResponseFormat.Type.JSON_OBJECT, null))
.build())
.call()
.entity(ArtistInfo.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ArtistInfo chatBeanOutput(@RequestBody MusicQuestion question) {
"genre", question.genre(),
"format", outputConverter.getFormat());
var prompt = userPromptTemplate.create(model, OpenAiChatOptions.builder()
.withResponseFormat(new ResponseFormat(ResponseFormat.Type.JSON_OBJECT, null))
.responseFormat(new ResponseFormat(ResponseFormat.Type.JSON_OBJECT, null))
.build());

var chatResponse = chatModel.call(prompt);
Expand Down Expand Up @@ -92,8 +92,8 @@ ArtistInfoVariant chatJsonOutput(@RequestBody MusicQuestion question) {
""");
Map<String,Object> model = Map.of("instrument", question.instrument(), "genre", question.genre());
var prompt = userPromptTemplate.create(model, OpenAiChatOptions.builder()
.withModel(OpenAiApi.ChatModel.GPT_4_O.getValue())
.withResponseFormat(new ResponseFormat(ResponseFormat.Type.JSON_SCHEMA, outputConverter.getJsonSchema()))
.model(OpenAiApi.ChatModel.GPT_4_O.getValue())
.responseFormat(new ResponseFormat(ResponseFormat.Type.JSON_SCHEMA, outputConverter.getJsonSchema()))
.build());

var chatResponse = chatModel.call(prompt);
Expand Down

0 comments on commit 190ef46

Please sign in to comment.