Spring Boot quick access to ChatGPT

This article is participating in the Artificial Intelligence Creator Support Program

1. Introduction

Since OpenAI-ChatGPT became popular, topics surrounding the application of OpenAI-ChatGPT have emerged one after another, and the development of large-scale artificial intelligence is an unstoppable trend. lucy-chat It is a Java solution for quickly accessing OpenAI-ChatGPT large-scale model artificial intelligence in the Java environment. We cannot create tools, but we need to use tools better. This package simplifies the access process, and k developers can easily introduce and Use the relevant functions provided by ChatGPT. the

2. Quick access

lucy-chat Two forms of access services are provided. After integration or independent deployment, you can visit [deployment address]/doc.html to call related interfaces.

2.1 Create a project

First, use IntelliJ IDEA to build a Spring Boot project.

Next, we start the project, if there are no errors. When we type in the browser: http://localhost:8080 will output the following.


2.2 Jar introduction

Before introducing any Lucy series dependencies, you need to complete the configuration of the jitpack mirror warehouse, as follows.


Then, we add the lucy-chat dependency to the Spring Boot project, which is currently 1.0.0-r4 by default.


After adding dependencies, you need to refresh the project to complete the lucy-chat dependencies, as shown below.

After the dependency is completed, we open the startup file of the project, and then enable the knife4j document, that is, we need to configure @EnableKnife4j on the startup class, and change the startup entry to LucyChatApplication.

public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(LucyChatApplication.class, args);

Before using lucy-chat, you need to configure the following file information in the configuration file.

# run port
# swagger match
# chat-gpt api-key
# Application address https://platform.openai.com/account/api-keys
# chat-gpt proxy host
# Configure proxy address, please refer to https://www.v2ex.com/t/921689
# The maximum number of connections in the connection pool
# Connection timeout, in milliseconds
# Data read timeout, in milliseconds

To be able to access openAi's Api normally, you need to go to openAi's official website to obtain an api-key. The link to apply is:


2.3 Independent Services

Of course, we can also deploy lucy-chat as an independent service. First, you need to download the project from the open source address:

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

Next, modify the packaging method in the POM file, that is, restore the commented out content related to <build>, refer to the following.


Then refer to the relevant content of the configuration file above to modify the relevant configuration file, and set the key provided in the project as a private key.


3. Test

After completing the configuration, you can visit [service address]/chat/web to enter the WebChat page, and you can directly use the Iframe tag to import it in other front-end applications.


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

Tags: ChatGPT

Posted by ivytony on Wed, 22 Mar 2023 16:38:13 +1030