Skip to content

Commit

Permalink
chore(deps) : upgrade to milestone 1.0.0-M1 (#60)
Browse files Browse the repository at this point in the history
* chore(deps) : upgrade to milestone

* fix : update use case

* feat : adds advisors

* fix : compilation issue

* fix service

* feat : adds docker compose

* tweak chat question
  • Loading branch information
rajadilipkolli authored Jun 13, 2024
1 parent 143ae37 commit 1f45d8d
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 158 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/chatbot-ollama-springai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ name: chatbot-ollama-springai CI Build
on:
push:
paths:
- "chatbot-ollama-springai/**"
- "chatbot/chatbot-ollama-springai/**"
branches: [main]
pull_request:
paths:
- "chatbot-ollama-springai/**"
- "chatbot/chatbot-ollama-springai/**"
types:
- opened
- synchronize
Expand All @@ -19,10 +19,9 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: chatbot-ollama-springai
working-directory: chatbot/chatbot-ollama-springai
strategy:
matrix:
distribution: [ 'temurin' ]
java: [ '21' ]
steps:
- uses: actions/checkout@v4
Expand All @@ -33,7 +32,7 @@ jobs:
uses: actions/[email protected]
with:
java-version: ${{ matrix.java }}
distribution: ${{ matrix.distribution }}
distribution: temurin
cache: 'maven'
- name: Build and analyze
run: ./mvnw clean verify

This file was deleted.

This file was deleted.

File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions chatbot/chatbot-ollama-springai/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.7'
services:
chroma:
container_name: chroma
image: chromadb/chroma:0.5.0
extra_hosts: [ 'host.docker.internal:host-gateway' ]
restart: always
ports:
- "8000:8000"
healthcheck:
# Adjust below to match your container port
test: [ "CMD", "curl", "-f", "http://localhost:8000/api/v1/heartbeat" ]
interval: 30s
timeout: 10s
retries: 3
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<properties>
<java.version>21</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 @@ -90,50 +90,50 @@
<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>
<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>

<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
@@ -0,0 +1,31 @@
package com.example.chatbot.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.QuestionAnswerAdvisor;
import org.springframework.ai.chat.client.advisor.VectorStoreChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
public class ChatConfig {

@Bean
ChatMemory chatMemory() {
return new InMemoryChatMemory();
}

@Bean
ChatClient chatClient(ChatClient.Builder chatClientBuilder, ChatMemory chatMemory, VectorStore vectorStore) {
return chatClientBuilder
.defaultAdvisors(
new MessageChatMemoryAdvisor(chatMemory),
new QuestionAnswerAdvisor(vectorStore, SearchRequest.defaults()), // RAG
new VectorStoreChatMemoryAdvisor(vectorStore))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example.chatbot.service;

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

import com.example.chatbot.model.request.AIChatRequest;
import com.example.chatbot.model.response.AIChatResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.stereotype.Service;

@Service
public class ChatbotService {

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

private final ChatClient chatClient;

public ChatbotService(ChatClient chatClient) {
this.chatClient = chatClient;
}

public AIChatResponse chat(AIChatRequest request) {

ChatResponse chatResponse = this.chatClient
.prompt()
.user(request.query())
.advisors(a -> a.param(CHAT_MEMORY_CONVERSATION_ID_KEY, request.conversationId())
.param(CHAT_MEMORY_RETRIEVE_SIZE_KEY, 100))
.call()
.chatResponse();
LOGGER.info("Response :{}", chatResponse.getResult());
return new AIChatResponse(chatResponse.getResult().getOutput().getContent(), request.conversationId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void chat() throws StreamReadException, DatabindException, IOException {
Response response = given().contentType(ContentType.JSON)
.body(new AIChatRequest(
"As a cricketer, how many centuries did Sachin Tendulkar scored adding up both One Day International (ODI) and Test centuries ?",
null))
"junit1"))
.when()
.post("/api/ai/chat")
.then()
Expand All @@ -56,18 +56,15 @@ void chat() throws StreamReadException, DatabindException, IOException {
.response();

AIChatResponse aiChatResponse = objectMapper.readValue(response.asByteArray(), AIChatResponse.class);
System.out.println("conversationalId :: " + aiChatResponse.conversationId());

given().contentType(ContentType.JSON)
.body(new AIChatRequest(
"How many One Day International (ODI) centuries did he scored ?",
aiChatResponse.conversationId()))
.body(new AIChatRequest("Who scored 100 centuries ?", aiChatResponse.conversationId()))
.when()
.post("/api/ai/chat")
.then()
.statusCode(HttpStatus.SC_OK)
.contentType(ContentType.JSON)
.body("answer", containsString("49"))
.body("answer", containsString("Sachin"))
.log()
.all(true);
}
Expand Down

0 comments on commit 1f45d8d

Please sign in to comment.