Skip to content

Commit

Permalink
Update to last snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasVitale committed Dec 14, 2024
1 parent f47aa7d commit e097ed0
Show file tree
Hide file tree
Showing 48 changed files with 399 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SearchController {
List<Document> searchSimilarDocuments(@RequestBody String query) {
var documents = vectorStore.similaritySearch(query);
return documents.stream()
.map(document -> new Document(document.getId(), document.getContent(), document.getMedia(), document.getMetadata()))
.map(document -> document.mutate().build())
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SearchController {
List<Document> searchSimilarDocuments(@RequestBody String query) {
var documents = vectorStore.similaritySearch(query);
return documents.stream()
.map(document -> new Document(document.getId(), document.getContent(), document.getMedia(), document.getMetadata()))
.map(document -> document.mutate().build())
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SearchController {
List<Document> searchSimilarDocuments(@RequestBody String query) {
var documents = vectorStore.similaritySearch(query);
return documents.stream()
.map(document -> new Document(document.getId(), document.getContent(), document.getMedia(), document.getMetadata()))
.map(document -> document.mutate().build())
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SearchController {
List<Document> searchSimilarDocuments(@RequestBody String query) {
var documents = vectorStore.similaritySearch(query);
return documents.stream()
.map(document -> new Document(document.getId(), document.getContent(), document.getMedia(), document.getMetadata()))
.map(document -> document.mutate().build())
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SearchController {
List<Document> searchSimilarDocuments(@RequestBody String query) {
var documents = vectorStore.similaritySearch(query);
return documents.stream()
.map(document -> new Document(document.getId(), document.getContent(), document.getMedia(), document.getMetadata()))
.map(document -> document.mutate().build())
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SearchController {
List<Document> searchSimilarDocuments(@RequestBody String query) {
var documents = vectorStore.similaritySearch(query);
return documents.stream()
.map(document -> new Document(document.getId(), document.getContent(), document.getMedia(), document.getMetadata()))
.map(document -> document.mutate().build())
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SearchController {
List<Document> searchSimilarDocuments(@RequestBody String query) {
var documents = vectorStore.similaritySearch(query);
return documents.stream()
.map(document -> new Document(document.getId(), document.getContent(), document.getMedia(), document.getMetadata()))
.map(document -> document.mutate().build())
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.thomasvitale.ai.spring;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.mistralai.MistralAiChatOptions;
import org.springframework.ai.mistralai.api.MistralAiApi;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -32,9 +32,9 @@ String chat(String question) {
String chatGenericOptions(String question) {
return chatClient
.prompt(question)
.options(ChatOptionsBuilder.builder()
.withModel(MistralAiApi.ChatModel.OPEN_MIXTRAL_7B.getName())
.withTemperature(0.9)
.options(ChatOptions.builder()
.model(MistralAiApi.ChatModel.OPEN_MIXTRAL_7B.getName())
.temperature(0.9)
.build())
.call()
.content();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.thomasvitale.ai.spring.model;

import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.mistralai.MistralAiChatOptions;
import org.springframework.ai.mistralai.api.MistralAiApi;
Expand Down Expand Up @@ -30,19 +30,19 @@ String chat(String question) {

@GetMapping("/chat/generic-options")
String chatGenericOptions(String question) {
return chatModel.call(new Prompt(question, ChatOptionsBuilder.builder()
.withModel(MistralAiApi.ChatModel.OPEN_MIXTRAL_7B.getName())
.withTemperature(0.9)
return chatModel.call(new Prompt(question, ChatOptions.builder()
.model(MistralAiApi.ChatModel.OPEN_MIXTRAL_7B.getName())
.temperature(0.9)
.build()))
.getResult().getOutput().getContent();
.getResult().getOutput().getText();
}

@GetMapping("/chat/provider-options")
String chatProviderOptions(String question) {
return chatModel.call(new Prompt(question, MistralAiChatOptions.builder()
.withSafePrompt(true)
.build()))
.getResult().getOutput().getContent();
.getResult().getOutput().getText();
}

@GetMapping("/chat/stream")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ String chatMistralAiOptions(String question) {
.withModel(MistralAiApi.ChatModel.OPEN_MIXTRAL_7B.getValue())
.withTemperature(1.0)
.build()))
.getResult().getOutput().getContent();
.getResult().getOutput().getText();
}

@GetMapping("/chat/openai-options")
Expand All @@ -51,7 +51,7 @@ String chatOpenAiOptions(String question) {
.withModel(OpenAiApi.ChatModel.GPT_4_O_MINI.getValue())
.withTemperature(1.0)
.build()))
.getResult().getOutput().getContent();
.getResult().getOutput().getText();
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.thomasvitale.ai.spring;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.ollama.api.OllamaOptions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -31,9 +31,9 @@ String chat(String question) {
String chatGenericOptions(String question) {
return chatClient
.prompt(question)
.options(ChatOptionsBuilder.builder()
.withModel("llama3.2:1b")
.withTemperature(0.9)
.options(ChatOptions.builder()
.model("llama3.2:1b")
.temperature(0.9)
.build())
.call()
.content();
Expand All @@ -54,8 +54,8 @@ String chatProviderOptions(String question) {
String chatHuggingFace(String question) {
return chatClient
.prompt(question)
.options(ChatOptionsBuilder.builder()
.withModel("hf.co/SanctumAI/Llama-3.2-1B-Instruct-GGUF")
.options(ChatOptions.builder()
.model("hf.co/SanctumAI/Llama-3.2-1B-Instruct-GGUF")
.build())
.call()
.content();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.thomasvitale.ai.spring.model;

import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.ollama.api.OllamaOptions;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -29,27 +29,27 @@ String chat(String question) {

@GetMapping("/chat/generic-options")
String chatGenericOptions(String question) {
return chatModel.call(new Prompt(question, ChatOptionsBuilder.builder()
.withModel("llama3.2:1b")
.withTemperature(0.9)
return chatModel.call(new Prompt(question, ChatOptions.builder()
.model("llama3.2:1b")
.temperature(0.9)
.build()))
.getResult().getOutput().getContent();
.getResult().getOutput().getText();
}

@GetMapping("/chat/provider-options")
String chatProviderOptions(String question) {
return chatModel.call(new Prompt(question, OllamaOptions.builder()
.withRepeatPenalty(1.5)
.build()))
.getResult().getOutput().getContent();
.getResult().getOutput().getText();
}

@GetMapping("/chat/huggingface")
String chatHuggingFace(String question) {
return chatModel.call(new Prompt(question, ChatOptionsBuilder.builder()
.withModel("hf.co/SanctumAI/Llama-3.2-1B-Instruct-GGUF")
return chatModel.call(new Prompt(question, ChatOptions.builder()
.model("hf.co/SanctumAI/Llama-3.2-1B-Instruct-GGUF")
.build()))
.getResult().getOutput().getContent();
.getResult().getOutput().getText();
}

@GetMapping("/chat/stream")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.thomasvitale.ai.spring;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -32,9 +32,9 @@ String chat(String question) {
String chatGenericOptions(String question) {
return chatClient
.prompt(question)
.options(ChatOptionsBuilder.builder()
.withModel(OpenAiApi.ChatModel.GPT_4_O_MINI.getValue())
.withTemperature(0.9)
.options(ChatOptions.builder()
.model(OpenAiApi.ChatModel.GPT_4_O_MINI.getValue())
.temperature(0.9)
.build())
.call()
.content();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.thomasvitale.ai.spring.model;

import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
Expand Down Expand Up @@ -30,19 +30,19 @@ String chat(String question) {

@GetMapping("/chat/generic-options")
String chatGenericOptions(String question) {
return chatModel.call(new Prompt(question, ChatOptionsBuilder.builder()
.withModel(OpenAiApi.ChatModel.GPT_4_O_MINI.getValue())
.withTemperature(0.9)
return chatModel.call(new Prompt(question, ChatOptions.builder()
.model(OpenAiApi.ChatModel.GPT_4_O_MINI.getValue())
.temperature(0.9)
.build()))
.getResult().getOutput().getContent();
.getResult().getOutput().getText();
}

@GetMapping("/chat/provider-options")
String chatProviderOptions(String question) {
return chatModel.call(new Prompt(question, OpenAiChatOptions.builder()
.withLogprobs(true)
.build()))
.getResult().getOutput().getContent();
.getResult().getOutput().getText();
}

@GetMapping("/chat/stream")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.mistralai.MistralAiChatOptions;
import org.springframework.ai.mistralai.api.MistralAiApi;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -18,7 +18,7 @@ class ChatController {
private final ChatClient chatClient;

ChatController(ChatClient.Builder chatClientBuilder) {
this.chatClient = chatClientBuilder.build();
this.chatClient = chatClientBuilder.clone().build();
}

@GetMapping("/chat")
Expand All @@ -35,9 +35,9 @@ String chatGenericOptions(String question) {
logger.info("Chatting with generic options: {}", question);
return chatClient
.prompt(question)
.options(ChatOptionsBuilder.builder()
.withModel(MistralAiApi.ChatModel.OPEN_MIXTRAL_7B.getName())
.withTemperature(0.9)
.options(ChatOptions.builder()
.model(MistralAiApi.ChatModel.OPEN_MIXTRAL_7B.getName())
.temperature(0.9)
.build())
.call()
.content();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.ollama.api.OllamaOptions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -17,7 +17,7 @@ class ChatController {
private final ChatClient chatClient;

ChatController(ChatClient.Builder chatClientBuilder) {
this.chatClient = chatClientBuilder.build();
this.chatClient = chatClientBuilder.clone().build();
}

@GetMapping("/chat")
Expand All @@ -34,9 +34,9 @@ String chatGenericOptions(String question) {
logger.info("Chatting with generic options: {}", question);
return chatClient
.prompt(question)
.options(ChatOptionsBuilder.builder()
.withModel("llama3.2:1b")
.withTemperature(0.9)
.options(ChatOptions.builder()
.model("llama3.2:1b")
.temperature(0.9)
.build())
.call()
.content();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -18,7 +18,7 @@ class ChatController {
private final ChatClient chatClient;

ChatController(ChatClient.Builder chatClientBuilder) {
this.chatClient = chatClientBuilder.build();
this.chatClient = chatClientBuilder.clone().build();
}

@GetMapping("/chat")
Expand All @@ -35,9 +35,9 @@ String chatGenericOptions(String question) {
logger.info("Chatting with generic options: {}", question);
return chatClient
.prompt(question)
.options(ChatOptionsBuilder.builder()
.withModel(OpenAiApi.ChatModel.GPT_4_O_MINI.getValue())
.withTemperature(0.9)
.options(ChatOptions.builder()
.model(OpenAiApi.ChatModel.GPT_4_O_MINI.getValue())
.temperature(0.9)
.build())
.call()
.content();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ChatController {
private final RetrievalAugmentationAdvisor retrievalAugmentationAdvisor;

ChatController(ChatClient.Builder chatClientBuilder, VectorStore vectorStore) {
this.chatClient = chatClientBuilder.build();
this.chatClient = chatClientBuilder.clone().build();
this.retrievalAugmentationAdvisor = RetrievalAugmentationAdvisor.builder()
.documentRetriever(VectorStoreDocumentRetriever.builder()
.vectorStore(vectorStore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ String chatVariant(String authorName) {
)
.functions(
FunctionCallback.builder()
.description("Get the list of books written by the given author available in the library")
.responseConverter(Object::toString)
.function("BooksByAuthor", bookService::getBooksByAuthor)
.description("Get the list of books written by the given author available in the library")
.inputType(BookService.Author.class)
.responseConverter(Object::toString)
.build()
)
.call()
Expand Down
Loading

0 comments on commit e097ed0

Please sign in to comment.