-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(deps) : upgrade to milestone 1.0.0-M1 (#60)
* 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
1 parent
143ae37
commit 1f45d8d
Showing
19 changed files
with
124 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 |
79 changes: 0 additions & 79 deletions
79
chatbot-ollama-springai/src/main/java/com/example/chatbot/config/ChatConfig.java
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
chatbot-ollama-springai/src/main/java/com/example/chatbot/service/ChatbotService.java
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
31 changes: 31 additions & 0 deletions
31
chatbot/chatbot-ollama-springai/src/main/java/com/example/chatbot/config/ChatConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions
37
...bot/chatbot-ollama-springai/src/main/java/com/example/chatbot/service/ChatbotService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.