Browse Source

fix: 修复工具集格式

fanyanpeng 1 year ago
parent
commit
2efdd03069

+ 8 - 6
src/main/java/com/njuzr/eaibackend/service/AIRequestService.java

@@ -57,7 +57,7 @@ public class AIRequestService {
     }
 
     public AIResponse requestChatGPT(List<AIEntry> messages) {
-        MyRequestObject requestObject = new MyRequestObject(model, messages);
+        MyRequestObject requestObject = new MyRequestObject(model, messages,0.7);
         String chatgptUrl = "https://api.openai.com";
         try {
             return chatgptClient.postWithToken(chatgptUrl+prefix, requestObject, AIResponse.class, key);
@@ -69,7 +69,7 @@ public class AIRequestService {
 
 
     public AIResponse requestChatGLM(List<AIEntry> messages) {
-        MyRequestObject requestObject = new MyRequestObject("ChatGLM3", messages);
+        MyRequestObject requestObject = new MyRequestObject("ChatGLM3", messages,0.7);
         String url = glm3Url;
 
         try {
@@ -82,20 +82,21 @@ public class AIRequestService {
 
 
     public AIResponse requestChatGLM4(List<AIEntry> messages) {
-        MyRequestObject requestObject = new MyRequestObject(glm4ModelName, messages);
+        MyRequestObject requestObject = new MyRequestObject(glm4ModelName, messages,0.7);
         String url = glm4Url;
 
         try {
             return chatglmClient.postWithToken(url+prefix, requestObject, AIResponse.class, glm4Token);
         } catch (Exception e) {
-            log.error("WebClient请求失败,AI请求失败~");
+            e.printStackTrace();
+            log.error("WebClient请求失败,AI请求失败~"+e.getMessage());
             throw new MyException(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()+":"+"服务器请求AI出错");
         }
     }
 
 
     public AIResponse requestQWen(List<AIEntry> messages) {
-        MyRequestObject requestObject = new MyRequestObject("QWen14B", messages);
+        MyRequestObject requestObject = new MyRequestObject("QWen14B", messages,0.7);
         String url = qWen14BUrl;
 
         try {
@@ -111,6 +112,7 @@ public class AIRequestService {
     static class MyRequestObject {
         private String model;
         private List<AIEntry> messages;
+        private Double temperature;
     }
 
     @Data
@@ -137,7 +139,7 @@ public class AIRequestService {
         private String content; // AI生成的回复
         private String role;
         private String function_call;
-        private String tool_calls;
+        private List<String> tool_calls;
     }
 
     @Data

+ 1 - 0
src/main/java/com/njuzr/eaibackend/utils/WebClientUtil.java

@@ -128,6 +128,7 @@ public class WebClientUtil {
             return this.webClient.post()
                     .uri(uri)
                     .header("Authorization", "Bearer " + key)
+                    .header("Content-Type","application/json")
                     .bodyValue(request)
                     .retrieve()
                     .bodyToMono(responseType)

+ 10 - 10
src/main/resources/application-dev.yaml

@@ -5,11 +5,11 @@ spring:
   datasource:
     driver-class-name: com.mysql.cj.jdbc.Driver
     username: root
-    password: Zr200012
-    url: jdbc:mysql://localhost:3306/eai?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=utf8
+    password: eai123456
+    url: jdbc:mysql://139.196.252.184:3306/eai?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true
   data:
     mongodb:
-      uri: mongodb://admin:admin@localhost:27017/eai?authSource=admin
+      uri: mongodb://admin:eai123456@139.196.252.184:27017/eai?authSource=admin
       authentication-database: admin
   mail:
     host: smtp.163.com
@@ -19,18 +19,17 @@ spring:
     default-encoding: UTF-8
 
 
-# MyBatis配置
 mybatis-plus:
   mapper-locations: classpath:mapper/*.xml
   type-aliases-package: com/njuzr/eaibackend/po
 
 
 jwt:
-  # jjwt密钥算法HS256,要求secret长度至少是256位
   secret: xTv@UA7e2q$*n&92AHo5Wj$@KAnguhxTv@UA7e2q$*n&92AHo5Wj$@KAnguhxTv@UA7e2q$*n&92AHo5Wj$@KAnguhxTv@UA7e2q$*n&92AHo5Wj$@KAnguhxTv@UA7e2q$*n&92AHo5Wj$@KAnguhxTv@UA7e2q$*n&92AHo5Wj$@KAnguhxTv@UA7e2q$*n&92AHo5Wj$@KAnguhxTv@UA7e2q$*n&92AHo5Wj$@KAnguh92AHo5Wj$@KAnguh92AHo5Wj$@KAnguh92AHo5Wj$@KAnguh
   issuer: eai
   expiration: 86400
 
+
 aliyun:
   oss:
     endpoint: oss-cn-shanghai.aliyuncs.com
@@ -38,8 +37,9 @@ aliyun:
     accessKeySecret: 2yvtVYE1qAZEgm0ChvdMqhp0LhB5Lj
     bucketName: eai-files
 
+
 logging:
-  config: classpath:log4j2-dev.xml
+  config: classpath:log4j2-prod.xml
 
 openai:
   chatgpt:
@@ -58,8 +58,8 @@ config:
     QWen14B:
       url: http://10.58.0.2:6679
 
-proxy:
-  enabled: true
-  host: 127.0.0.1
-  port: 7890
 
+proxy:
+  enabled: false
+  host: 20.111.54.16
+  port: 8123

+ 13 - 0
src/test/java/com/njuzr/eaibackend/service/AIRequestServiceTest.java

@@ -1,8 +1,13 @@
 package com.njuzr.eaibackend.service;
 
+import com.njuzr.eaibackend.po.AIEntry;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author: Leonezhurui
@@ -10,6 +15,7 @@ import org.springframework.boot.test.context.SpringBootTest;
  * @Package: EAI-Backend
  */
 
+@ActiveProfiles("dev")
 @SpringBootTest
 public class AIRequestServiceTest {
     private final AIRequestService aiRequestService;
@@ -21,5 +27,12 @@ public class AIRequestServiceTest {
 
     @Test
     public void testChatGLM() {
+        List<AIEntry> ms = new ArrayList<>();
+        AIEntry a1 = new AIEntry();
+        a1.setRole("user");
+        a1.setContent("123");
+        ms.add(a1);
+        AIRequestService.AIResponse response= aiRequestService.requestChatGLM4(ms);
+        System.out.println(response);
     }
 }