diff --git a/Dockerfiles/Dockerfile.jar b/Dockerfiles/Dockerfile.jar index 02d696f..28564a9 100644 --- a/Dockerfiles/Dockerfile.jar +++ b/Dockerfiles/Dockerfile.jar @@ -12,7 +12,7 @@ ENV TZ=Asia/Shanghai RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone # 复制JAR文件到容器的/app目录下 -COPY /target/gpt-4-copilot-0.2.5.jar app.jar +COPY /target/gpt-4-copilot-0.2.6.jar app.jar # 声明服务运行在8081端口 EXPOSE 8081 diff --git a/pom.xml b/pom.xml index 3a0954a..626af84 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.gpt4.copilot gpt-4-copilot - 0.2.5 + 0.2.6 native Demo project for Spring Boot with GraalVM Native Image diff --git a/src/main/java/com/gpt4/copilot/controller/ChatController.java b/src/main/java/com/gpt4/copilot/controller/ChatController.java index 37b1db3..244c83a 100644 --- a/src/main/java/com/gpt4/copilot/controller/ChatController.java +++ b/src/main/java/com/gpt4/copilot/controller/ChatController.java @@ -8,10 +8,7 @@ import com.alibaba.fastjson2.TypeReference; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.gpt4.copilot.copilotApplication; -import com.gpt4.copilot.pojo.Conversation; -import com.gpt4.copilot.pojo.Result; -import com.gpt4.copilot.pojo.SystemSetting; -import com.gpt4.copilot.pojo.streamResponse; +import com.gpt4.copilot.pojo.*; import com.unfbx.chatgpt.entity.chat.Message; import com.unfbx.chatgpt.utils.TikTokensUtil; import jakarta.servlet.http.HttpServletRequest; @@ -886,9 +883,15 @@ public class ChatController { } } - private Request getEmdPrompt(Object conversation, + private Request getEmdPrompt(Embeddings conversation, Map headersMap) { try { + Object input = conversation.getInput(); + if (input instanceof String) { + List resInput = new ArrayList<>(); + resInput.add((String) input); + conversation.setInput(resInput); + } String json = com.alibaba.fastjson2.JSON.toJSONString(conversation); RequestBody requestBody = RequestBody.create(json, JSON); Request.Builder requestBuilder = new Request.Builder().url(github_embaddings).post(requestBody); @@ -917,7 +920,7 @@ public class ChatController { @PostMapping(value = "/v1/embeddings") public ResponseEntity coPilotEmbeddings(HttpServletResponse response, HttpServletRequest request, - @org.springframework.web.bind.annotation.RequestBody Object conversation) { + @org.springframework.web.bind.annotation.RequestBody Embeddings conversation) { String header = request.getHeader("Authorization"); String authorizationHeader = (header != null && !header.trim().isEmpty()) ? header.trim() : null; // 异步处理 @@ -1010,7 +1013,7 @@ public class ChatController { @PostMapping(value = "/cocopilot/v1/embeddings") public ResponseEntity coCoPilotEmbeddings(HttpServletResponse response, HttpServletRequest request, - @org.springframework.web.bind.annotation.RequestBody Object conversation) { + @org.springframework.web.bind.annotation.RequestBody Embeddings conversation) { String header = request.getHeader("Authorization"); String authorizationHeader = (header != null && !header.trim().isEmpty()) ? header.trim() : null; // 异步处理 @@ -1033,7 +1036,7 @@ public class ChatController { return new ResponseEntity<>(Result.error("current requests is " + requestNum + " rate limit exceeded"), HttpStatus.TOO_MANY_REQUESTS); } } - // 创建OkHttpClient请求 请求https://api.githubcopilot.com/embeddings + // 创建OkHttpClient请求 请求https://api.githubcopilot.com/Embeddings String chat_token = coCopilotTokenList.get(apiKey); Map headersMap = new HashMap<>(); //添加头部 @@ -1088,7 +1091,7 @@ public class ChatController { @PostMapping(value = "/self/v1/embeddings") public ResponseEntity selfEmbeddings(HttpServletResponse response, HttpServletRequest request, - @org.springframework.web.bind.annotation.RequestBody Object conversation) { + @org.springframework.web.bind.annotation.RequestBody Embeddings conversation) { String header = request.getHeader("Authorization"); String authorizationHeader = (header != null && !header.trim().isEmpty()) ? header.trim() : null; // 异步处理 @@ -1413,8 +1416,8 @@ public class ChatController { String chat_message_id = resJson.getString("id"); long timestamp = resJson.getLong("created"); // 使用stream形式适应List - List choices = Stream.of(new streamResponse.Choice(0, new streamResponse.Delta(content), null)).collect(Collectors.toList()); - streamResponse streamResponse = new streamResponse(chat_message_id, model, "chat.completion.chunk", choices, timestamp); + List choices = Stream.of(new StreamResponse.Choice(0, new StreamResponse.Delta(content), null)).collect(Collectors.toList()); + StreamResponse streamResponse = new StreamResponse(chat_message_id, model, "chat.completion.chunk", choices, timestamp); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("data: "); stringBuilder.append(com.alibaba.fastjson.JSONObject.toJSONString(streamResponse)); diff --git a/src/main/java/com/gpt4/copilot/controller/CustomErrorController.java b/src/main/java/com/gpt4/copilot/controller/CustomErrorController.java index f648e0e..4362d94 100644 --- a/src/main/java/com/gpt4/copilot/controller/CustomErrorController.java +++ b/src/main/java/com/gpt4/copilot/controller/CustomErrorController.java @@ -25,7 +25,7 @@ public class CustomErrorController implements ErrorController { " Document\n" + "\n" + "\n" + - "

