Class ChatGPT

java.lang.Object
com.anlavn.openai.ChatGPT

public class ChatGPT extends Object
The ChatGPT class supports to connect to OpenAI using API key.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Our GPT-3 models can understand and generate natural language.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ChatGPT(String APIKey)
    Create an ChatGPT service using API key.
  • Method Summary

    Modifier and Type
    Method
    Description
    final String
    Chat(String question)
    Use this method to chat with ChatGPT bot, just ask the question and you will get reply from chatGPT bot.
    Using model Davinci with max 256 token.
    final String
    Chat(String question, int maxTokens)
    Use this method to chat with ChatGPT bot, just ask the question, enter the max token will return and you will get reply from chatGPT bot.
    Using model Davinci.
    final String
    Chat(String question, ChatGPT.Model model)
    Use this method to chat with ChatGPT bot, just ask the question, required the model will answer you and you will get reply from chatGPT bot.
    Using max 256 token.
    final String
    Chat(String question, ChatGPT.Model model, int maxTokens)
    Use this method to chat with ChatGPT bot, just ask the question, required the model will answer you, enter the max token will return and you will get reply from chatGPT bot.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ChatGPT

      public ChatGPT(String APIKey)
      Create an ChatGPT service using API key. API key is a mandatory requirement. It has format "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".
      Login to OpenAI website with your account and access to https://beta.openai.com/account/api-keys to get API key.
      Parameters:
      APIKey - is your API key in OpenAI.
  • Method Details

    • Chat

      public final String Chat(String question)
      Use this method to chat with ChatGPT bot, just ask the question and you will get reply from chatGPT bot.
      Using model Davinci with max 256 token.
      Parameters:
      question - a string of any question you wonder. The longer the question, the more tokens it costs.
      Returns:
      a string choices of model with your question.
      See Also:
    • Chat

      public final String Chat(String question, int maxTokens)
      Use this method to chat with ChatGPT bot, just ask the question, enter the max token will return and you will get reply from chatGPT bot.
      Using model Davinci.
      Parameters:
      question - a string of any question you wonder. The longer the question, the more tokens it costs.
      maxTokens - is the maximum token limit will return. Other models only have 2048 while Davinci is 4000.
      Returns:
      a string choices of model with your question.
      See Also:
    • Chat

      public final String Chat(String question, ChatGPT.Model model)
      Use this method to chat with ChatGPT bot, just ask the question, required the model will answer you and you will get reply from chatGPT bot.
      Using max 256 token.
      Parameters:
      question - a string of any question you wonder. The longer the question, the more tokens it costs.
      model - is a model will answer your question. Ada is the fastest model, while Davinci is the most powerful.
      Returns:
      a string choices of model with your question.
      See Also:
    • Chat

      public final String Chat(String question, ChatGPT.Model model, int maxTokens)
      Use this method to chat with ChatGPT bot, just ask the question, required the model will answer you, enter the max token will return and you will get reply from chatGPT bot.
      Parameters:
      question - a string of any question you wonder. The longer the question, the more tokens it costs.
      model - is a model will answer your question. Ada is the fastest model, while Davinci is the most powerful.
      maxTokens - is the maximum token limit will return. Other models only have 2048 while Davinci is 4000.
      Returns:
      a string that the model choices to answer your question.