diff --git a/rearServer/.idea/misc.xml b/rearServer/.idea/misc.xml
index 02fce0c..e68a673 100644
--- a/rearServer/.idea/misc.xml
+++ b/rearServer/.idea/misc.xml
@@ -1,3 +1,4 @@
+
@@ -15,7 +16,7 @@
-
+
\ No newline at end of file
diff --git a/rearServer/pom.xml b/rearServer/pom.xml
index e80ad7a..f5c3b3e 100644
--- a/rearServer/pom.xml
+++ b/rearServer/pom.xml
@@ -5,7 +5,7 @@
org.springframework.boot
spring-boot-starter-parent
- 2.7.15
+ 3.2.1
com.yyandywt99
@@ -14,7 +14,7 @@
pandoraNext
pandoraNext
- 11
+ 17
@@ -43,6 +43,12 @@
jjwt
0.9.1
+
+
+ javax.xml.bind
+ jaxb-api
+ 2.3.1
+
org.springframework.boot
@@ -59,11 +65,10 @@
docker-java
3.2.10
-
+
- com.github.plexpt
- chatgpt
- 4.3.0
+ com.squareup.okhttp3
+ okhttp
diff --git a/rearServer/src/main/java/com/tokensTool/pandoraNext/aop/LogAspect.java b/rearServer/src/main/java/com/tokensTool/pandoraNext/aop/LogAspect.java
index ac701b0..885778e 100644
--- a/rearServer/src/main/java/com/tokensTool/pandoraNext/aop/LogAspect.java
+++ b/rearServer/src/main/java/com/tokensTool/pandoraNext/aop/LogAspect.java
@@ -42,10 +42,10 @@ public void recordLog() {
log.info(controller.reloadContainer().toString());
} catch (Exception e) {
e.printStackTrace();
- log.info("热重载失败!");
+ log.error("热重载失败!");
}
} else {
- log.info("热重载未开启!");
+ log.error("热重载未开启!");
}
}
}
diff --git a/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/ChatCompletionResult.java b/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/ChatCompletionResult.java
deleted file mode 100644
index 0700448..0000000
--- a/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/ChatCompletionResult.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.tokensTool.pandoraNext.chat;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-import java.util.List;
-
-@Data
-@Builder
-@AllArgsConstructor
-@NoArgsConstructor
-public class ChatCompletionResult {
-
- private String id;
-
- private String object;
-
- private Long created;
-
- private String model;
-
- private List choices;
-
- private Usage usage;
-
- private String system_fingerprint;
-
-}
diff --git a/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/Choice.java b/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/Choice.java
deleted file mode 100644
index 9769c8f..0000000
--- a/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/Choice.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.tokensTool.pandoraNext.chat;
-
-import com.plexpt.chatgpt.entity.chat.Message;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@AllArgsConstructor
-@NoArgsConstructor
-public class Choice {
-
- private long index;
-
- private Message message;
-
- private String finish_reason;
-
-}
diff --git a/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/ContentChoice.java b/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/ContentChoice.java
deleted file mode 100644
index 8fa5921..0000000
--- a/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/ContentChoice.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.tokensTool.pandoraNext.chat;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@AllArgsConstructor
-@NoArgsConstructor
-public class ContentChoice {
-
- private String text;
-
-
- private int index;
-
-
- private String logprobs;
-
-
- private String finish_reason;
-
-
-}
diff --git a/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/ContentCompletion.java b/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/ContentCompletion.java
deleted file mode 100644
index 50af490..0000000
--- a/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/ContentCompletion.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package com.tokensTool.pandoraNext.chat;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@AllArgsConstructor
-@NoArgsConstructor
-public class ContentCompletion {
-
- /**
- * 指定要使用的模型
- */
- private String model;
-
-
- /**
- * 提供一个文本片段,作为模型生成文本的启动点或上下文
- */
- private String prompt;
-
-
- /**
- * 限制生成文本的最大长度,以一定数量的 tokens(标记)为单位。
- */
- private int max_tokens;
-
-
- /**
- * 控制生成文本的创造性,较高的值增加随机性,较低的值使生成更加确定性。
- */
- private int temperature;
-
-
- /**
- * 仅考虑概率累积最高的 tokens,而忽略其他概率较低的 tokens。
- */
- private int top_p;
-
-
- /**
- * 生成多少个不同的文本样本。
- */
- private int n;
-
-
- /**
- * 指定是否启用流式传输,即是否在生成文本时逐步接收输出。
- */
- private Boolean stream;
-
-
- /**
- * 是否返回每个 token 的对数概率。
- */
- private String logprobs;
-
-
- /**
- * 指定在生成文本时的停止条件,即遇到哪个字符串时停止生成。
- */
- private String stop;
-
-}
diff --git a/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/ContentResult.java b/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/ContentResult.java
deleted file mode 100644
index d9a02b1..0000000
--- a/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/ContentResult.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.tokensTool.pandoraNext.chat;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-import java.util.List;
-
-
-/**
- * 内容补全返回结果
- */
-@Data
-@Builder
-@AllArgsConstructor
-@NoArgsConstructor
-public class ContentResult {
-
- private String id;
-
- private String object;
-
- private Long created;
-
- private String model;
-
- private List choices;
-
- private Usage usage;
-
-}
diff --git a/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/Conversation.java b/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/Conversation.java
index 963b442..80aab80 100644
--- a/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/Conversation.java
+++ b/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/Conversation.java
@@ -1,7 +1,6 @@
package com.tokensTool.pandoraNext.chat;
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.plexpt.chatgpt.entity.chat.Message;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
diff --git a/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/Message.java b/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/Message.java
new file mode 100644
index 0000000..61dc01e
--- /dev/null
+++ b/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/Message.java
@@ -0,0 +1,63 @@
+package com.tokensTool.pandoraNext.chat;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import lombok.*;
+
+/**
+ * @author plexpt
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class Message {
+ /**
+ * 目前支持三种角色参考官网,进行情景输入:https://platform.openai.com/docs/guides/chat/introduction
+ */
+ private String role;
+ private String content;
+ private String name;
+
+
+ public Message(String role, String content) {
+ this.role = role;
+ this.content = content;
+ }
+
+ public static Message of(String content) {
+
+ return new Message(Message.Role.USER.getValue(), content);
+ }
+
+ public static Message ofSystem(String content) {
+
+ return new Message(Role.SYSTEM.getValue(), content);
+ }
+
+ public static Message ofAssistant(String content) {
+
+ return new Message(Role.ASSISTANT.getValue(), content);
+ }
+
+ public static Message ofFunction(String function) {
+
+ return new Message(Role.FUNCTION.getValue(), function);
+ }
+
+ @Getter
+ @AllArgsConstructor
+ public enum Role {
+
+ SYSTEM("system"),
+ USER("user"),
+ ASSISTANT("assistant"),
+
+ FUNCTION("function"),
+ ;
+ private String value;
+ }
+
+}
diff --git a/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/Usage.java b/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/Usage.java
deleted file mode 100644
index 24258fd..0000000
--- a/rearServer/src/main/java/com/tokensTool/pandoraNext/chat/Usage.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.tokensTool.pandoraNext.chat;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@AllArgsConstructor
-@NoArgsConstructor
-public class Usage {
-
- /**
- * 提示词消耗的tokens
- */
- @JsonProperty("prompt_tokens")
- private long promptTokens;
-
- /**
- * 回答消耗的tokens
- */
- @JsonProperty("completion_tokens")
- private long completionTokens;
-
- /**
- * 本次对话消耗的tokens
- */
- @JsonProperty("total_tokens")
- private long totalTokens;
-
-
-}
diff --git a/rearServer/src/main/java/com/tokensTool/pandoraNext/controller/apiController.java b/rearServer/src/main/java/com/tokensTool/pandoraNext/controller/apiController.java
index eefcdb3..8765874 100644
--- a/rearServer/src/main/java/com/tokensTool/pandoraNext/controller/apiController.java
+++ b/rearServer/src/main/java/com/tokensTool/pandoraNext/controller/apiController.java
@@ -268,7 +268,7 @@ public Result reloadContainer() {
try {
int exitCode = reloadProcess.waitFor();
if (exitCode != 0) {
- log.info("无法重载PandoraNext服务");
+ log.error("无法重载PandoraNext服务");
return Result.success("无法重载PandoraNext服务");
}
return Result.success("重置PandoraNext服务成功!");
@@ -305,11 +305,11 @@ public void restartContainer(String containerName) {
throw new RuntimeException(e);
}
} catch (Exception e) {
- log.info("无法重启PandoraNext服务");
+ log.error("无法重启PandoraNext服务");
throw new RuntimeException(e);
}
} else {
- log.info("jar包填错信息");
+ log.error("jar包填错信息");
}
}
@@ -336,10 +336,10 @@ public void closeRelease(String containName) {
throw new RuntimeException(e);
}
if (exitCode != 0) {
- log.info("无法关闭PandoraNext服务");
+ log.error("无法关闭PandoraNext服务");
throw new RuntimeException("无法关闭PandoraNext服务");
}
- log.info("关闭PandoraNext服务成功!");
+ log.error("关闭PandoraNext服务成功!");
} catch (Exception e) {
throw new RuntimeException();
}
@@ -364,7 +364,7 @@ public void openRelease(String containerName) {
Process startProcess = executeCommand(startCommand);
int exitCode = startProcess.waitFor();
if (exitCode != 0) {
- log.info("无法启动PandoraNext服务");
+ log.error("无法启动PandoraNext服务");
throw new RuntimeException("无法启动PandoraNext服务");
}
log.info("启动PandoraNext服务成功!");
@@ -384,7 +384,7 @@ public void docker(String containerName, String way) {
Process process = executeCommand(dockerCommand);
int exitCode = process.waitFor();
if (exitCode != 0) {
- log.info("无法" + way + "PandoraNext服务");
+ log.error("无法" + way + "PandoraNext服务");
throw new RuntimeException("无法" + way + "PandoraNext服务");
}
log.info(way + "PandoraNext服务");
@@ -403,7 +403,7 @@ public Process executeCommand(String command) {
ProcessBuilder processBuilder = new ProcessBuilder("bash", "-c", command);
return processBuilder.start();
} catch (Exception e) {
- throw new RuntimeException();
+ throw new RuntimeException("重载失败!");
}
}
diff --git a/rearServer/src/main/java/com/tokensTool/pandoraNext/controller/autoTokenController.java b/rearServer/src/main/java/com/tokensTool/pandoraNext/controller/autoTokenController.java
index fc5421d..45be567 100644
--- a/rearServer/src/main/java/com/tokensTool/pandoraNext/controller/autoTokenController.java
+++ b/rearServer/src/main/java/com/tokensTool/pandoraNext/controller/autoTokenController.java
@@ -47,7 +47,7 @@ public void toUpdateToken() {
} catch (Exception e) {
e.printStackTrace();
}
- log.info(Result.error("自动检查更新access_token,share_token和pool_token失败").toString());
+ log.warn(Result.error("自动检查更新access_token,share_token和pool_token失败").toString());
}
/**
diff --git a/rearServer/src/main/java/com/tokensTool/pandoraNext/controller/chatController.java b/rearServer/src/main/java/com/tokensTool/pandoraNext/controller/chatController.java
index 176ae61..cd9850d 100644
--- a/rearServer/src/main/java/com/tokensTool/pandoraNext/controller/chatController.java
+++ b/rearServer/src/main/java/com/tokensTool/pandoraNext/controller/chatController.java
@@ -7,6 +7,8 @@
import com.tokensTool.pandoraNext.chat.Conversation;
import com.tokensTool.pandoraNext.pojo.Result;
import com.tokensTool.pandoraNext.pojo.modelsUsage;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.apache.commons.lang.StringUtils;
@@ -20,8 +22,6 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
@@ -67,7 +67,7 @@ public class chatController {
@Value("${copilot_interface}")
private boolean copilot_interface;
- private ExecutorService executor = new ThreadPoolExecutor(0, 1000,
+ private ExecutorService executor = new ThreadPoolExecutor(0, 100,
60L, TimeUnit.SECONDS,
new SynchronousQueue());
@@ -113,9 +113,11 @@ private void clearModelsUsage() {
* @throws IOException
*/
@PostMapping(value = "/v1/chat/completions")
- public Object coPilotConversation(HttpServletResponse response, HttpServletRequest request, @org.springframework.web.bind.annotation.RequestBody Conversation conversation) throws ExecutionException, InterruptedException {
- Future