diff --git a/.github/workflows/jar-image.yml b/.github/workflows/jar-image.yml index 3c8ef9c..852b6ac 100644 --- a/.github/workflows/jar-image.yml +++ b/.github/workflows/jar-image.yml @@ -2,7 +2,7 @@ name: Build and Push Docker Image -jar on: release: - types: [created] + types: [ created ] workflow_dispatch: inputs: tag: @@ -14,33 +14,33 @@ jobs: build-and-push: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} - - name: Set tag name - id: tag_name - run: | - if [ "${{ github.event_name }}" = "release" ]; then - echo "::set-output name=tag::${GITHUB_REF#refs/tags/}" - elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then - echo "::set-output name=tag::${{ github.event.inputs.tag }}" - fi + - name: Set tag name + id: tag_name + run: | + if [ "${{ github.event_name }}" = "release" ]; then + echo "::set-output name=tag::${GITHUB_REF#refs/tags/}" + elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + echo "::set-output name=tag::${{ github.event.inputs.tag }}" + fi - - name: Build and push Docker image with Release tag - uses: docker/build-push-action@v2 - with: - context: . - file: ./Dockerfiles/Dockerfile.jar - push: true - tags: | - yangclivia/gpt4-copilot-java:${{ steps.tag_name.outputs.tag }}-jar - yangclivia/gpt4-copilot-java:latest-jar - platforms: linux/amd64,linux/arm64/v8 + - name: Build and push Docker image with Release tag + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfiles/Dockerfile.jar + push: true + tags: | + yangclivia/gpt4-copilot-java:${{ steps.tag_name.outputs.tag }}-jar + yangclivia/gpt4-copilot-java:latest-jar + platforms: linux/amd64,linux/arm64/v8 diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index a37aa20..3a0d969 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -1,7 +1,7 @@ name: Build and Upload Spring Boot Native Image with Maven on: release: - types: [created] + types: [ created ] workflow_dispatch: inputs: tag: @@ -13,100 +13,100 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + os: [ ubuntu-latest, macos-latest, windows-latest ] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Set tag name - id: tag_name - run: | - if [ "${{ github.event_name }}" = "release" ]; then - echo "::set-output name=tag::${GITHUB_REF#refs/tags/}" - elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then - echo "::set-output name=tag::${{ github.event.inputs.tag }}" - fi - shell: bash - - name: Set up JDK 17 - uses: actions/setup-java@v2 - with: - java-version: '17' - distribution: 'temurin' - - name: Cache Maven packages - uses: actions/cache@v2 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 - - uses: graalvm/setup-graalvm@v1 - with: - java-version: '21' - distribution: 'graalvm' - github-token: ${{ secrets.GITHUB_TOKEN }} - native-image-job-reports: 'true' - - name: Set execute permissions for mvnw - run: chmod +x ./mvnw - - name: Set UTF-8 Encoding - run: echo "JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8" >> $GITHUB_ENV - - name: Build native image with Maven - run: | - ./mvnw native:compile -Pnative - if [ "${{ matrix.os }}" = "windows-latest" ]; then - mv ./target/gpt-4-copilot.exe ./target/gpt-4-copilot-${{ steps.tag_name.outputs.tag }}-${{ matrix.os }}.exe - else - mv ./target/gpt-4-copilot ./target/gpt-4-copilot-${{ steps.tag_name.outputs.tag }}-${{ matrix.os }} - fi - shell: bash - - name: Create directory for packaging - run: | - mkdir packaging - if [ "${{ matrix.os }}" = "windows-latest" ]; then - cp ./target/gpt-4-copilot-${{ steps.tag_name.outputs.tag }}-${{ matrix.os }}.exe ./packaging/gpt-4-copilot.exe - else - cp ./target/gpt-4-copilot-${{ steps.tag_name.outputs.tag }}-${{ matrix.os }} ./packaging/gpt-4-copilot - fi - cp ./config.json ./packaging/config.json - shell: bash - - name: Create ZIP (Unix) - if: runner.os != 'Windows' - run: | - cd packaging - zip -r ../target/gpt-4-copilot-${{ steps.tag_name.outputs.tag }}-${{ matrix.os }}.zip . - shell: bash - - name: Create ZIP (Windows) - if: runner.os == 'Windows' - run: | - Compress-Archive -Path packaging/* -DestinationPath ./target/gpt-4-copilot-${{ steps.tag_name.outputs.tag }}-${{ matrix.os }}.zip - shell: powershell - - name: Check if release exists - id: check_release - run: | - RELEASE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.tag_name.outputs.tag }}) || true - if echo "$RELEASE" | grep -q '"id":'; then - echo "::set-output name=exists::true" - UPLOAD_URL=$(echo "$RELEASE" | jq -r .upload_url) - echo "::set-output name=upload_url::${UPLOAD_URL}" - else - echo "::set-output name=exists::false" - fi - shell: bash - - name: Create Release if not exists - if: steps.check_release.outputs.exists == 'false' - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ steps.tag_name.outputs.tag }} - release_name: Release ${{ steps.tag_name.outputs.tag }} - draft: false - prerelease: false - - name: Upload ZIP to Release - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.check_release.outputs.exists == 'true' && steps.check_release.outputs.upload_url || steps.create_release.outputs.upload_url }} - asset_path: ./target/gpt-4-copilot-${{ steps.tag_name.outputs.tag }}-${{ matrix.os }}.zip - asset_name: gpt-4-copilot-${{ steps.tag_name.outputs.tag }}-${{ matrix.os }}.zip - asset_content_type: application/zip + - name: Set tag name + id: tag_name + run: | + if [ "${{ github.event_name }}" = "release" ]; then + echo "::set-output name=tag::${GITHUB_REF#refs/tags/}" + elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + echo "::set-output name=tag::${{ github.event.inputs.tag }}" + fi + shell: bash + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + java-version: '17' + distribution: 'temurin' + - name: Cache Maven packages + uses: actions/cache@v2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + - uses: graalvm/setup-graalvm@v1 + with: + java-version: '21' + distribution: 'graalvm' + github-token: ${{ secrets.GITHUB_TOKEN }} + native-image-job-reports: 'true' + - name: Set execute permissions for mvnw + run: chmod +x ./mvnw + - name: Set UTF-8 Encoding + run: echo "JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8" >> $GITHUB_ENV + - name: Build native image with Maven + run: | + ./mvnw native:compile -Pnative + if [ "${{ matrix.os }}" = "windows-latest" ]; then + mv ./target/gpt-4-copilot.exe ./target/gpt-4-copilot-${{ steps.tag_name.outputs.tag }}-${{ matrix.os }}.exe + else + mv ./target/gpt-4-copilot ./target/gpt-4-copilot-${{ steps.tag_name.outputs.tag }}-${{ matrix.os }} + fi + shell: bash + - name: Create directory for packaging + run: | + mkdir packaging + if [ "${{ matrix.os }}" = "windows-latest" ]; then + cp ./target/gpt-4-copilot-${{ steps.tag_name.outputs.tag }}-${{ matrix.os }}.exe ./packaging/gpt-4-copilot.exe + else + cp ./target/gpt-4-copilot-${{ steps.tag_name.outputs.tag }}-${{ matrix.os }} ./packaging/gpt-4-copilot + fi + cp ./config.json ./packaging/config.json + shell: bash + - name: Create ZIP (Unix) + if: runner.os != 'Windows' + run: | + cd packaging + zip -r ../target/gpt-4-copilot-${{ steps.tag_name.outputs.tag }}-${{ matrix.os }}.zip . + shell: bash + - name: Create ZIP (Windows) + if: runner.os == 'Windows' + run: | + Compress-Archive -Path packaging/* -DestinationPath ./target/gpt-4-copilot-${{ steps.tag_name.outputs.tag }}-${{ matrix.os }}.zip + shell: powershell + - name: Check if release exists + id: check_release + run: | + RELEASE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.tag_name.outputs.tag }}) || true + if echo "$RELEASE" | grep -q '"id":'; then + echo "::set-output name=exists::true" + UPLOAD_URL=$(echo "$RELEASE" | jq -r .upload_url) + echo "::set-output name=upload_url::${UPLOAD_URL}" + else + echo "::set-output name=exists::false" + fi + shell: bash + - name: Create Release if not exists + if: steps.check_release.outputs.exists == 'false' + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.tag_name.outputs.tag }} + release_name: Release ${{ steps.tag_name.outputs.tag }} + draft: false + prerelease: false + - name: Upload ZIP to Release + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.check_release.outputs.exists == 'true' && steps.check_release.outputs.upload_url || steps.create_release.outputs.upload_url }} + asset_path: ./target/gpt-4-copilot-${{ steps.tag_name.outputs.tag }}-${{ matrix.os }}.zip + asset_name: gpt-4-copilot-${{ steps.tag_name.outputs.tag }}-${{ matrix.os }}.zip + asset_content_type: application/zip diff --git a/.gitignore b/.gitignore index 42a2157..74b6926 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ e -i 66fe458e9ff3b7072252b455b08ac5c3076591bc^ +*.json +*.json diff --git a/config.json b/config.json index 4adc63e..e84b217 100644 --- a/config.json +++ b/config.json @@ -1,15 +1,15 @@ { - "password":"920052ec-14fc-4215-974d-d6fd3c89dd91", - "gpt4_prompt":true, - "gpt3_sleepTime":0, - "gpt4_sleepTime":100, - "maxPoolSize":300, - "vscode_version":"1.88.0", - "copilot_chat_version":"0.15.2024041001", - "get_token_url":"https://api.cocopilot.org/copilot_internal/v2/token", - "one_copilot_limit":30, - "one_coCopilot_limit":30, - "one_selfCopilot_limit":30, - "serverPort":8080, - "prefix":"/" + "password": "920052ec-14fc-4215-974d-d6fd3c89dd91", + "gpt4_prompt": true, + "gpt3_sleepTime": 0, + "gpt4_sleepTime": 100, + "maxPoolSize": 300, + "vscode_version": "1.88.0", + "copilot_chat_version": "0.15.2024041001", + "get_token_url": "https://api.cocopilot.org/copilot_internal/v2/token", + "one_copilot_limit": 30, + "one_coCopilot_limit": 30, + "one_selfCopilot_limit": 30, + "serverPort": 8080, + "prefix": "/" } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6eaeb8c..5bc7f2b 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.gpt4.copilot gpt-4-copilot - 0.1.3 + 0.2.0 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 514eb97..99d39c7 100644 --- a/src/main/java/com/gpt4/copilot/controller/ChatController.java +++ b/src/main/java/com/gpt4/copilot/controller/ChatController.java @@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.server.ResponseStatusException; import java.io.*; import java.nio.charset.StandardCharsets; @@ -157,7 +158,7 @@ public class ChatController { File jsonFile = new File(parent); Path jsonFilePath = Paths.get(parent); // 如果 JSON 文件不存在,创建一个新的 JSON 对象 - if (!jsonFile.exists() || jsonFile.length() == 0){ + if (!jsonFile.exists() || jsonFile.length() == 0) { try { if (!jsonFile.exists()) { // 创建文件machineIdList.json @@ -476,15 +477,7 @@ public class ChatController { // 异步处理 CompletableFuture> future = CompletableFuture.supplyAsync(() -> { try { - if (conversation == null) { - return new ResponseEntity<>(Result.error("Request body is missing or not in JSON format"), HttpStatus.BAD_REQUEST); - } - String apiKey; - if (authorizationHeader != null && authorizationHeader.startsWith("Bearer ")) { - apiKey = authorizationHeader.substring(7); - } else { - return new ResponseEntity<>(Result.error("Authorization header is missing"), HttpStatus.UNAUTHORIZED); - } + String apiKey = getRequestApikey(authorizationHeader, conversation); if (!copilotTokenList.containsKey(apiKey)) { String token = getCopilotToken(apiKey); if (token == null) { @@ -512,6 +505,8 @@ public class ChatController { if (!resp.isSuccessful()) { if (resp.code() == 429) { return new ResponseEntity<>(Result.error("rate limit exceeded"), HttpStatus.TOO_MANY_REQUESTS); + } else if (resp.code() == 400) { + return new ResponseEntity<>(Result.error("messages is none or too long and over 32K"), HttpStatus.INTERNAL_SERVER_ERROR); } else { String token = getCopilotToken(apiKey); if (token == null) { @@ -526,8 +521,8 @@ public class ChatController { outPutChat(response, resp, conversation, model); } } - } catch (IOException e) { - throw new RuntimeException(e); + } catch (Exception e) { + return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); } return null; }, executor); @@ -535,14 +530,26 @@ public class ChatController { return getObjectResponseEntity(response, future); } + private String getRequestApikey(String authorizationHeader, @org.springframework.web.bind.annotation.RequestBody Object conversation) { + if (conversation == null) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Request body is missing or not in JSON format"); + } + String apiKey; + if (authorizationHeader != null && authorizationHeader.startsWith("Bearer ")) { + apiKey = authorizationHeader.substring(7); + } else { + throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "Authorization header is missing"); + } + return apiKey; + } + private String modelAdjust(Conversation conversation) { String model = conversation.getModel(); - if(model == null){ + if (model == null) { conversation.setModel("gpt-3.5-turbo"); return "gpt-3.5-turbo"; - } - else{ - if(model.startsWith("gpt-4")) { + } else { + if (model.startsWith("gpt-4")) { conversation.setModel("gpt-4"); } return model; @@ -571,15 +578,7 @@ public class ChatController { // 异步处理 CompletableFuture> future = CompletableFuture.supplyAsync(() -> { try { - if (conversation == null) { - return new ResponseEntity<>(Result.error("Request body is missing or not in JSON format"), HttpStatus.BAD_REQUEST); - } - String apiKey; - if (authorizationHeader != null && authorizationHeader.startsWith("Bearer ")) { - apiKey = authorizationHeader.substring(7); - } else { - return new ResponseEntity<>(Result.error("Authorization header is missing"), HttpStatus.UNAUTHORIZED); - } + String apiKey = getRequestApikey(authorizationHeader, conversation); if (!coCopilotTokenList.containsKey(apiKey)) { String token = getCoCoToken(apiKey); if (token == null) { @@ -607,6 +606,8 @@ public class ChatController { if (!resp.isSuccessful()) { if (resp.code() == 429) { return new ResponseEntity<>(Result.error("rate limit exceeded"), HttpStatus.TOO_MANY_REQUESTS); + } else if (resp.code() == 400) { + return new ResponseEntity<>(Result.error("messages is none or too long and over 32K"), HttpStatus.INTERNAL_SERVER_ERROR); } else { String token = getCoCoToken(apiKey); if (token == null) { @@ -621,8 +622,8 @@ public class ChatController { outPutChat(response, resp, conversation, model); } } - } catch (IOException e) { - throw new RuntimeException(e); + } catch (Exception e) { + return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); } return null; }, executor); @@ -661,7 +662,7 @@ public class ChatController { */ private String[] extractApiKeyAndRequestUrl(String authorizationHeader, Object conversation) throws IllegalArgumentException { if (conversation == null) { - throw new IllegalArgumentException("Request body is missing or not in JSON format"); + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Request body is missing or not in JSON format"); } String apiKey = null; String requestUrl = null; @@ -732,6 +733,8 @@ public class ChatController { if (!resp.isSuccessful()) { if (resp.code() == 429) { return new ResponseEntity<>(Result.error("rate limit exceeded"), HttpStatus.TOO_MANY_REQUESTS); + } else if (resp.code() == 400) { + return new ResponseEntity<>(Result.error("messages is none or too long and over 32K"), HttpStatus.INTERNAL_SERVER_ERROR); } else { String token = getSelfToken(apiKey, requestUrl); if (token == null) { @@ -746,8 +749,8 @@ public class ChatController { outPutChat(response, resp, conversation, model); } } - } catch (IOException e) { - throw new RuntimeException(e); + } catch (Exception e) { + return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); } return null; }, executor); @@ -807,7 +810,7 @@ public class ChatController { } private Request getEmdPrompt(Object conversation, - Map headersMap) { + Map headersMap) { try { String json = com.alibaba.fastjson2.JSON.toJSONString(conversation); RequestBody requestBody = RequestBody.create(json, JSON); @@ -821,7 +824,6 @@ public class ChatController { } - /** * ghu/gho 请求 * 请求体不是json 会报Request body is missing or not in JSON format @@ -844,15 +846,7 @@ public class ChatController { // 异步处理 CompletableFuture> future = CompletableFuture.supplyAsync(() -> { try { - if (conversation == null) { - return new ResponseEntity<>(Result.error("Request body is missing or not in JSON format"), HttpStatus.BAD_REQUEST); - } - String apiKey; - if (authorizationHeader != null && authorizationHeader.startsWith("Bearer ")) { - apiKey = authorizationHeader.substring(7); - } else { - return new ResponseEntity<>(Result.error("Authorization header is missing"), HttpStatus.UNAUTHORIZED); - } + String apiKey = getRequestApikey(authorizationHeader, conversation); if (!copilotTokenList.containsKey(apiKey)) { String token = getCopilotToken(apiKey); if (token == null) { @@ -879,6 +873,8 @@ public class ChatController { if (!resp.isSuccessful()) { if (resp.code() == 429) { return new ResponseEntity<>(Result.error("rate limit exceeded"), HttpStatus.TOO_MANY_REQUESTS); + } else if (resp.code() == 400) { + return new ResponseEntity<>(Result.error("messages is none or too long and over 32K"), HttpStatus.INTERNAL_SERVER_ERROR); } else { String token = getCopilotToken(apiKey); if (token == null) { @@ -894,8 +890,8 @@ public class ChatController { } } return null; - } catch (IOException e) { - throw new RuntimeException(e); + } catch (Exception e) { + return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); } }, executor); @@ -940,15 +936,7 @@ public class ChatController { // 异步处理 CompletableFuture> future = CompletableFuture.supplyAsync(() -> { try { - if (conversation == null) { - return new ResponseEntity<>(Result.error("Request body is missing or not in JSON format"), HttpStatus.BAD_REQUEST); - } - String apiKey; - if (authorizationHeader != null && authorizationHeader.startsWith("Bearer ")) { - apiKey = authorizationHeader.substring(7); - } else { - return new ResponseEntity<>(Result.error("Authorization header is missing"), HttpStatus.UNAUTHORIZED); - } + String apiKey = getRequestApikey(authorizationHeader, conversation); if (!coCopilotTokenList.containsKey(apiKey)) { String token = getCoCoToken(apiKey); if (token == null) { @@ -975,6 +963,8 @@ public class ChatController { if (!resp.isSuccessful()) { if (resp.code() == 429) { return new ResponseEntity<>(Result.error("rate limit exceeded"), HttpStatus.TOO_MANY_REQUESTS); + } else if (resp.code() == 400) { + return new ResponseEntity<>(Result.error("messages is none or too long and over 32K"), HttpStatus.INTERNAL_SERVER_ERROR); } else { String token = getCoCoToken(apiKey); if (token == null) { @@ -990,8 +980,8 @@ public class ChatController { } } return null; - } catch (IOException e) { - throw new RuntimeException(e); + } catch (Exception e) { + return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); } }, executor); @@ -1049,6 +1039,8 @@ public class ChatController { if (!resp.isSuccessful()) { if (resp.code() == 429) { return new ResponseEntity<>(Result.error("rate limit exceeded"), HttpStatus.TOO_MANY_REQUESTS); + } else if (resp.code() == 400) { + return new ResponseEntity<>(Result.error("messages is none or too long and over 32K"), HttpStatus.INTERNAL_SERVER_ERROR); } else { String token = getSelfToken(apiKey, requestUrl); if (token == null) { @@ -1064,8 +1056,8 @@ public class ChatController { } } return null; - } catch (IOException e) { - throw new RuntimeException(e); + } catch (Exception e) { + return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); } }, executor); return getObjectResponseEntity(future); @@ -1094,7 +1086,7 @@ public class ChatController { } return null; } catch (Exception e) { - throw new RuntimeException(e); + return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); } } @@ -1301,7 +1293,7 @@ public class ChatController { */ private String saveMadchineId(String apiKey) { try { - if(machineIdList.containsKey(apiKey)){ + if (machineIdList.containsKey(apiKey)) { String machineId = machineIdList.get(apiKey); log.info("机械码读取成功!对应的机械码为:" + machineId); return machineId; diff --git a/src/main/java/com/gpt4/copilot/controller/CustomErrorController.java b/src/main/java/com/gpt4/copilot/controller/CustomErrorController.java index 02a825b..3e421d0 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.1.3

\n" + + "

Thanks you use gpt4-copilot-java-0.2.0

\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 f06d3c3..81aad40 100644 --- a/src/main/java/com/gpt4/copilot/copilotApplication.java +++ b/src/main/java/com/gpt4/copilot/copilotApplication.java @@ -37,7 +37,7 @@ public class copilotApplication { private static final String VS_CODE_API_URL = "https://api.github.com/repos/microsoft/vscode/releases/latest"; private static final String VS_CODE_CHAT_URL = "https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery"; - public static void main(String[] args){ + public static void main(String[] args) { String configFilePath = System.getProperty("user.dir") + File.separator + "config.json"; SystemSetting config = loadConfig(configFilePath); setSystemProperties(config); @@ -48,7 +48,7 @@ public class copilotApplication { private static SystemSetting loadConfig(String configFilePath) { File jsonFile = new File(configFilePath); Path jsonFilePath = Paths.get(configFilePath); - if (!jsonFile.exists() || jsonFile.length() == 0){ + if (!jsonFile.exists() || jsonFile.length() == 0) { try { if (!jsonFile.exists()) { // 创建文件config.json @@ -71,7 +71,7 @@ public class copilotApplication { String jsonContent = new String(Files.readAllBytes(Paths.get(configFilePath))); // 将 JSON 字符串解析为 JSONObject JSONObject jsonObject = com.alibaba.fastjson2.JSON.parseObject(jsonContent); - if(jsonObject == null){ + if (jsonObject == null) { jsonObject = new JSONObject(); } String password = getValueOrDefault(jsonObject, "password", UUID.randomUUID().toString(), "config.json没有新增password参数,现已增加!"); @@ -115,8 +115,7 @@ public class copilotApplication { T value; if (jsonObject == null) { value = null; - } - else { + } else { try { value = (T) jsonObject.get(key); } catch (JSONException e) { @@ -297,11 +296,12 @@ 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-native v0.1.3启动成功******"); + System.out.println("******原神gpt4-copilot-java-native v0.2.0启动成功******"); System.out.println("* 对chat接口的模型进行重定向,减少潜在的风险"); System.out.println("* 使用ConcurrentHashMap,粗略的对于每个密钥按每分钟进行限速"); System.out.println("* 新增环境变量用于对gpt-4*等模型进行系统prompt提示"); System.out.println("* 新增url|apikey形式传入/self/*接口,用于自定义地址和密钥"); + System.out.println("* 新增对于消息报错提醒,减少对于用户的困扰"); System.out.println("* 修复部分bug,优化读取config.json代码,提升稳定性"); System.out.println("* 新增每个密钥对于特定的机器码,且保存在文件中,一秘钥一机器码,减小被查询异常"); System.out.println("URL地址:http://0.0.0.0:" + config.getServerPort() + config.getPrefix() + ""); diff --git a/target/classes/com/gpt4/copilot/controller/ChatController$1.class b/target/classes/com/gpt4/copilot/controller/ChatController$1.class index 5a8aa5d..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 85ca325..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 5dc2139..3c5035e 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 4318caa..f1608a3 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 c4bcc05..ac7d631 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/Conversation$ConversationBuilder.class b/target/classes/com/gpt4/copilot/pojo/Conversation$ConversationBuilder.class index a5cacf0..1f00e0a 100644 Binary files a/target/classes/com/gpt4/copilot/pojo/Conversation$ConversationBuilder.class and b/target/classes/com/gpt4/copilot/pojo/Conversation$ConversationBuilder.class differ diff --git a/target/classes/com/gpt4/copilot/pojo/Conversation.class b/target/classes/com/gpt4/copilot/pojo/Conversation.class index dddae83..c07ec30 100644 Binary files a/target/classes/com/gpt4/copilot/pojo/Conversation.class and b/target/classes/com/gpt4/copilot/pojo/Conversation.class differ diff --git a/target/gpt-4-copilot-0.1.3.jar.original b/target/gpt-4-copilot-0.1.3.jar.original deleted file mode 100644 index 4819255..0000000 Binary files a/target/gpt-4-copilot-0.1.3.jar.original and /dev/null differ diff --git a/target/gpt-4-copilot-0.1.3.jar b/target/gpt-4-copilot-0.2.0.jar similarity index 99% rename from target/gpt-4-copilot-0.1.3.jar rename to target/gpt-4-copilot-0.2.0.jar index 0e55b36..37af756 100644 Binary files a/target/gpt-4-copilot-0.1.3.jar and b/target/gpt-4-copilot-0.2.0.jar differ diff --git a/target/gpt-4-copilot-0.2.0.jar.original b/target/gpt-4-copilot-0.2.0.jar.original new file mode 100644 index 0000000..7129804 Binary files /dev/null and b/target/gpt-4-copilot-0.2.0.jar.original differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties index e86272c..ec29e29 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.1.3 +version=0.2.0