Thanks you use gpt4-copilot-java-0.2.5

\n" + + "

Thanks you use gpt4-copilot-java-0.2.6

\n" + "

详细使用文档

\n" + "

项目地址

\n" + "\n" + diff --git a/src/main/java/com/gpt4/copilot/copilotApplication.java b/src/main/java/com/gpt4/copilot/copilotApplication.java index 0d3ad84..5bb3f5e 100644 --- a/src/main/java/com/gpt4/copilot/copilotApplication.java +++ b/src/main/java/com/gpt4/copilot/copilotApplication.java @@ -298,9 +298,10 @@ public class copilotApplication { System.out.println("one_selfCopilot_limit:" + ChatController.getSystemSetting().getOne_selfCopilot_limit()); System.out.println("gpt4-copilot-java 初始化接口成功!"); System.out.println("======================================================"); - System.out.println("******原神gpt4-copilot-java v0.2.5启动成功******"); + System.out.println("******原神gpt4-copilot-java v0.2.6启动成功******"); System.out.println("* 由于本人略菜,graalvm依赖问题无法解决,之后代码将只通过jar和docker的形式运行"); System.out.println("* 适配最新的ui Open Webui"); + System.out.println("* 同时适配最新的UI Open Webui 里的/v1/embeddings接口"); System.out.println("URL地址:http://0.0.0.0:" + config.getServerPort() + config.getPrefix() + ""); System.out.println("======================================================"); } diff --git a/src/main/java/com/gpt4/copilot/pojo/Embeddings.java b/src/main/java/com/gpt4/copilot/pojo/Embeddings.java new file mode 100644 index 0000000..1302037 --- /dev/null +++ b/src/main/java/com/gpt4/copilot/pojo/Embeddings.java @@ -0,0 +1,20 @@ +package com.gpt4.copilot.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +/** + * @author Yangyang + * @create 2024-04-26 14:15 + */ + +@Data +@Slf4j +@NoArgsConstructor +@AllArgsConstructor +public class Embeddings { + private Object input; + private String model; +} diff --git a/src/main/java/com/gpt4/copilot/pojo/streamResponse.java b/src/main/java/com/gpt4/copilot/pojo/StreamResponse.java similarity index 96% rename from src/main/java/com/gpt4/copilot/pojo/streamResponse.java rename to src/main/java/com/gpt4/copilot/pojo/StreamResponse.java index e4ff31e..4f62090 100644 --- a/src/main/java/com/gpt4/copilot/pojo/streamResponse.java +++ b/src/main/java/com/gpt4/copilot/pojo/StreamResponse.java @@ -15,7 +15,7 @@ import java.util.List; @NoArgsConstructor @AllArgsConstructor @JSONType(orders={"id","model","object","choices","created"}) -public class streamResponse { +public class StreamResponse { private String id; private String model; private String object; diff --git a/target/classes/com/gpt4/copilot/controller/ChatController$1.class b/target/classes/com/gpt4/copilot/controller/ChatController$1.class index d930e21..2ef1c1b 100644 Binary files a/target/classes/com/gpt4/copilot/controller/ChatController$1.class and b/target/classes/com/gpt4/copilot/controller/ChatController$1.class differ diff --git a/target/classes/com/gpt4/copilot/controller/ChatController$2.class b/target/classes/com/gpt4/copilot/controller/ChatController$2.class index 145c0bb..0575bdb 100644 Binary files a/target/classes/com/gpt4/copilot/controller/ChatController$2.class and b/target/classes/com/gpt4/copilot/controller/ChatController$2.class differ diff --git a/target/classes/com/gpt4/copilot/controller/ChatController.class b/target/classes/com/gpt4/copilot/controller/ChatController.class index 5fa020f..35a7e95 100644 Binary files a/target/classes/com/gpt4/copilot/controller/ChatController.class and b/target/classes/com/gpt4/copilot/controller/ChatController.class differ diff --git a/target/classes/com/gpt4/copilot/controller/CustomErrorController.class b/target/classes/com/gpt4/copilot/controller/CustomErrorController.class index 712fc35..5bfb223 100644 Binary files a/target/classes/com/gpt4/copilot/controller/CustomErrorController.class and b/target/classes/com/gpt4/copilot/controller/CustomErrorController.class differ diff --git a/target/classes/com/gpt4/copilot/copilotApplication.class b/target/classes/com/gpt4/copilot/copilotApplication.class index 72f3460..98a9a8d 100644 Binary files a/target/classes/com/gpt4/copilot/copilotApplication.class and b/target/classes/com/gpt4/copilot/copilotApplication.class differ diff --git a/target/classes/com/gpt4/copilot/pojo/Embeddings.class b/target/classes/com/gpt4/copilot/pojo/Embeddings.class new file mode 100644 index 0000000..c1b7640 Binary files /dev/null and b/target/classes/com/gpt4/copilot/pojo/Embeddings.class differ diff --git a/target/classes/com/gpt4/copilot/pojo/streamResponse$Choice.class b/target/classes/com/gpt4/copilot/pojo/streamResponse$Choice.class index 53fb138..c604ffb 100644 Binary files a/target/classes/com/gpt4/copilot/pojo/streamResponse$Choice.class and b/target/classes/com/gpt4/copilot/pojo/streamResponse$Choice.class differ diff --git a/target/classes/com/gpt4/copilot/pojo/streamResponse$Delta.class b/target/classes/com/gpt4/copilot/pojo/streamResponse$Delta.class index e6d8a13..a0b5894 100644 Binary files a/target/classes/com/gpt4/copilot/pojo/streamResponse$Delta.class and b/target/classes/com/gpt4/copilot/pojo/streamResponse$Delta.class differ diff --git a/target/classes/com/gpt4/copilot/pojo/streamResponse.class b/target/classes/com/gpt4/copilot/pojo/streamResponse.class index b8fcf2d..bcad6c5 100644 Binary files a/target/classes/com/gpt4/copilot/pojo/streamResponse.class and b/target/classes/com/gpt4/copilot/pojo/streamResponse.class differ diff --git a/target/gpt-4-copilot-0.2.5.jar.original b/target/gpt-4-copilot-0.2.5.jar.original deleted file mode 100644 index 8d0f02f..0000000 Binary files a/target/gpt-4-copilot-0.2.5.jar.original and /dev/null differ diff --git a/target/gpt-4-copilot-0.2.5.jar b/target/gpt-4-copilot-0.2.6.jar similarity index 99% rename from target/gpt-4-copilot-0.2.5.jar rename to target/gpt-4-copilot-0.2.6.jar index f72eee5..3a855a6 100644 Binary files a/target/gpt-4-copilot-0.2.5.jar and b/target/gpt-4-copilot-0.2.6.jar differ diff --git a/target/gpt-4-copilot-0.2.6.jar.original b/target/gpt-4-copilot-0.2.6.jar.original new file mode 100644 index 0000000..02ad4a1 Binary files /dev/null and b/target/gpt-4-copilot-0.2.6.jar.original differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties index 17e36ad..8a00aaf 100644 --- a/target/maven-archiver/pom.properties +++ b/target/maven-archiver/pom.properties @@ -1,3 +1,3 @@ artifactId=gpt-4-copilot groupId=com.gpt4.copilot -version=0.2.5 +version=0.2.6 diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index 9180cbc..4a16b94 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -1,15 +1,16 @@ com\gpt4\copilot\controller\ChatController.class com\gpt4\copilot\config\CorsConfig.class +com\gpt4\copilot\pojo\StreamResponse.class com\gpt4\copilot\pojo\Conversation$ConversationBuilderImpl.class -com\gpt4\copilot\pojo\streamResponse.class com\gpt4\copilot\copilotApplication.class -com\gpt4\copilot\pojo\streamResponse$Delta.class com\gpt4\copilot\controller\ChatController$1.class com\gpt4\copilot\pojo\Conversation$ConversationBuilder.class com\gpt4\copilot\config\WebConfig.class com\gpt4\copilot\controller\CustomErrorController.class com\gpt4\copilot\pojo\Conversation.class -com\gpt4\copilot\pojo\streamResponse$Choice.class +com\gpt4\copilot\pojo\StreamResponse$Choice.class com\gpt4\copilot\pojo\SystemSetting.class com\gpt4\copilot\pojo\Result.class +com\gpt4\copilot\pojo\StreamResponse$Delta.class +com\gpt4\copilot\pojo\Embeddings.class com\gpt4\copilot\controller\ChatController$2.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index 3be3273..d1445e7 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -4,6 +4,7 @@ F:\vue\fakeApiTool\graalvm-demos\spring-native-image\GPT4-Copilot\src\main\java\ F:\vue\fakeApiTool\graalvm-demos\spring-native-image\GPT4-Copilot\src\main\java\com\gpt4\copilot\pojo\Conversation.java F:\vue\fakeApiTool\graalvm-demos\spring-native-image\GPT4-Copilot\src\main\java\com\gpt4\copilot\pojo\SystemSetting.java F:\vue\fakeApiTool\graalvm-demos\spring-native-image\GPT4-Copilot\src\main\java\com\gpt4\copilot\controller\ChatController.java -F:\vue\fakeApiTool\graalvm-demos\spring-native-image\GPT4-Copilot\src\main\java\com\gpt4\copilot\pojo\streamResponse.java +F:\vue\fakeApiTool\graalvm-demos\spring-native-image\GPT4-Copilot\src\main\java\com\gpt4\copilot\pojo\StreamResponse.java F:\vue\fakeApiTool\graalvm-demos\spring-native-image\GPT4-Copilot\src\main\java\com\gpt4\copilot\config\WebConfig.java F:\vue\fakeApiTool\graalvm-demos\spring-native-image\GPT4-Copilot\src\main\java\com\gpt4\copilot\copilotApplication.java +F:\vue\fakeApiTool\graalvm-demos\spring-native-image\GPT4-Copilot\src\main\java\com\gpt4\copilot\pojo\Embeddings.java