关于chatgpt:Spring-Boot-快速接入-ChatGPT

4次阅读

共计 2286 个字符,预计需要花费 6 分钟才能阅读完成。

本文正在加入 人工智能创作者搀扶打算

一、简介

自从 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
@SpringBootApplication
public 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-keys
openai.chat.key=
# chat-gpt proxy host
# 配置代理地址 请参阅 https://www.v2ex.com/t/921689
openai.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

正文完
 0