Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot]
94452dc4c3
⬆️ Bump org.apache.tomcat.embed:tomcat-embed-core
Bumps org.apache.tomcat.embed:tomcat-embed-core from 9.0.84 to 9.0.90.

---
updated-dependencies:
- dependency-name: org.apache.tomcat.embed:tomcat-embed-core
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-05 20:44:21 +00:00
4 changed files with 59 additions and 55 deletions

54
pom.xml
View File

@ -32,13 +32,21 @@
<groupId>io.netty</groupId>
<artifactId>netty-codec</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</exclusion>
</exclusions>
</dependency>
@ -51,27 +59,12 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--- log 日志依赖 start -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.13</version>
<version>1.5.3</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
@ -82,9 +75,18 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.13</version>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.19.0</version>
</dependency>
<!--- log 日志依赖 end -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec</artifactId>
@ -139,7 +141,7 @@
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>9.0.84</version>
<version>9.0.90</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -249,6 +251,12 @@
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -473,7 +481,7 @@
<profileActive>dev</profileActive>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
<profile>
@ -482,7 +490,7 @@
<profileActive>prod</profileActive>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>

View File

@ -1,10 +1,10 @@
package com.rymcu.forest.openai;
import com.alibaba.fastjson.JSONObject;
import com.rymcu.forest.core.result.GlobalResult;
import com.rymcu.forest.core.result.GlobalResultGenerator;
import com.rymcu.forest.entity.User;
import com.rymcu.forest.openai.entity.ChatMessageModel;
import com.rymcu.forest.openai.entity.ChatModel;
import com.rymcu.forest.openai.service.OpenAiService;
import com.rymcu.forest.openai.service.SseService;
import com.rymcu.forest.util.Html2TextUtil;
@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
@ -41,9 +42,20 @@ public class OpenAiController {
private String token;
@PostMapping("/chat")
public GlobalResult newChat(@RequestBody ChatModel chatModel) {
List<ChatMessageModel> messages = chatModel.getMessages();
String model = chatModel.getModel();
public GlobalResult chat(@RequestBody JSONObject jsonObject) {
String message = jsonObject.getString("message");
if (StringUtils.isBlank(message)) {
throw new IllegalArgumentException("参数异常!");
}
User user = UserUtils.getCurrentUserByToken();
ChatMessage chatMessage = new ChatMessage("user", message);
List<ChatMessage> list = new ArrayList<>(4);
list.add(chatMessage);
return sendMessage(user, list);
}
@PostMapping("/new-chat")
public GlobalResult newChat(@RequestBody List<ChatMessageModel> messages) {
if (messages.isEmpty()) {
throw new IllegalArgumentException("参数异常!");
}
@ -60,17 +72,15 @@ public class OpenAiController {
ChatMessage message = new ChatMessage(chatMessageModel.getRole(), Html2TextUtil.getContent(chatMessageModel.getContent()));
list.add(message);
});
return sendMessage(user, list, model);
return sendMessage(user, list);
}
@NotNull
private GlobalResult sendMessage(User user, List<ChatMessage> list, String model) {
if (StringUtils.isBlank(model)) {
model = "gpt-3.5-turbo-16k-0613";
}
private GlobalResult sendMessage(User user, List<ChatMessage> list) {
boolean isAdmin = UserUtils.isAdmin(user.getEmail());
OpenAiService service = new OpenAiService(token, Duration.ofSeconds(180));
ChatCompletionRequest completionRequest = ChatCompletionRequest.builder()
.model(model)
.model("gpt-3.5-turbo-16k-0613")
.stream(true)
.messages(list)
.build();

View File

@ -1,21 +0,0 @@
package com.rymcu.forest.openai.entity;
import lombok.Data;
import java.util.List;
/**
* Created on 2024/8/6 10:24.
*
* @author ronger
* @email ronger-x@outlook.com
* @desc : com.rymcu.forest.openai.entity
*/
@Data
public class ChatModel {
String model;
List<ChatMessageModel> messages;
}

View File

@ -8,11 +8,16 @@ import com.rymcu.forest.dto.LinkToImageUrlDTO;
import com.rymcu.forest.dto.TokenUser;
import com.rymcu.forest.enumerate.FilePath;
import com.rymcu.forest.service.ForestFileService;
import com.rymcu.forest.util.*;
import com.rymcu.forest.util.FileUtils;
import com.rymcu.forest.util.SpringContextHolder;
import com.rymcu.forest.util.UserUtils;
import com.rymcu.forest.util.Utils;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.UnauthorizedException;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.springframework.transaction.annotation.Transactional;
@ -29,6 +34,8 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;
import com.rymcu.forest.util.SSRFUtil;
/**
* 文件上传控制器
*