经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » Java相关 » Spring Boot » 查看文章
springboot 接入 ChatGPT
来源:cnblogs  作者:Kindear  时间:2023/3/20 8:43:33  对本文有异议

项目地址

https://gitee.com/Kindear/lucy-chat

介绍

lucy-chat是接入OpenAI-ChatGPT大模型人工智能的Java解决方案,大模型人工智能的发展是不可阻挡的趋势,我们环境无法创造工具,但是也要更好的使用工具,该包简化了接入流程,可以非常方便的引入并使用ChatGPT相关功能。

接入方式

lucy-chat提供了两种形式接入服务,完成集成或者独立部署后可以访问[部署地址]/doc.html调用相关接口。

1. Jar引入

准备

在引入任何 Lucy系列依赖之前,需要完成jitpack镜像仓库的配置。

  1. <repositories>
  2. <repository>
  3. <id>jitpack.io</id>
  4. <url>https://www.jitpack.io</url>
  5. </repository>
  6. </repositories>

引入

根据版本号引入

当前默认1.0.0-r4

  1. <dependency>
  2. <groupId>com.gitee.kindear</groupId>
  3. <artifactId>lucy-chat</artifactId>
  4. <version>${version}</version>
  5. </dependency>

启动类

启用 knife4j 文档,需要在启动类上配置 @EnableKnife4j

  1. @EnableKnife4j
  2. @SpringBootApplication
  3. public class DemoApplication {
  4. public static void main(String[] args) {
  5. SpringApplication.run(LucyAdminApplication.class, args);
  6. }
  7. }

配置文件

使用 lucy-chat需要配置如下文件信息

  1. spring.application.name=lucy-chat
  2. # 运行端口
  3. server.port=8080
  4. # swagger 匹配
  5. spring.mvc.pathmatch.matching-strategy=ant_path_matcher
  6. # chat-gpt api-key
  7. # 申请地址 https://platform.openai.com/account/api-keys
  8. openai.chat.key=
  9. # chat-gpt proxy host
  10. # 配置代理地址 请参阅 https://www.v2ex.com/t/921689
  11. openai.chat.host=
  12. # 连接池最大连接数
  13. forest.max-connections=1000
  14. # 连接超时时间,单位为毫秒
  15. forest.connect-timeout=30000
  16. # 数据读取超时时间,单位为毫秒
  17. forest.read-timeout=30000

2. 独立服务

  1. 从开源地址下载项目
  1. git clone https://gitee.com/Kindear/lucy-chat
  1. 修改POM文件中打包方式,即恢复 <build>相关注释掉的内容
  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.apache.maven.plugins</groupId>
  5. <artifactId>maven-compiler-plugin</artifactId>
  6. <version>3.8.1</version>
  7. <configuration>
  8. <source>1.8</source>
  9. <target>1.8</target>
  10. <encoding>UTF-8</encoding>
  11. </configuration>
  12. </plugin>
  13. <plugin>
  14. <groupId>org.springframework.boot</groupId>
  15. <artifactId>spring-boot-maven-plugin</artifactId>
  16. <version>${spring-boot.version}</version>
  17. <executions>
  18. <execution>
  19. <goals>
  20. <goal>repackage</goal>
  21. </goals>
  22. </execution>
  23. </executions>
  24. </plugin>
  25. </plugins>
  26. </build>
  1. 修改相关配置文件, 参考上文的配置文件相关内容,项目中提供的 key为私人 key,随时会被替换。
  2. 打包项目并部署

效果

1. 对话

2. 图像绘制

3. 文本编辑

原文链接:https://www.cnblogs.com/masterchd/p/17233297.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号