tanlie 2 nedēļas atpakaļ
vecāks
revīzija
850a170933

+ 5 - 3
wishing-platform/platform-service/platform-service-mobile/src/main/java/cn/qinys/platform/config/ChatClientConfig.java

@@ -10,7 +10,7 @@ public class ChatClientConfig {
 
     @Bean
     ChatClient chatClient(ChatModel chatModel) {
-        return ChatClient.builder(chatModel)
+        var builder = ChatClient.builder(chatModel)
                 .defaultSystem("""
                         你是许愿树的智能客服小助手,名叫"小愿"。
                         你的职责是:
@@ -34,7 +34,9 @@ public class ChatClientConfig {
 
                         回复控制在 100-200 字以内,简洁明了。
                         如果用户问的问题与许愿无关,礼貌地引导回许愿相关话题。
-                        """)
-                .build();
+                        """);
+
+
+        return builder.build();
     }
 }

+ 5 - 0
wishing-platform/platform-service/platform-service-mobile/src/main/java/cn/qinys/platform/mobile/service/impl/ChatServiceImpl.java

@@ -5,6 +5,7 @@ import cn.qinys.platform.entity.wishing.ChatMessage;
 import cn.qinys.platform.mobile.mapper.ChatMessageMapper;
 import cn.qinys.platform.mobile.resp.ChatHistoryResp;
 import cn.qinys.platform.mobile.service.ChatService;
+import cn.qinys.platform.mobile.tool.DateTimeTools;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
@@ -23,6 +24,7 @@ public class ChatServiceImpl implements ChatService {
     @Resource
     private ChatMessageMapper chatMessageMapper;
 
+
     @Override
     public String chat(String message, Integer treeId) {
         String userId = getUserId();
@@ -34,6 +36,7 @@ public class ChatServiceImpl implements ChatService {
         try {
             reply = chatClient.prompt()
                     .user(message)
+                    .tools(new DateTimeTools())
                     .call()
                     .content();
         } catch (Exception e) {
@@ -47,6 +50,8 @@ public class ChatServiceImpl implements ChatService {
         return reply;
     }
 
+    // ...existing code...
+
     @Override
     public ChatHistoryResp getHistory(Integer treeId) {
         String userId = getUserId();

+ 21 - 0
wishing-platform/platform-service/platform-service-mobile/src/main/java/cn/qinys/platform/mobile/tool/DateTimeTools.java

@@ -0,0 +1,21 @@
+package cn.qinys.platform.mobile.tool;
+
+import org.springframework.ai.tool.annotation.Tool;
+import org.springframework.context.i18n.LocaleContextHolder;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author lie tan
+ * @description
+ * @date 2026-06-13 10:20
+ **/
+public class DateTimeTools {
+
+
+    @Tool(description = "Get the current date and time in the user's timezone")
+    String getCurrentDateTime() {
+        return LocalDateTime.now().atZone(LocaleContextHolder.getTimeZone().toZoneId()).toString();
+    }
+
+}

+ 2 - 0
wishing-platform/platform-service/platform-service-mobile/src/main/resources/application.yml

@@ -20,6 +20,8 @@ jwt:
     - /dgapi/mobile/user/login/captcha
     - /dgapi/mobile/wishingtree/list
     - /dgapi/mobile/wishingtree/detail
+    - /dgapi/mobile/chat/history
+    - /dgapi/mobile/chat
     - dgapi/mobile/wish/tree/**
     - /dgapi/mobile/ext/file/**