-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update modules/ai: add 2 del 1 files
- Loading branch information
1 parent
627f3d4
commit 423c6d2
Showing
4 changed files
with
106 additions
and
24 deletions.
There are no files selected for viewing
23 changes: 0 additions & 23 deletions
23
modules/ai/src/main/java/com/bytedesk/ai/config/SpringAiConfig.java
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
modules/ai/src/main/java/com/bytedesk/ai/springai/CustomerSupportAssistant.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,69 @@ | ||
/* | ||
* @Author: jackning 270580156@qq.com | ||
* @Date: 2025-02-13 09:08:39 | ||
* @LastEditors: jackning 270580156@qq.com | ||
* @LastEditTime: 2025-02-13 09:10:19 | ||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk | ||
* Please be aware of the BSL license restrictions before installing Bytedesk IM – | ||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. | ||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE | ||
* contact: 270580156@qq.com | ||
* | ||
* Copyright (c) 2025 by bytedesk.com, All Rights Reserved. | ||
*/ | ||
package com.bytedesk.ai.springai; | ||
|
||
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 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.SimpleLoggerAdvisor; | ||
import org.springframework.ai.chat.memory.ChatMemory; | ||
import org.springframework.ai.vectorstore.VectorStore; | ||
import org.springframework.stereotype.Service; | ||
|
||
import reactor.core.publisher.Flux; | ||
|
||
/** | ||
* https://docs.spring.io/spring-ai/reference/api/chatclient.html#_chat_memory | ||
*/ | ||
@Service | ||
public class CustomerSupportAssistant { | ||
|
||
private final ChatClient chatClient; | ||
|
||
public CustomerSupportAssistant(ChatClient.Builder builder, VectorStore vectorStore, ChatMemory chatMemory) { | ||
|
||
this.chatClient = builder | ||
.defaultSystem(""" | ||
You are a customer chat support agent of an airline named "Funnair". Respond in a friendly, | ||
helpful, and joyful manner. | ||
Before providing information about a booking or cancelling a booking, you MUST always | ||
get the following information from the user: booking number, customer first name and last name. | ||
Before changing a booking you MUST ensure it is permitted by the terms. | ||
If there is a charge for the change, you MUST ask the user to consent before proceeding. | ||
""") | ||
.defaultAdvisors( | ||
new MessageChatMemoryAdvisor(chatMemory), // CHAT MEMORY | ||
new QuestionAnswerAdvisor(vectorStore), // RAG | ||
new SimpleLoggerAdvisor()) | ||
.defaultTools("getBookingDetails", "changeBooking", "cancelBooking") // FUNCTION CALLING | ||
.build(); | ||
} | ||
|
||
public Flux<String> chat(String chatId, String userMessageContent) { | ||
|
||
return this.chatClient.prompt() | ||
.user(userMessageContent) | ||
.advisors(a -> a | ||
.param(CHAT_MEMORY_CONVERSATION_ID_KEY, chatId) | ||
.param(CHAT_MEMORY_RETRIEVE_SIZE_KEY, 100)) | ||
.stream().content(); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...esk/ai/controller/SpringAIController.java → ...edesk/ai/springai/SpringAIController.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
36 changes: 36 additions & 0 deletions
36
modules/ai/src/main/java/com/bytedesk/ai/springai/SpringAiConfig.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,36 @@ | ||
/* | ||
* @Author: jackning 270580156@qq.com | ||
* @Date: 2025-02-12 12:09:13 | ||
* @LastEditors: jackning 270580156@qq.com | ||
* @LastEditTime: 2025-02-13 09:08:28 | ||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk | ||
* Please be aware of the BSL license restrictions before installing Bytedesk IM – | ||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. | ||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE | ||
* contact: 270580156@qq.com | ||
* | ||
* Copyright (c) 2025 by bytedesk.com, All Rights Reserved. | ||
*/ | ||
package com.bytedesk.ai.springai; | ||
|
||
import org.springframework.ai.chat.client.ChatClient; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Configuration | ||
public class SpringAiConfig { | ||
|
||
// https://docs.spring.io/spring-ai/reference/api/chatclient.html | ||
@Bean | ||
ChatClient chatClient(ChatClient.Builder builder) { | ||
return builder | ||
.defaultSystem("You are a friendly chat bot that answers question in the voice of a {voice}") | ||
.build(); | ||
} | ||
|
||
|
||
|
||
} |