Giter VIP home page Giter VIP logo

chatgpt-web-api's Introduction

chatgpt-web-api

A Java Version ChatGPT SDK

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

How TO

中文

Start a python server(python >= 3.7)

you will find it in src/main/resources/server.py, and acheong08/ChatGPT is active,you need run pip3 install revChatGPT --upgrade frequently.

    pip3 install flask flask-restful
    pip3 install revChatGPT --upgrade
    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.
  • you need create your account firstly.
  • modify password, the password is your openAI's api-keys, you can find here.
  • set address to http://127.0.0.1:5000 or another.
    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.
  • in first round chat, conversationId would be null. when you want reset multiple rounds set them to null too.
    //first round or reset multiple rounds
    ChatRequest request = ChatRequest.builder()
                                    .prompt(content)
                                    .conversationId(null)
                                    .build();
    
    ChatResponse response = chatgptClient.chat(request);

  • if you want to chat multiple rounds. you need get conversationId from response and set them to next chat request.
    //multiple rounds  
    ChatRequest request = ChatRequest.builder()
                                    .prompt(content)
                                    .conversationId(response.getConversationId())
                                    .build();
    ChatResponse response = chatgptClient.chat(request);
  1. Notice.
  • the conversationId now is the full object of python chatbot object, so maybe it was huge.

  • you must set conversationId to null in your java program when you restart your python server.

chatgpt-web-api's People

Contributors

liuhe36 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.