swordintent / chatgpt-web-api

A Java Version ChatGPT SDK
MIT License
39 stars 12 forks source link

chatgpt-web-api

A Java Version ChatGPT SDK

integrate with acheong08/ChatGPT, use official Api of openAI(2023.3.2).

update

2023.3.2 use official api, model is not free, but you have $18 free quota

pip3 install --upgrade revChatGPT

How TO

中文

Start a python server(python >= 3.7)

you will find it in src/main/resources/server.py, and run:

    pip3 install flask flask-restful
    pip3 install --upgrade revChatGPT
    python3 server.py

by default, it listen on http://127.0.0.1:5000

Import maven jar

https://search.maven.org/artifact/com.swordintent.chatgpt/web-api/

Maven

    <dependency>
      <groupId>com.swordintent.chatgpt</groupId>
      <artifactId>web-api</artifactId>
      <version>1.0.0</version>
    </dependency>

Gradle

    implementation 'com.swordintent.chatgpt:web-api:1.0.0'

Enjoy it in your project

  1. first, you can invoke chatgptClient.init(address, chatGptConfig) method to init client.
    ChatgptClient chatgptClient = ChatgptClientImpl.getInstance();
    ChatGptConfig chatGptConfig = ChatGptConfig.builder()
                                    .password("")
                                    .build();
    String address = "http://127.0.0.1:5000";
    chatgptClient.init(address, chatGptConfig);
  1. then you can invoke chat chatgptClient.chat(request) method to chat.
    //first round or reset multiple rounds
    ChatRequest request = ChatRequest.builder()
                                    .prompt(content)
                                    .conversationId(null)
                                    .build();

    ChatResponse response = chatgptClient.chat(request);
    //multiple rounds  
    ChatRequest request = ChatRequest.builder()
                                    .prompt(content)
                                    .conversationId(response.getConversationId())
                                    .build();
    ChatResponse response = chatgptClient.chat(request);
  1. Notice.