本文正在加入 人工智能创作者搀扶打算
一、简介
自从OpenAI-ChatGPT火了之后,围绕OpenAI-ChatGPT的利用的话题就层出不穷,大模型人工智能的倒退是不可阻挡的趋势。lucy-chat是Java环境下疾速接入OpenAI-ChatGPT大模型人工智能的Java解决方案,咱们无奈发明工具,但也要更好的应用工具,该包简化了接入流程,k开发者能够十分不便的引入并应用ChatGPT提供的相干性能。
二、疾速接入
lucy-chat提供了两种模式接入服务,实现集成或者独立部署后能够拜访[部署地址]/doc.html调用相干接口。
2.1 创立我的项目
首先,应用IntelliJ IDEA构建一个Spring Boot工程。
接着,咱们启动我的项目,如果没有任何的报错。当咱们在浏览器中输出:http://localhost:8080时会输入如下内容。
2.2 Jar引入
在引入任何 Lucy系列依赖之前,须要实现jitpack镜像仓库的配置,如下。
<repositories> <repository> <id>jitpack.io</id> <url>https://www.jitpack.io</url> </repository></repositories>
而后,咱们在Spring Boot我的项目中增加lucy-chat依赖,以后默认1.0.0-r4。
<dependency> <groupId>com.gitee.kindear</groupId> <artifactId>lucy-chat</artifactId> <version>${version}</version></dependency>
增加依赖后,须要刷新一下我的项目能力实现lucy-chat依赖,如下图。
依赖实现之后,咱们关上我的项目的启动文件,而后启用 knife4j 文档,即须要在启动类上配置 @EnableKnife4j,并将启动的入口改为LucyChatApplication。
@EnableKnife4j@SpringBootApplicationpublic class DemoApplication { public static void main(String[] args) { SpringApplication.run(LucyChatApplication.class, args); }}
应用lucy-chat前,还须要在配置文件中配置如下文件信息。
spring.application.name=lucy-chat# 运行端口server.port=8080# swagger 匹配spring.mvc.pathmatch.matching-strategy=ant_path_matcher# chat-gpt api-key# 申请地址 https://platform.openai.com/account/api-keysopenai.chat.key=# chat-gpt proxy host# 配置代理地址 请参阅 https://www.v2ex.com/t/921689openai.chat.host=# 连接池最大连接数forest.max-connections=1000# 连贯超时工夫,单位为毫秒forest.connect-timeout=30000# 数据读取超时工夫,单位为毫秒forest.read-timeout=30000
要想可能失常拜访openAi的Api,须要去openAi的官网获取一个api-key,申请的链接为:
https://platform.openai.com/account/api-keys
2.3 独立服务
当然,咱们也能够将lucy-chat部署成独立的服务。首先,须要从开源地址下载我的项目:
git clone https://gitee.com/Kindear/lucy-chat
接着,批改POM文件中打包形式,即复原 <build>相干正文掉的内容,参考如下。
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring-boot.version}</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
而后参考上文的配置文件相干内容批改相干配置文件, 将我的项目中提供的 key为私人 key就能够了。
三、测试
实现配置后,能够拜访[服务地址]/chat/web进入WebChat页面,能够在其余前端利用中,间接应用Iframe标签引入。
lucy-chat源码:https://gitee.com/Kindear/lucy-chat