This commit is contained in:
Yanyutin753
2024-02-16 16:54:17 +08:00
parent 47ceb3e031
commit f0507f422f
19 changed files with 244 additions and 139 deletions

View File

@@ -2,7 +2,7 @@ name: Build and Push Docker Image
on:
release:
types: [created]
types: [ created ]
workflow_dispatch:
inputs:
tag:

View File

@@ -2,7 +2,7 @@ name: Maven Package
on:
release:
types: [created]
types: [ created ]
jobs:
build:

7
.idea/compiler.xml generated
View File

@@ -7,13 +7,16 @@
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="gpt-4-copilot-native" />
<module name="gpt-4-copilot" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel target="17" />
<bytecodeTargetLevel target="17">
<module name="gpt-4-copilot-native" target="17" />
</bytecodeTargetLevel>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="gpt-4-copilot" options="-parameters" />
<module name="gpt-4-copilot-native" options="-parameters" />
</option>
</component>

View File

@@ -1,14 +1,18 @@
# Spring Boot Microservice with Oracle GraalVM in OCI Cloud Shell
This part shows how you can get started quickly with Oracle GraalVM in Oracle Cloud Infrastructure (OCI) Cloud Shell using the Spring Boot 3 microservice example.
This part shows how you can get started quickly with Oracle GraalVM in Oracle Cloud Infrastructure (OCI) Cloud Shell
using the Spring Boot 3 microservice example.
Oracle GraalVM is available for use on Oracle Cloud Infrastructure (OCI) at no additional cost.
## What is Cloud Shell?
[Cloud Shell](https://www.oracle.com/devops/cloud-shell/) is a free-to-use browser-based terminal accessible from the Oracle Cloud Console. It provides access to a Linux shell with preinstalled developer tools and a pre-authenticated OCI CLI. You can use the shell to interact with OCI resources, follow labs and tutorials, and quickly run utility commands.
[Cloud Shell](https://www.oracle.com/devops/cloud-shell/) is a free-to-use browser-based terminal accessible from the
Oracle Cloud Console. It provides access to a Linux shell with preinstalled developer tools and a pre-authenticated OCI
CLI. You can use the shell to interact with OCI resources, follow labs and tutorials, and quickly run utility commands.
Oracle GraalVM for JDK 17 (with Native Image) is preinstalled in Cloud Shell, so you dont have to install and configure a development machine to get started.
Oracle GraalVM for JDK 17 (with Native Image) is preinstalled in Cloud Shell, so you dont have to install and configure
a development machine to get started.
## Step 1: Launch Cloud Shell
@@ -85,7 +89,8 @@ This step is optional - [Check software version and environment variables](../_c
curl http://localhost:8080/jibber
```
It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be similar to:
It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be
similar to:
```shell
...
@@ -133,7 +138,8 @@ Now build a native executable for your Spring Boot microservice using Oracle Gra
curl http://localhost:8080/jibber
```
It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be similar to:
It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be
similar to:
```shell
...

View File

@@ -1,20 +1,26 @@
# Spring Boot Microservice with Oracle GraalVM in OCI Code Editor
This part shows how you can get started quickly with Oracle GraalVM in Oracle Cloud Infrastructure (OCI) Code Editor using the Spring Boot 3 microservice example.
This part shows how you can get started quickly with Oracle GraalVM in Oracle Cloud Infrastructure (OCI) Code Editor
using the Spring Boot 3 microservice example.
Oracle GraalVM is available for use on Oracle Cloud Infrastructure (OCI) at no additional cost.
## What is Code Editor?
[Code Editor](https://www.oracle.com/devops/code-editor/) enables you to edit and deploy code directly from the Oracle Cloud Console. You can develop applications, service workflows, and scripts entirely from a browser. This makes it easy to rapidly prototype cloud solutions, try new services, and accomplish quick coding tasks.
[Code Editor](https://www.oracle.com/devops/code-editor/) enables you to edit and deploy code directly from the Oracle
Cloud Console. You can develop applications, service workflows, and scripts entirely from a browser. This makes it easy
to rapidly prototype cloud solutions, try new services, and accomplish quick coding tasks.
Oracle GraalVM for JDK 17 (with Native Image) is preinstalled in Cloud Shell, so you dont have to install and configure a development machine to get started. Code Editor's integration with Cloud Shell gives you direct access to Oracle GraalVM JDK and Native Image.
Oracle GraalVM for JDK 17 (with Native Image) is preinstalled in Cloud Shell, so you dont have to install and configure
a development machine to get started. Code Editor's integration with Cloud Shell gives you direct access to Oracle
GraalVM JDK and Native Image.
## Step 1: Open Terminal in Code Editor
1. [Login to OCI Console and launch Code Editor](https://cloud.oracle.com/?bdcstate=maximized&codeeditor=true).
2. Open a `New Terminal` in Code Editor. Use this Terminal window to run the commands shown in this sample.
![](./images/oci-ce-terminal.png)
![](./images/oci-ce-terminal.png)
## Step 2: Select GraalVM as the Current JDK
@@ -87,7 +93,8 @@ This step is optional - [Check software version and environment variables](../_c
curl http://localhost:8080/jibber
```
It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be similar to:
It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be
similar to:
```shell
...
@@ -133,7 +140,8 @@ Now build a native executable for your Spring Boot microservice using GraalVM Na
```shell
curl http://localhost:8080/jibber
```
It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be similar to:
It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be
similar to:
```shell
...

105
README.md
View File

@@ -1,8 +1,12 @@
# Spring Boot Native Image Microservice
This demo shows how to build, package, and run a simple Spring Boot 3 microservice from a JAR file with the GraalVM JDK, and from a native executable with GraalVM Native Image. The benefits of using a native executable are faster start-up times and reduced memory consumption. It also demonstrates how to run the application and build the native executable within a Docker container.
This demo shows how to build, package, and run a simple Spring Boot 3 microservice from a JAR file with the GraalVM JDK,
and from a native executable with GraalVM Native Image. The benefits of using a native executable are faster start-up
times and reduced memory consumption. It also demonstrates how to run the application and build the native executable
within a Docker container.
There are two ways to generate a native executable from a Spring Boot application:
- [Using GraalVM Native Build Tools](https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.native-build-tools)
- [Using Buildpacks](https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.buildpacks)
@@ -10,12 +14,22 @@ There are two ways to generate a native executable from a Spring Boot applicatio
The example is a minimal REST-based API application, built on top of Spring Boot 3. It consists of:
- `com.example.jibber.JibberApplication`: the main Spring Boot class. It is also a REST controller which serves as an entry-point for HTTP requests.
- `com.example.jibber.JibberApplication`: the main Spring Boot class. It is also a REST controller which serves as an
entry-point for HTTP requests.
- `com.example.jibber.Jabberwocky`: a utility class that implements the logic of the application.
If you call the HTTP endpoint, `/jibber`, it will return some nonsense verse generated in the style of the Jabberwocky poem, by Lewis Carroll. The program achieves this by using a Markov Chain to model the original poem (this is essentially a statistical model). This model generates a new text. The example application provides the text of the poem, then generates a model of the text, which the application then uses to generate a new text that is similar to the original text. The application uses the [RiTa library](https://rednoise.org/rita/) as an external dependency to build and use Markov Chains.
If you call the HTTP endpoint, `/jibber`, it will return some nonsense verse generated in the style of the Jabberwocky
poem, by Lewis Carroll. The program achieves this by using a Markov Chain to model the original poem (this is
essentially a statistical model). This model generates a new text. The example application provides the text of the
poem, then generates a model of the text, which the application then uses to generate a new text that is similar to the
original text. The application uses the [RiTa library](https://rednoise.org/rita/) as an external dependency to build
and use Markov Chains.
By default, the demo uses the [Native Build Tools Maven plugin](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html) to perform the tasks. If you would like to run this demo using [BuildPacks](https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.buildpacks), the build configuration is provided for you too.
By default, the demo uses
the [Native Build Tools Maven plugin](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html) to perform
the tasks. If you would like to run this demo
using [BuildPacks](https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.buildpacks),
the build configuration is provided for you too.
## Prerequisites
@@ -24,7 +38,11 @@ By default, the demo uses the [Native Build Tools Maven plugin](https://graalvm.
sdk install java 21.0.2-graal
```
2. (Optional) Install and run a Docker-API compatible container runtime such as [Rancher Desktop](https://docs.rancherdesktop.io/getting-started/installation/), [Docker](https://www.docker.io/gettingstarted/), or [Podman](https://podman.io/docs/installation). If you are using Docker, configure it to [allow non-root user access](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user) if you are on Linux.
2. (Optional) Install and run a Docker-API compatible container runtime such
as [Rancher Desktop](https://docs.rancherdesktop.io/getting-started/installation/), [Docker](https://www.docker.io/gettingstarted/),
or [Podman](https://podman.io/docs/installation). If you are using Docker, configure it
to [allow non-root user access](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user)
if you are on Linux.
3. Download the demos repository or clone it as follows:
@@ -50,7 +68,8 @@ This demo is built using Maven.
./mvnw clean package
```
It generates a runnable JAR file that contains all of the applications dependencies and also a correctly configured `MANIFEST` file.
It generates a runnable JAR file that contains all of the applications dependencies and also a correctly
configured `MANIFEST` file.
2. Run the application JAR and put it into the background by appending `&`:
@@ -58,7 +77,8 @@ This demo is built using Maven.
java -jar ./target/benchmark-jibber-0.0.1-SNAPSHOT.jar &
```
3. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or call the endpoint using `curl`:
3. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or call the endpoint
using `curl`:
```shell
curl http://localhost:8080/jibber
@@ -70,7 +90,8 @@ This demo is built using Maven.
### (Optional) Containerize the JAR
The following steps (5-8) show how you can easily containerize the JAR built in the previous step using the Oracle GraalVM JDK container image `container-registry.oracle.com/graalvm/jdk:17-ol8`.
The following steps (5-8) show how you can easily containerize the JAR built in the previous step using the Oracle
GraalVM JDK container image `container-registry.oracle.com/graalvm/jdk:17-ol8`.
5. Run this command to package the JAR as a Docker container:
@@ -84,7 +105,8 @@ The following steps (5-8) show how you can easily containerize the JAR built in
docker run --rm --name graal -p 8080:8080 jibber-benchmark:jvm.0.0.1-SNAPSHOT
```
7. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or from a new terminal window, call the endpoint using `curl`:
7. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or from a new
terminal window, call the endpoint using `curl`:
```shell
curl http://localhost:8080/jibber
@@ -103,16 +125,21 @@ The following steps (5-8) show how you can easily containerize the JAR built in
Recap what you have so far: built a Spring Boot application with an HTTP endpoint, and successfully containerised it.
Now you will look at how you can create a native executable from your application.
Spring Boot 3's built-in support for GraalVM Native Image makes it easy to compile a Spring Boot 3 application into a native executable.
Spring Boot 3's built-in support for GraalVM Native Image makes it easy to compile a Spring Boot 3 application into a
native executable.
This native executable not only starts faster but also uses far fewer resources than running the application as a JAR file.
This native executable not only starts faster but also uses far fewer resources than running the application as a JAR
file.
You can use the `native-image` tool from the GraalVM installation to build a native executable.
In this example, you'll use the [GraalVM Native Build Tools for Maven](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html) to build a native executable.
In this example, you'll use
the [GraalVM Native Build Tools for Maven](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html) to
build a native executable.
### Default Native Build Configuration
Make sure youre using `spring-boot-starter-parent` in order to inherit the out-of-the-box `native` profile, and the `org.graalvm.buildtools:native-maven-plugin` plugin.
Make sure youre using `spring-boot-starter-parent` in order to inherit the out-of-the-box `native` profile, and
the `org.graalvm.buildtools:native-maven-plugin` plugin.
You should see the following in the Maven `pom.xml` file:
@@ -137,11 +164,13 @@ You should see the following in the Maven `pom.xml` file:
</build>
```
The out-of-the-box `native` profile has [GraalVM Reachability Metadata](https://www.graalvm.org/native-image/libraries-and-frameworks/) enabled by default.
The out-of-the-box `native` profile
has [GraalVM Reachability Metadata](https://www.graalvm.org/native-image/libraries-and-frameworks/) enabled by default.
### Build and Run as a Native Executable
With the out-of-the-box `native` profile active, you can invoke the `native:compile` goal to trigger native-image compilation.
With the out-of-the-box `native` profile active, you can invoke the `native:compile` goal to trigger native-image
compilation.
1. Run the following command:
@@ -149,9 +178,12 @@ With the out-of-the-box `native` profile active, you can invoke the `native:comp
./mvnw native:compile -Pnative
```
The `native` profile is used to generate a native executable for your platform. The native executable is called _benchmark-jibber_ and is generated in the _target_ directory.
The `native` profile is used to generate a native executable for your platform. The native executable is called
_benchmark-jibber_ and is generated in the _target_ directory.
>Alternatively, to build using BuildPacks, run the `./mvnw spring-boot:build-image -Pnative` command to generate a native executable. For more information about using BuildPacks to create a native executable, see [Building a Native Image Using Buildpacks](https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.buildpacks).
> Alternatively, to build using BuildPacks, run the `./mvnw spring-boot:build-image -Pnative` command to generate a
native executable. For more information about using BuildPacks to create a native executable,
see [Building a Native Image Using Buildpacks](https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.buildpacks).
2. Run the native executable and put it into the background by appending `&`:
@@ -159,7 +191,8 @@ With the out-of-the-box `native` profile active, you can invoke the `native:comp
./target/benchmark-jibber &
```
3. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or call the endpoint using `curl`:
3. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or call the endpoint
using `curl`:
```shell
curl http://localhost:8080/jibber
@@ -169,13 +202,17 @@ With the out-of-the-box `native` profile active, you can invoke the `native:comp
4. Bring the application to the foreground using `fg`, and then enter `<CTRL-c>` to terminate the application.
From the log output, notice how much quicker the native executable version of this Spring Boot application starts compared to the JAR. The native executable also uses fewer resources than running from a JAR file.
From the log output, notice how much quicker the native executable version of this Spring Boot application starts
compared to the JAR. The native executable also uses fewer resources than running from a JAR file.
### Additional Native Build Configuration
Notice that you can pass additional configuration arguments to the underlying `native-image` build tool using the `<buildArgs>` section. In individual `buildArg` tags, you can pass parameters exactly the same way as you do from a command line. This lets you use all of the parameters that work with the `native-image` tool from Maven.
Notice that you can pass additional configuration arguments to the underlying `native-image` build tool using
the `<buildArgs>` section. In individual `buildArg` tags, you can pass parameters exactly the same way as you do from a
command line. This lets you use all of the parameters that work with the `native-image` tool from Maven.
Add the following snippet to the pom.xml to pass additional arguments to enable verbose output, quick build mode, etc. over and above the out-of-the-box `native` profile.
Add the following snippet to the pom.xml to pass additional arguments to enable verbose output, quick build mode, etc.
over and above the out-of-the-box `native` profile.
```xml
<profiles>
@@ -211,7 +248,8 @@ Let's rebuild the native executable with the additional configuration arguments.
./mvnw native:compile -Pnative
```
With the quick build mode enabled, it takes less time to build the native executable. This mode should be used in development for faster builds.
With the quick build mode enabled, it takes less time to build the native executable. This mode should be used in
development for faster builds.
2. Run the native executable and put it into the background by appending `&`:
@@ -219,7 +257,8 @@ Let's rebuild the native executable with the additional configuration arguments.
./target/benchmark-jibber &
```
3. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or call the endpoint using `curl`:
3. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or call the endpoint
using `curl`:
```shell
curl http://localhost:8080/jibber
@@ -229,7 +268,8 @@ Let's rebuild the native executable with the additional configuration arguments.
4. Bring the application to the foreground using `fg`, and then enter `<CTRL-c>` to terminate the application.
From the log output, notice how much quicker the native executable version of this Spring Boot application starts compared to the JAR. The native executable also uses fewer resources than running from a JAR file.
From the log output, notice how much quicker the native executable version of this Spring Boot application starts
compared to the JAR. The native executable also uses fewer resources than running from a JAR file.
### (Optional) Containerize the Native Executable on Linux
@@ -247,7 +287,8 @@ The following steps (5-8) are for Linux only.
docker run --rm --name native -p 8080:8080 jibber-benchmark:native.0.0.1-SNAPSHOT
```
7. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or from a new terminal window, call the endpoint using `curl`:
7. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or from a new
terminal window, call the endpoint using `curl`:
```shell
curl http://localhost:8080/jibber
@@ -265,7 +306,9 @@ The following steps (5-8) are for Linux only.
The following steps (9-12) are for all platforms - MacOS, Windows, and Linux.
For MacOS and Windows, to build a Docker image containing your native executable, you need to build the native executable inside a Docker container. To do this, we've provided a [multistage Docker build file](./Dockerfiles/Dockerfile).
For MacOS and Windows, to build a Docker image containing your native executable, you need to build the native
executable inside a Docker container. To do this, we've provided
a [multistage Docker build file](./Dockerfiles/Dockerfile).
9. Run this command to build the native executable within a Docker container:
@@ -279,7 +322,8 @@ For MacOS and Windows, to build a Docker image containing your native executable
docker run --rm --name native -p 8080:8080 jibber-benchmark:native.0.0.1-SNAPSHOT
```
11. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or from a new terminal window, call the endpoint using `curl`:
11. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or from a new
terminal window, call the endpoint using `curl`:
```shell
curl http://localhost:8080/jibber
@@ -295,12 +339,15 @@ For MacOS and Windows, to build a Docker image containing your native executable
## Measure the Performance of the Application and Metrics
The Spring Actuator dependency has been added to the project, along with support for Prometheus. If you want to test the performance of either the JVM version, or the native executable version of the application, you can make use of the Prometheus support. If you are hosting the application locally, it is available on port 8080:
The Spring Actuator dependency has been added to the project, along with support for Prometheus. If you want to test the
performance of either the JVM version, or the native executable version of the application, you can make use of the
Prometheus support. If you are hosting the application locally, it is available on port 8080:
[http://localhost:8080/actuator/prometheus](http://localhost:8080/actuator/prometheus)
## Related Documentation
- Run an interactive lab: [Level Up your Spring Boot Java Application with GraalVM](https://luna.oracle.com/lab/268ea851-2f09-43e6-8d70-40a10cb4de03)
- Run an interactive
lab: [Level Up your Spring Boot Java Application with GraalVM](https://luna.oracle.com/lab/268ea851-2f09-43e6-8d70-40a10cb4de03)
- [Maven Build Plugin for GraalVM Native Image](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html/)
- [Spring Boot GraalVM Native Image Support](https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html)

View File

@@ -1,6 +1,6 @@
{
"gpt3_sleepTime": 0,
"password": "abc",
"password": "2602c0f5-7e73-4586-a788-2c856d2eb748",
"get_token_url": "http:\/\/124.220.157.23:8800\/copilot_internal\/v2\/token",
"prefix": "\/tokensTool",
"serverPort": 8081,

17
pom.xml
View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -77,6 +77,21 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@@ -105,6 +105,38 @@ public class chatController {
private final String github_embaddings = "https://api.githubcopilot.com/embeddings";
private final String vscode_version = "vscode/1.85.2";
public static Integer getGpt4_sleepTime() {
return gpt4_sleepTime;
}
public static void setGpt4_sleepTime(Integer gpt4_sleepTime) {
chatController.gpt4_sleepTime = gpt4_sleepTime;
}
public static Integer getGpt3_sleepTime() {
return gpt3_sleepTime;
}
public static void setGpt3_sleepTime(Integer gpt3_sleepTime) {
chatController.gpt3_sleepTime = gpt3_sleepTime;
}
public static String getPassword() {
return password;
}
public static void setPassword(String password) {
chatController.password = password;
}
public static String getGet_token_url() {
return get_token_url;
}
public static void setGet_token_url(String get_token_url) {
chatController.get_token_url = get_token_url;
}
public static String selectFile() {
String projectRoot = System.getProperty("user.dir");
String parent = projectRoot + File.separator + "config.json";
@@ -126,21 +158,6 @@ public class chatController {
return parent;
}
public static void setGpt4_sleepTime(Integer gpt4_sleepTime) {
chatController.gpt4_sleepTime = gpt4_sleepTime;
}
public static void setGpt3_sleepTime(Integer gpt3_sleepTime) {
chatController.gpt3_sleepTime = gpt3_sleepTime;
}
public static void setGet_token_url(String get_token_url) {
chatController.get_token_url = get_token_url;
}
/**
* 查询config.json里的系统值
*
@@ -222,10 +239,6 @@ public class chatController {
}
}
public static void setPassword(String password) {
chatController.password = password;
}
/**
* 修改sleep时间
*/

View File

@@ -1,6 +1,7 @@
package com.gpt4.copilot;
import com.gpt4.copilot.controller.chatController;
import com.gpt4.copilot.pojo.systemSetting;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONException;
@@ -13,7 +14,6 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.UUID;
/**
* @author YANGYANG
@@ -70,10 +70,6 @@ public class copilotApplication {
systemSetting config = new systemSetting();
config.setServerPort(getIntOrDefault(jsonObject, "serverPort", 8080));
config.setPrefix(getStringOrDefault(jsonObject, "prefix", "/"));
config.setGpt4_sleepTime(getIntOrDefault(jsonObject, "gpt4_sleepTime", 100));
config.setGpt3_sleepTime(getIntOrDefault(jsonObject, "gpt3_sleepTime", 0));
config.setPassword(getStringOrDefault(jsonObject, "password", UUID.randomUUID().toString()));
config.setGet_token_url(getStringOrDefault(jsonObject, "get_token_url", "https://api.copilot.org/copilot_internal/v2/token"));
String updatedJson = jsonObject.toString(2);
Files.write(Paths.get(configFilePath), updatedJson.getBytes());
return config;
@@ -114,20 +110,22 @@ public class copilotApplication {
}
private static void printStartupMessage(systemSetting config) {
System.out.println("-------------------------------------------------------");
System.out.println("\n-------------------------------------------------------");
System.out.println("------原神gpt4-copilot-java-native v0.0.4启动成功--------");
System.out.println("* 采用graalvm打包运行内存大幅度减小");
System.out.println("* 增加自定义获取token渠道");
System.out.println("* 增加自定义/self/*接口");
System.out.println("* 增加反代/copilot_internal/v2/token接口");
System.out.println("URL地址http://0.0.0.0:" + config.getServerPort() + config.getPrefix() + "");
System.out.println("-------------------------------------------------------\n");
System.out.println("-------------------------------------------------------");
System.out.println("---------------------配置说明---------------------------");
System.out.println("gpt4_sleepTime" + config.getGpt4_sleepTime());
System.out.println("gpt3_sleepTime" + config.getGpt3_sleepTime());
System.out.println("get_token_url" + config.getGet_token_url());
System.out.println("password" + config.getPassword());
System.out.println("初始化接口成功!");
System.out.println("serverPort" + config.getServerPort());
System.out.println("prefix" + config.getPrefix());
System.out.println("gpt3_sleepTime" + chatController.getGpt3_sleepTime());
System.out.println("gpt4_sleepTime" + chatController.getGpt4_sleepTime());
System.out.println("get_token_url" + chatController.getGet_token_url());
System.out.println("password" + chatController.getPassword());
System.out.println("gpt4-copilot-java-native初始化接口成功");
System.out.println("-------------------------------------------------------");
}

View File

@@ -0,0 +1,15 @@
management.endpoints.web.exposure.include=metrics,health,info,prometheus
# server.port
server.port=8080
# SpringBoot 2.* prefix
server.servlet.context-path=/
# gpt4 sleep time
gpt4_sleepTime=100
# gpt3 sleep time
gpt3_sleepTime=0
# changeSleepTime's password
password=gpt4-copilot-java
# self-define get_token_url
get_token_url=https://api.cocopilot.org/copilot_internal/v2/token

Binary file not shown.

Binary file not shown.