springboot 接入 ChatGPT

項目地址

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

介紹

lucy-chat是接入OpenAI-ChatGPT大模型人工智能的Java解決方案,大模型人工智能的發展是不可阻擋的趨勢,我們環境無法創造工具,但是也要更好的使用工具,該包簡化了接入流程,可以非常方便的引入並使用ChatGPT相關功能。

接入方式

lucy-chat提供了兩種形式接入服務,完成集成或者獨立部署後可以訪問[部署地址]/doc.html調用相關接口。

1. Jar引入

準備

在引入任何 Lucy系列依賴之前,需要完成jitpack鏡像倉庫的配置。

<repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://www.jitpack.io</url>
        </repository>
</repositories>

引入

根據版本號引入

當前默認1.0.0-r4

		<dependency>
			<groupId>com.gitee.kindear</groupId>
			<artifactId>lucy-chat</artifactId>
			<version>${version}</version>
		</dependency>

啓動類

啓用 knife4j 文檔,需要在啓動類上配置 @EnableKnife4j

@EnableKnife4j
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {

        SpringApplication.run(LucyAdminApplication.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


2. 獨立服務

  1. 從開源地址下載項目
git clone https://gitee.com/Kindear/lucy-chat
  1. 修改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>
  1. 修改相關配置文件, 參考上文的配置文件相關內容,項目中提供的 key爲私人 key,隨時會被替換。
  2. 打包項目並部署

效果

1. 對話

2. 圖像繪製

3. 文本編輯

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章