From cc58c4cf6a699556f446ae0d5980eedb4bbfc774 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com>
Date: Thu, 23 Mar 2023 15:06:42 +0800
Subject: [PATCH] =?UTF-8?q?fix:=E7=BC=93=E5=AD=98=E8=AF=B7=E6=B1=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 22 +++
.../controller/FileUploadController.java | 2 +-
.../controller/PersonController.java | 59 -------
.../controller/RedisController.java | 2 +-
.../entity/chat/ChoiceMessage.java | 30 ++++
.../springbootkwan/entity/chat/Choices.java | 33 ++++
.../entity/chat/CompletionChatRequest.java | 41 +++++
.../entity/chat/CompletionChatResponse.java | 49 ++++++
.../utils/FileContainsUtil.java | 150 ++++++++++++++++++
.../utils/OpenAIChatGptUtil.java | 99 ++++++++++++
src/main/resources/mapper/UserMapper.xml | 7 -
11 files changed, 426 insertions(+), 68 deletions(-)
delete mode 100644 src/main/java/com/kwan/springbootkwan/controller/PersonController.java
create mode 100644 src/main/java/com/kwan/springbootkwan/entity/chat/ChoiceMessage.java
create mode 100644 src/main/java/com/kwan/springbootkwan/entity/chat/Choices.java
create mode 100644 src/main/java/com/kwan/springbootkwan/entity/chat/CompletionChatRequest.java
create mode 100644 src/main/java/com/kwan/springbootkwan/entity/chat/CompletionChatResponse.java
create mode 100644 src/main/java/com/kwan/springbootkwan/utils/FileContainsUtil.java
create mode 100644 src/main/java/com/kwan/springbootkwan/utils/OpenAIChatGptUtil.java
diff --git a/pom.xml b/pom.xml
index ab3dc48..5c8dd73 100644
--- a/pom.xml
+++ b/pom.xml
@@ -139,6 +139,28 @@
dynamic-datasource-spring-boot-starter
3.5.1
+
+
+ com.theokanning.openai-gpt3-java
+ service
+ 0.11.0
+
+
+
+ com.theokanning.openai-gpt3-java
+ client
+ 0.11.1
+
+
+ cn.hutool
+ hutool-all
+ 5.8.12
+
+
+ com.alibaba.fastjson2
+ fastjson2
+ 2.0.23
+
diff --git a/src/main/java/com/kwan/springbootkwan/controller/FileUploadController.java b/src/main/java/com/kwan/springbootkwan/controller/FileUploadController.java
index df2b520..c9b4e95 100644
--- a/src/main/java/com/kwan/springbootkwan/controller/FileUploadController.java
+++ b/src/main/java/com/kwan/springbootkwan/controller/FileUploadController.java
@@ -21,7 +21,7 @@ import java.util.UUID;
* @version : 2.2.0
* @date : 2022/12/19 16:07
*/
-@Api(description = "文件上传信息", tags = "FileUploadController")
+@Api(value = "文件上传信息", tags = "FileUploadController")
@RestController
public class FileUploadController {
diff --git a/src/main/java/com/kwan/springbootkwan/controller/PersonController.java b/src/main/java/com/kwan/springbootkwan/controller/PersonController.java
deleted file mode 100644
index bf567fb..0000000
--- a/src/main/java/com/kwan/springbootkwan/controller/PersonController.java
+++ /dev/null
@@ -1,59 +0,0 @@
-//package com.kwan.springbootkwan.controller;
-//
-//import com.kwan.springbootkwan.entity.Person;
-//import com.kwan.springbootkwan.entity.User;
-//import com.kwan.springbootkwan.service.IUserService;
-//import io.swagger.annotations.Api;
-//import io.swagger.annotations.ApiOperation;
-//import org.springframework.batch.core.Job;
-//import org.springframework.batch.core.JobParameters;
-//import org.springframework.batch.core.launch.JobLauncher;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.web.bind.annotation.*;
-//
-//import java.util.Date;
-//import java.util.List;
-//
-///**
-// * Person相关
-// *
-// * @author : qinyingjie
-// * @version : 2.2.0
-// * @date : 2022/12/19 16:08
-// */
-//@Api(description = "person用户信息", tags = "PersonController")
-//@RestController
-//@RequestMapping("/person")
-//public class PersonController {
-//
-// @Autowired
-// private JobLauncher jobLauncher;
-// @Autowired
-// private Job job;
-//
-// /**
-// * {
-// * "name": "zhang san",
-// * "age": 24,
-// * "birthday": "2022-12-19"
-// * }
-// */
-// @ApiOperation(value = "json返回", notes = "json返回")
-// @GetMapping("/person")
-// public Person person() {
-// Person person = new Person();
-// person.setUsername("zhang san");
-// person.setId(24);
-// person.setAddress("湖北");
-// return person;
-// }
-//
-// @GetMapping("/hello")
-// public void hello() {
-// try {
-// jobLauncher.run(job, new JobParameters());
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-// }
-//}
\ No newline at end of file
diff --git a/src/main/java/com/kwan/springbootkwan/controller/RedisController.java b/src/main/java/com/kwan/springbootkwan/controller/RedisController.java
index c28a5c5..d9b5ea8 100644
--- a/src/main/java/com/kwan/springbootkwan/controller/RedisController.java
+++ b/src/main/java/com/kwan/springbootkwan/controller/RedisController.java
@@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
-@Api(description = "redis测试信息", tags = "RedisController")
+@Api(value = "redis测试信息", tags = "RedisController")
@RestController
@RequestMapping("/test")
public class RedisController {
diff --git a/src/main/java/com/kwan/springbootkwan/entity/chat/ChoiceMessage.java b/src/main/java/com/kwan/springbootkwan/entity/chat/ChoiceMessage.java
new file mode 100644
index 0000000..3d34808
--- /dev/null
+++ b/src/main/java/com/kwan/springbootkwan/entity/chat/ChoiceMessage.java
@@ -0,0 +1,30 @@
+package com.kwan.springbootkwan.entity.chat;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+
+/**
+ * 结果
+ *
+ * @author : qinyingjie
+ * @version : 2.2.0
+ * @date : 2023/3/22 21:12
+ */
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@Data
+public class ChoiceMessage {
+ /**
+ * 角色
+ */
+ String role;
+ /**
+ * 具体内容
+ */
+ String content;
+}
+
diff --git a/src/main/java/com/kwan/springbootkwan/entity/chat/Choices.java b/src/main/java/com/kwan/springbootkwan/entity/chat/Choices.java
new file mode 100644
index 0000000..62fff46
--- /dev/null
+++ b/src/main/java/com/kwan/springbootkwan/entity/chat/Choices.java
@@ -0,0 +1,33 @@
+package com.kwan.springbootkwan.entity.chat;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+
+/**
+ * 结果集
+ *
+ * @author : qinyingjie
+ * @version : 2.2.0
+ * @date : 2023/3/22 21:12
+ */
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@Data
+public class Choices {
+ /**
+ * 内容对象
+ */
+ private ChoiceMessage message;
+ /**
+ * 结束原因
+ */
+ private String finish_reason;
+ /**
+ * 索引位置
+ */
+ private Integer index;
+}
diff --git a/src/main/java/com/kwan/springbootkwan/entity/chat/CompletionChatRequest.java b/src/main/java/com/kwan/springbootkwan/entity/chat/CompletionChatRequest.java
new file mode 100644
index 0000000..d60967b
--- /dev/null
+++ b/src/main/java/com/kwan/springbootkwan/entity/chat/CompletionChatRequest.java
@@ -0,0 +1,41 @@
+package com.kwan.springbootkwan.entity.chat;
+
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * 请求参数
+ *
+ * @author : qinyingjie
+ * @version : 2.2.0
+ * @date : 2023/3/22 21:00
+ */
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@Data
+public class CompletionChatRequest {
+ String model;
+ List