This commit is contained in:
Yanyutin753
2024-02-15 23:58:04 +08:00
parent 284cdf02fa
commit 1554832b05
23 changed files with 1238 additions and 108 deletions

4
.idea/compiler.xml generated
View File

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

1
.idea/misc.xml generated
View File

@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CodeInsightWorkspaceSettings">
<option name="optimizeImportsOnTheFly" value="true" />

1
.idea/vcs.xml generated
View File

@@ -2,5 +2,6 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

32
pom.xml
View File

@@ -8,9 +8,9 @@
<version>3.2.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>benchmark-jibber</artifactId>
<version>0.0.1-SNAPSHOT</version>
<groupId>com.gpt4.copilot</groupId>
<artifactId>gpt-4-copilot-native</artifactId>
<version>gpt-4-copilot-native</version>
<name>benchmark-jibber</name>
<description>Demo project for Spring Boot with GraalVM Native Image</description>
<properties>
@@ -40,6 +40,32 @@
<artifactId>rita</artifactId>
<version>2.4.501</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- json-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.32</version>
</dependency>
<!-- okhttp依赖-->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
<version>0.0.20131108.vaadin1</version>
</dependency>
</dependencies>
<build>

View File

@@ -1,32 +0,0 @@
/*
* Copyright © 2023, Oracle and/or its affiliates.
* Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/.
*/
package com.example.benchmarks.jibber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class DemoApplication {
@Autowired
Jabberwocky j;
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@RequestMapping(method = RequestMethod.GET, path = "/jibber")
ResponseEntity<String> jibber() {
return ResponseEntity.ok(j.generate());
}
}

View File

@@ -1,68 +0,0 @@
/*
* Copyright © 2023, Oracle and/or its affiliates.
* Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/.
*/
package com.example.benchmarks.jibber;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import rita.RiMarkov;
@Service
@Scope("singleton")
public class Jabberwocky {
//
private RiMarkov r;
public Jabberwocky() {
loadModel();
}
private void loadModel() {
//
String text = "Twas brillig, and the slithy toves " +
"Did gyre and gimble in the wabe: " +
"All mimsy were the borogoves, " +
"And the mome raths outgrabe. " +
"Beware the Jabberwock, my son! " +
"The jaws that bite, the claws that catch! " +
"Beware the Jubjub bird, and shun " +
"The frumious Bandersnatch! " +
"He took his vorpal sword in hand; " +
"Long time the manxome foe he sought— " +
"So rested he by the Tumtum tree " +
"And stood awhile in thought. " +
"And, as in uffish thought he stood, " +
"The Jabberwock, with eyes of flame, " +
"Came whiffling through the tulgey wood, " +
"And burbled as it came! " +
"One, two! One, two! And through and through " +
"The vorpal blade went snicker-snack! " +
"He left it dead, and with its head " +
"He went galumphing back. " +
"And hast thou slain the Jabberwock? " +
"Come to my arms, my beamish boy! " +
"O frabjous day! Callooh! Callay! " +
"He chortled in his joy. " +
"Twas brillig, and the slithy toves " +
"Did gyre and gimble in the wabe: " +
"All mimsy were the borogoves, " +
"And the mome raths outgrabe.";
this.r = new RiMarkov(3);
this.r.addText(text);
}
public String generate() {
String[] lines = this.r.generate(10);
StringBuilder b = new StringBuilder();
//
for (String line : lines ) {
b.append(line);
b.append("<br/>\n");
}
//
return b.toString();
}
}

View File

@@ -0,0 +1,29 @@
package com.gpt4.copilot.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
* @author Yangyang
* @create 2023-09-21 17:00
*/
@Configuration
public class CorsConfig {
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
// 允许本地所有端口,也可以设置具体的域名
config.addAllowedOrigin("*");
// 允许所有请求头
config.addAllowedHeader("*");
// 允许所有HTTP方法
config.addAllowedMethod("*");
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}

View File

@@ -0,0 +1,18 @@
package com.gpt4.copilot.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.concurrent.TimeUnit;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
// 设置默认异步请求超时时间例如设置为6分钟
configurer.setDefaultTimeout(TimeUnit.MINUTES.toMillis(6));
}
}

View File

@@ -0,0 +1,34 @@
package com.gpt4.copilot.controller;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Yangyang
* @create 2024-02-05 1:18
*/
@RestController
public class CustomErrorController implements ErrorController {
private static final String PATH = "/error";
@RequestMapping(value = PATH)
public ResponseEntity<String> error() {
return new ResponseEntity<>("<!DOCTYPE html>\n" +
"<html lang=\"en\">\n" +
"<head>\n" +
" <meta charset=\"UTF-8\">\n" +
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
" <title>Document</title>\n" +
"</head>\n" +
"<body>\n" +
" <p>Thanks you use gpt4-copilot-java</p>\n" +
" <p><a href=\"https://apifox.com/apidoc/shared-4301e565-a8df-48a0-85a5-bda2c4c3965a\">详细使用文档</a></p>\n" +
" <p><a href=\"https://github.com/Yanyutin753/gpt4-copilot-java-sh\">项目地址</a></p>\n" +
"</body>\n" +
"</html>\n", HttpStatus.OK);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,45 @@
package com.gpt4.copilot;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* @author YANGYANG
*/
/**
* 定时注解
* @author YANGYANG
*/
@Slf4j
@EnableScheduling
@SpringBootApplication
public class copilotApplication {
@Value("${server.servlet.context-path}")
private String contextPath;
@Value("${server.port}")
private String serverPort;
public static void main(String[] args) {
SpringApplication.run(copilotApplication.class, args);
}
@PostConstruct
public void initialize() {
System.out.println("------------------------------------------------------");
System.out.println("----------原神gpt4-copilot-java v0.0.3启动成功------------");
System.out.println("* 优化打字机输出");
System.out.println("* 增加自定义获取token渠道");
System.out.println("* 增加反代/copilot_internal/v2/token接口");
System.out.println("URL地址http://0.0.0.0:" + serverPort + contextPath +"");
System.out.println("------------------------------------------------------");
}
}

View File

@@ -0,0 +1,47 @@
package com.gpt4.copilot.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {
/**
* 响应码1 代表成功; 0 代表失败
*/
private Integer code;
/**
* 响应信息 描述字符串
*/
private String msg;
/**
* 返回的数据
*/
private Object data;
/**
* 增删改 成功响应
*/
public static Result success() {
return new Result(1, "success", null);
}
/**
* 查询 成功响应
*/
public static Result success(Object data) {
return new Result(1, "success", data);
}
/**
* 失败响应
*/
public static Result error(String msg) {
return new Result(0, msg, null);
}
}

View File

@@ -1 +1,15 @@
management.endpoints.web.exposure.include=metrics,health,info,prometheus
# server.port
server.port=8081
# 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

View File

@@ -1 +1,15 @@
management.endpoints.web.exposure.include=metrics,health,info,prometheus
# server.port
server.port=8081
# 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.