12 changed files with 435 additions and 0 deletions
@ -0,0 +1,140 @@ |
|||||
|
<?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" |
||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
|
<parent> |
||||
|
<artifactId>bnyer-services</artifactId> |
||||
|
<groupId>com.dimensionalnode</groupId> |
||||
|
<version>1.0.0</version> |
||||
|
</parent> |
||||
|
<modelVersion>4.0.0</modelVersion> |
||||
|
|
||||
|
<artifactId>bnyer-ai</artifactId> |
||||
|
|
||||
|
<description> |
||||
|
bnyer-ai服务 |
||||
|
</description> |
||||
|
|
||||
|
<dependencies> |
||||
|
<!-- SpringCloud Alibaba Nacos --> |
||||
|
<dependency> |
||||
|
<groupId>com.alibaba.cloud</groupId> |
||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- SpringCloud Alibaba Nacos Config --> |
||||
|
<dependency> |
||||
|
<groupId>com.alibaba.cloud</groupId> |
||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- SpringCloud Alibaba Sentinel --> |
||||
|
<dependency> |
||||
|
<groupId>com.alibaba.cloud</groupId> |
||||
|
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- SpringBoot Actuator --> |
||||
|
<dependency> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-starter-actuator</artifactId> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- Swagger UI --> |
||||
|
<dependency> |
||||
|
<groupId>io.springfox</groupId> |
||||
|
<artifactId>springfox-swagger-ui</artifactId> |
||||
|
<version>${swagger.fox.version}</version> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- Mysql Connector --> |
||||
|
<dependency> |
||||
|
<groupId>mysql</groupId> |
||||
|
<artifactId>mysql-connector-java</artifactId> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- bnyer Common DataSource --> |
||||
|
<dependency> |
||||
|
<groupId>com.dimensionalnode</groupId> |
||||
|
<artifactId>bnyer-common-datasource</artifactId> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- bnyer Common DataScope --> |
||||
|
<dependency> |
||||
|
<groupId>com.dimensionalnode</groupId> |
||||
|
<artifactId>bnyer-common-datascope</artifactId> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- bnyer Common Log --> |
||||
|
<dependency> |
||||
|
<groupId>com.dimensionalnode</groupId> |
||||
|
<artifactId>bnyer-common-log</artifactId> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- bnyer Common core --> |
||||
|
<dependency> |
||||
|
<groupId>com.dimensionalnode</groupId> |
||||
|
<artifactId>bnyer-common-core</artifactId> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- bnyer Common Swagger --> |
||||
|
<dependency> |
||||
|
<groupId>com.dimensionalnode</groupId> |
||||
|
<artifactId>bnyer-common-swagger</artifactId> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- mybatis-plus --> |
||||
|
<dependency> |
||||
|
<groupId>com.baomidou</groupId> |
||||
|
<artifactId>mybatis-plus-boot-starter</artifactId> |
||||
|
</dependency> |
||||
|
|
||||
|
<!--任务调度中心--> |
||||
|
<!-- <dependency>--> |
||||
|
<!-- <groupId>com.xuxueli</groupId>--> |
||||
|
<!-- <artifactId>xxl-job-core</artifactId>--> |
||||
|
<!-- <version>2.3.1</version>--> |
||||
|
<!-- </dependency>--> |
||||
|
|
||||
|
<!--微信小程序工具包--> |
||||
|
<!-- <dependency>--> |
||||
|
<!-- <groupId>com.github.binarywang</groupId>--> |
||||
|
<!-- <artifactId>weixin-java-miniapp</artifactId>--> |
||||
|
<!-- <version>4.2.0</version>--> |
||||
|
<!-- </dependency>--> |
||||
|
|
||||
|
<!--七牛云--> |
||||
|
<!-- <dependency>--> |
||||
|
<!-- <groupId>com.qiniu</groupId>--> |
||||
|
<!-- <artifactId>qiniu-java-sdk</artifactId>--> |
||||
|
<!-- <version>7.2.18</version>--> |
||||
|
<!-- </dependency>--> |
||||
|
|
||||
|
<!--chatgpt--> |
||||
|
<dependency> |
||||
|
<groupId>com.github.plexpt</groupId> |
||||
|
<artifactId>chatgpt</artifactId> |
||||
|
<version>4.0.5</version> |
||||
|
</dependency> |
||||
|
|
||||
|
</dependencies> |
||||
|
|
||||
|
<build> |
||||
|
<finalName>${project.artifactId}</finalName> |
||||
|
<plugins> |
||||
|
<plugin> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
|
<version>2.6.2</version> |
||||
|
<executions> |
||||
|
<execution> |
||||
|
<goals> |
||||
|
<goal>repackage</goal> |
||||
|
</goals> |
||||
|
</execution> |
||||
|
</executions> |
||||
|
</plugin> |
||||
|
</plugins> |
||||
|
</build> |
||||
|
|
||||
|
</project> |
||||
@ -0,0 +1,33 @@ |
|||||
|
package com.bnyer.ai; |
||||
|
|
||||
|
import com.bnyer.common.security.annotation.EnableCustomConfig; |
||||
|
import com.bnyer.common.security.annotation.EnableRyFeignClients; |
||||
|
import com.bnyer.common.swagger.annotation.EnableCustomSwagger2; |
||||
|
import org.springframework.boot.SpringApplication; |
||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
|
import org.springframework.scheduling.annotation.EnableAsync; |
||||
|
|
||||
|
/** |
||||
|
* ai模块 |
||||
|
* |
||||
|
* @author penny |
||||
|
*/ |
||||
|
@EnableCustomConfig |
||||
|
@EnableCustomSwagger2 |
||||
|
@EnableRyFeignClients |
||||
|
@SpringBootApplication |
||||
|
@EnableAsync |
||||
|
public class BnyerAiApplication |
||||
|
{ |
||||
|
public static void main(String[] args) |
||||
|
{ |
||||
|
SpringApplication.run(BnyerAiApplication.class, args); |
||||
|
System.out.println("(♥◠‿◠)ノ゙ bnyerAi服务启动成功 ლ(´ڡ`ლ)゙ \n" + |
||||
|
"__________ \n" + |
||||
|
"\\______ \\ ____ ___.__. ___________ \n" + |
||||
|
" | | _// < | |/ __ \\_ __ \\\n" + |
||||
|
" | | \\ | \\___ \\ ___/| | \\/\n" + |
||||
|
" |______ /___| / ____|\\___ >__| \n" + |
||||
|
" \\/ \\/\\/ \\/ \n"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
package com.bnyer.ai.controller; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSON; |
||||
|
import com.bnyer.ai.service.ChatGptService; |
||||
|
import com.bnyer.common.core.domain.Feedback; |
||||
|
import com.bnyer.common.core.dto.FeedBackDto; |
||||
|
import com.bnyer.common.core.web.domain.AjaxResult; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import io.swagger.annotations.ApiParam; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
@Api(value = "【AI】接口",tags = "【AI】接口") |
||||
|
@RestController |
||||
|
@RequestMapping("/ai") |
||||
|
public class ChatGptController { |
||||
|
|
||||
|
@Autowired |
||||
|
private ChatGptService chatGptService; |
||||
|
|
||||
|
@ApiOperation(value="chat") |
||||
|
@PostMapping(value = "/chatWithGpt") |
||||
|
public AjaxResult chatWithGpt(){ |
||||
|
chatGptService.talkWithChatGpt(); |
||||
|
return AjaxResult.success(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,6 @@ |
|||||
|
package com.bnyer.ai.service; |
||||
|
|
||||
|
public interface ChatGptService { |
||||
|
|
||||
|
void talkWithChatGpt(); |
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
package com.bnyer.ai.service.impl; |
||||
|
|
||||
|
import com.bnyer.ai.service.ChatGptService; |
||||
|
import com.plexpt.chatgpt.ChatGPT; |
||||
|
import com.plexpt.chatgpt.entity.chat.ChatCompletion; |
||||
|
import com.plexpt.chatgpt.entity.chat.ChatCompletionResponse; |
||||
|
import com.plexpt.chatgpt.entity.chat.Message; |
||||
|
import com.plexpt.chatgpt.util.Proxys; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.net.Proxy; |
||||
|
import java.util.Arrays; |
||||
|
|
||||
|
@Service |
||||
|
@Slf4j |
||||
|
public class ChatGptServiceImpl implements ChatGptService { |
||||
|
@Override |
||||
|
public void talkWithChatGpt() { |
||||
|
Proxy proxy = Proxys.http("18.179.21.104", 21584); |
||||
|
ChatGPT chatGPT = ChatGPT.builder() |
||||
|
.apiKey("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") |
||||
|
.proxy(proxy) |
||||
|
.timeout(100000) |
||||
|
.apiHost("https://api.openai.com/") //反向代理地址
|
||||
|
.build() |
||||
|
.init(); |
||||
|
|
||||
|
Message system = Message.ofSystem("你现在是一个诗人,专门写七言绝句"); |
||||
|
Message message = Message.of("写一段七言绝句诗,题目是:火锅!"); |
||||
|
|
||||
|
ChatCompletion chatCompletion = ChatCompletion.builder() |
||||
|
.model(ChatCompletion.Model.GPT_3_5_TURBO.getName()) |
||||
|
.messages(Arrays.asList(system, message)) |
||||
|
.maxTokens(3000) |
||||
|
.temperature(0.9) |
||||
|
.build(); |
||||
|
ChatCompletionResponse response = chatGPT.chatCompletion(chatCompletion); |
||||
|
Message res = response.getChoices().get(0).getMessage(); |
||||
|
System.out.println(res); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
spring: |
||||
|
cloud: |
||||
|
nacos: |
||||
|
discovery: |
||||
|
# 服务注册地址 |
||||
|
server-addr: http://117.50.61.7:8848 |
||||
|
# 命名空间地址 |
||||
|
namespace: c4f53d8c-0a91-4249-a804-f16f543ec3b0 |
||||
|
# 命名空间分组 |
||||
|
group: dev |
||||
|
config: |
||||
|
# 配置中心地址 |
||||
|
server-addr: http://117.50.61.7:8848 |
||||
|
# 配置文件格式 |
||||
|
file-extension: yml |
||||
|
# 命名空间地址 |
||||
|
namespace: c4f53d8c-0a91-4249-a804-f16f543ec3b0 |
||||
|
# 命名空间分组 |
||||
|
group: dev |
||||
|
# 共享配置 |
||||
|
shared-configs: |
||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} |
||||
@ -0,0 +1,26 @@ |
|||||
|
spring: |
||||
|
cloud: |
||||
|
nacos: |
||||
|
discovery: |
||||
|
# 解决部署在不同服务器访问不到的问题,需暴露外网ip |
||||
|
ip: 81.69.47.31 |
||||
|
# 部署在不同服务器上的指定端口 |
||||
|
port: 9102 |
||||
|
# 服务注册地址 |
||||
|
server-addr: http://175.24.122.142:8848 |
||||
|
# 命名空间地址 |
||||
|
namespace: abfe8ee6-161b-4f8f-b61f-51663bbfa4f9 |
||||
|
# 命名空间分组 |
||||
|
group: grey |
||||
|
config: |
||||
|
# 配置中心地址 |
||||
|
server-addr: http://175.24.122.142:8848 |
||||
|
# 配置文件格式 |
||||
|
file-extension: yml |
||||
|
# 命名空间地址 |
||||
|
namespace: abfe8ee6-161b-4f8f-b61f-51663bbfa4f9 |
||||
|
# 命名空间分组 |
||||
|
group: grey |
||||
|
# 共享配置 |
||||
|
shared-configs: |
||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} |
||||
@ -0,0 +1,22 @@ |
|||||
|
spring: |
||||
|
cloud: |
||||
|
nacos: |
||||
|
discovery: |
||||
|
# 服务注册地址 |
||||
|
server-addr: http://192.168.3.100:6001 |
||||
|
# 命名空间地址 |
||||
|
namespace: b133c9e5-9f8d-4ed4-9ebd-95557802889f |
||||
|
# 命名空间分组 |
||||
|
group: prod |
||||
|
config: |
||||
|
# 配置中心地址 |
||||
|
server-addr: http://192.168.3.100:6001 |
||||
|
# 配置文件格式 |
||||
|
file-extension: yml |
||||
|
# 命名空间地址 |
||||
|
namespace: b133c9e5-9f8d-4ed4-9ebd-95557802889f |
||||
|
# 命名空间分组 |
||||
|
group: prod |
||||
|
# 共享配置 |
||||
|
shared-configs: |
||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} |
||||
@ -0,0 +1,22 @@ |
|||||
|
spring: |
||||
|
cloud: |
||||
|
nacos: |
||||
|
discovery: |
||||
|
# 服务注册地址 |
||||
|
server-addr: http://117.50.61.7:8848 |
||||
|
# 命名空间地址 |
||||
|
namespace: 1bf94455-a046-41e3-b7e4-c12fd11c3690 |
||||
|
# 命名空间分组 |
||||
|
group: test |
||||
|
config: |
||||
|
# 配置中心地址 |
||||
|
server-addr: http://117.50.61.7:8848 |
||||
|
# 配置文件格式 |
||||
|
file-extension: yml |
||||
|
# 命名空间地址 |
||||
|
namespace: 1bf94455-a046-41e3-b7e4-c12fd11c3690 |
||||
|
# 命名空间分组 |
||||
|
group: test |
||||
|
# 共享配置 |
||||
|
shared-configs: |
||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} |
||||
@ -0,0 +1,15 @@ |
|||||
|
# Tomcat |
||||
|
server: |
||||
|
port: 9105 |
||||
|
|
||||
|
# Spring |
||||
|
spring: |
||||
|
main: |
||||
|
#解决循环依赖问题 |
||||
|
allow-circular-references: true |
||||
|
application: |
||||
|
# 应用名称 |
||||
|
name: bnyer-ai |
||||
|
profiles: |
||||
|
# 环境配置 |
||||
|
active: dev |
||||
@ -0,0 +1,74 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<configuration scan="true" scanPeriod="60 seconds" debug="false"> |
||||
|
<!-- 日志存放路径 --> |
||||
|
<property name="log.path" value="logs/bnyer-ai" /> |
||||
|
<!-- 日志输出格式 --> |
||||
|
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" /> |
||||
|
|
||||
|
<!-- 控制台输出 --> |
||||
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender"> |
||||
|
<encoder> |
||||
|
<pattern>${log.pattern}</pattern> |
||||
|
</encoder> |
||||
|
</appender> |
||||
|
|
||||
|
<!-- 系统日志输出 --> |
||||
|
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
|
<file>${log.path}/info.log</file> |
||||
|
<!-- 循环政策:基于时间创建日志文件 --> |
||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
|
<!-- 日志文件名格式 --> |
||||
|
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern> |
||||
|
<!-- 日志最大的历史 60天 --> |
||||
|
<maxHistory>20</maxHistory> |
||||
|
</rollingPolicy> |
||||
|
<encoder> |
||||
|
<pattern>${log.pattern}</pattern> |
||||
|
</encoder> |
||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
|
<!-- 过滤的级别 --> |
||||
|
<level>INFO</level> |
||||
|
<!-- 匹配时的操作:接收(记录) --> |
||||
|
<onMatch>ACCEPT</onMatch> |
||||
|
<!-- 不匹配时的操作:拒绝(不记录) --> |
||||
|
<onMismatch>DENY</onMismatch> |
||||
|
</filter> |
||||
|
</appender> |
||||
|
|
||||
|
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
|
<file>${log.path}/error.log</file> |
||||
|
<!-- 循环政策:基于时间创建日志文件 --> |
||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
|
<!-- 日志文件名格式 --> |
||||
|
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern> |
||||
|
<!-- 日志最大的历史 60天 --> |
||||
|
<maxHistory>20</maxHistory> |
||||
|
</rollingPolicy> |
||||
|
<encoder> |
||||
|
<pattern>${log.pattern}</pattern> |
||||
|
</encoder> |
||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
|
<!-- 过滤的级别 --> |
||||
|
<level>ERROR</level> |
||||
|
<!-- 匹配时的操作:接收(记录) --> |
||||
|
<onMatch>ACCEPT</onMatch> |
||||
|
<!-- 不匹配时的操作:拒绝(不记录) --> |
||||
|
<onMismatch>DENY</onMismatch> |
||||
|
</filter> |
||||
|
</appender> |
||||
|
|
||||
|
<!-- 系统模块日志级别控制 --> |
||||
|
<logger name="com.bnyer" level="info" /> |
||||
|
<!-- Spring日志级别控制 --> |
||||
|
<logger name="org.springframework" level="warn" /> |
||||
|
|
||||
|
<root level="info"> |
||||
|
<appender-ref ref="console" /> |
||||
|
</root> |
||||
|
|
||||
|
<!--系统操作日志--> |
||||
|
<root level="info"> |
||||
|
<appender-ref ref="file_info" /> |
||||
|
<appender-ref ref="file_error" /> |
||||
|
</root> |
||||
|
</configuration> |
||||
Loading…
Reference in new issue