Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : upgrade to 1.0.0-M1 #61

Closed
wants to merge 10 commits into from
22 changes: 11 additions & 11 deletions chatbot/chatbot-openai-springai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<properties>
<java.version>17</java.version>
<spotless.version>2.43.0</spotless.version>
<spring-ai.version>1.0.0-SNAPSHOT</spring-ai.version>
<spring-ai.version>1.0.0-M1</spring-ai.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -122,22 +122,22 @@

<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<releases>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</releases>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<releases>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</releases>
</snapshots>
</pluginRepository>
</pluginRepositories>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ spring.ai.openai.base-url=http://langchain4j.dev/demo/openai
spring.ai.openai.chat.options.model=gpt-3.5-turbo
spring.ai.openai.chat.options.temperature=0.7

spring.ai.vectorstore.milvus.collectionName=SpringAiCollection

spring.ai.openai.embedding.enabled=true

spring.testcontainers.beans.startup=parallel
8 changes: 4 additions & 4 deletions embeddingstores/neo4j-springai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>21</java.version>
<spring-ai.version>0.8.1</spring-ai.version>
<spring-ai.version>1.0.0-M1</spring-ai.version>
<spotless.version>2.43.0</spotless.version>
</properties>

Expand Down Expand Up @@ -57,8 +57,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -98,7 +98,7 @@
<configuration>
<java>
<palantirJavaFormat>
<version>2.40.0</version>
<version>2.47.0</version>
</palantirJavaFormat>
<importOrder />
<removeUnusedImports />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Neo4jVectorEmbeddingStoreExample {
class Neo4jVectorEmbeddingStoreExample {

public static void main(String[] args) {
SpringApplication.run(Neo4jVectorEmbeddingStoreExample.class, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.springframework.stereotype.Component;

@Component
public class Initializer implements CommandLineRunner {
class Initializer implements CommandLineRunner {

private final Neo4jVectorStoreService neo4jVectorStoreService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.ai.openai.api-key", havingValue = "demo")
public class ResponseHeadersModification {
class ResponseHeadersModification {

@Bean
RestClient.Builder restClientBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

@Configuration(proxyBeanMethods = false)
@OpenAPIDefinition(info = @Info(title = "pgvector-springai", version = "v1.0.0"), servers = @Server(url = "/"))
public class SwaggerConfig {}
class SwaggerConfig {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@RestController
@RequestMapping("/api/ai")
public class QueryController {
class QueryController {

private final Neo4jVectorStoreService neo4jVectorStoreService;

Expand Down
33 changes: 29 additions & 4 deletions embeddingstores/pgvector-springai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<spring-ai.version>0.8.1</spring-ai.version>
<java.version>21</java.version>
<spring-ai.version>1.0.0-M1</spring-ai.version>

<spotless.version>2.43.0</spotless.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -56,8 +58,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -90,6 +92,29 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version>
<configuration>
<java>
<palantirJavaFormat>
<version>2.47.0</version>
</palantirJavaFormat>
<importOrder />
<removeUnusedImports />
<formatAnnotations />
</java>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.springframework.stereotype.Component;

@Component
public class Initializer implements CommandLineRunner {
class Initializer implements CommandLineRunner {

private final PgVectorStoreService pgVectorStoreService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.ai.openai.api-key", havingValue = "demo")
public class ResponseHeadersModification {
class ResponseHeadersModification {

@Bean
RestClient.Builder restClientBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

@Configuration(proxyBeanMethods = false)
@OpenAPIDefinition(info = @Info(title = "pgvector-springai", version = "v1.0.0"), servers = @Server(url = "/"))
public class SwaggerConfig {}
class SwaggerConfig {}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@RestController
@RequestMapping("/api/ai")
public class QueryController {
class QueryController {

private final PgVectorStoreService pgVectorStoreService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.containsStringIgnoringCase;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;

Expand Down Expand Up @@ -70,7 +71,7 @@ void testRag() {
.post("/api/ai/chat")
.then()
.statusCode(200)
.body("queryResponse", containsString("yes"))
.body("queryResponse", containsStringIgnoringCase("yes"))
.log()
.all();
}
Expand All @@ -84,7 +85,7 @@ void testRag2() {
.post("/api/ai/chat")
.then()
.statusCode(200)
.body("queryResponse", containsString("No"))
.body("queryResponse", containsStringIgnoringCase("No"))
.log()
.all();
}
Expand Down
2 changes: 1 addition & 1 deletion rag/rag-springai-openai-llm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<properties>
<java.version>21</java.version>
<spring-ai.version>0.8.1</spring-ai.version>
<spring-ai.version>1.0.0-M1</spring-ai.version>
<spotless.version>2.43.0</spotless.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class LlmRagWithSpringAiApplication {
class LlmRagWithSpringAiApplication {

public static void main(String[] args) {
SpringApplication.run(LlmRagWithSpringAiApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.springframework.jdbc.core.JdbcTemplate;

@Configuration(proxyBeanMethods = false)
public class AppConfig {
class AppConfig {
private static final Logger log = LoggerFactory.getLogger(AppConfig.class);

@Value("classpath:Rohit_Gurunath_Sharma.docx")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.context.annotation.Description;

@Configuration(proxyBeanMethods = false)
public class FunctionConfiguration {
class FunctionConfiguration {

private static final Logger log = LoggerFactory.getLogger(FunctionConfiguration.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

@Order(Ordered.HIGHEST_PRECEDENCE)
@ControllerAdvice
public class GlobalExceptionHandler {
class GlobalExceptionHandler {

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.ai.openai.api-key", havingValue = "demo")
public class ResponseHeadersModification {
class ResponseHeadersModification {

private static final Logger LOGGER = LoggerFactory.getLogger(ResponseHeadersModification.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

@Configuration(proxyBeanMethods = false)
@OpenAPIDefinition(info = @Info(title = "rag-springai-openai-llm", version = "v1.0.0"), servers = @Server(url = "/"))
public class SwaggerConfig {}
class SwaggerConfig {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@RestController
@RequestMapping("/api/ai")
@Validated
public class AiController {
class AiController {

private final AIChatService aiChatService;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.learning.ai.llmragwithspringai.service;

import static org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor.CHAT_MEMORY_RETRIEVE_SIZE_KEY;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.ai.chat.ChatClient;
import org.springframework.ai.chat.ChatResponse;
import org.springframework.ai.chat.Generation;
import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.chat.prompt.SystemPromptTemplate;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.PromptChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.QuestionAnswerAdvisor;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.model.Generation;
import org.springframework.ai.document.Document;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -40,8 +40,15 @@ with one player from the fielding team (the bowler) bowling the ball towards the
private final ChatClient aiClient;
private final VectorStore vectorStore;

public AIChatService(ChatClient aiClient, VectorStore vectorStore) {
this.aiClient = aiClient;
public AIChatService(ChatClient.Builder modelBuilder, VectorStore vectorStore) {
this.aiClient = modelBuilder
.defaultSystem(template)
.defaultAdvisors(
new PromptChatMemoryAdvisor(new InMemoryChatMemory()),
// new MessageChatMemoryAdvisor(chatMemory), // CHAT MEMORY
new QuestionAnswerAdvisor(vectorStore, SearchRequest.defaults())) // RAG
.defaultFunctions("currentDateFunction") // FUNCTION CALLING
.build();
this.vectorStore = vectorStore;
}

Expand All @@ -53,12 +60,12 @@ public String chat(String searchQuery) {
.collect(Collectors.joining(System.lineSeparator()));
// Constructing the systemMessage to indicate the AI model to use the passed information
// to answer the question.
Message systemMessage = new SystemPromptTemplate(template).createMessage(Map.of("documents", documents));
UserMessage userMessage = new UserMessage(searchQuery);
OpenAiChatOptions chatOptions =
OpenAiChatOptions.builder().withFunction("currentDateFunction").build();
Prompt prompt = new Prompt(List.of(systemMessage, userMessage), chatOptions);
ChatResponse aiResponse = aiClient.call(prompt);
ChatResponse aiResponse = aiClient.prompt()
.system(sp -> sp.param("documents", documents))
.user(searchQuery)
.advisors(a -> a.param(CHAT_MEMORY_RETRIEVE_SIZE_KEY, 100))
.call()
.chatResponse();
Generation generation = aiResponse.getResult();
return (generation != null) ? generation.getOutput().getContent() : "";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
spring.datasource.password=secret
spring.datasource.username=appuser
spring.datasource.url=jdbc:postgresql://localhost/appdb

# default value of openai is 1536
spring.ai.vectorstore.pgvector.dimensions=384
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ spring.ai.openai.chat.options.model=gpt-3.5-turbo
spring.ai.openai.chat.options.temperature=0.2
spring.ai.openai.chat.options.responseFormat=json_object

spring.ai.openai.embedding.options.model=text-embedding-ada-002

#spring.ai.openai.image.model=dall-e-3
Loading