Class OpenAIWrapper

java.lang.Object
com.intellijava.core.wrappers.OpenAIWrapper
All Implemented Interfaces:
ImageModelInterface, LanguageModelInterface

public class OpenAIWrapper extends Object implements LanguageModelInterface, ImageModelInterface
OpenAIWrapper is a wrapper for the OpenAI API, providing a simplified interface for interacting with the API.
Author:
github.com/Barqawiz
  • Constructor Details

    • OpenAIWrapper

      public OpenAIWrapper(String apiKey)
      OpenAIWrapper constructor with the API key
      Parameters:
      apiKey - openai API key, generate if from your account.
  • Method Details

    • generateText

      public BaseRemoteModel generateText(Map<String,Object> params) throws IOException
      Generate text from remote large language model based on the received prompt.
      Specified by:
      generateText in interface LanguageModelInterface
      Parameters:
      params - key and value for the API parameters model the model name, example: text-davinci-002. prompt text of the required action or the question. temperature higher values means more risks and creativity. maxTokens maximum size of the model input and output. For more GPT3 models: https://beta.openai.com/docs/models/gpt-3
      Returns:
      BaseRemoteModel for model response
      Throws:
      IOException - if there is an error when connecting to the OpenAI API.
    • generateChatText

      public BaseRemoteModel generateChatText(Map<String,Object> params) throws IOException
      Generate text from remote large language model based on the chat history.
      Parameters:
      params - key and value for the API parameters model the model name, example: gpt-3.5-turbo. messages a dictionary of role and prompt. temperature higher values means more risks and creativity. maxTokens maximum size of the model input and output. For more GPT3 models: https://beta.openai.com/docs/models/gpt-3
      Returns:
      BaseRemoteModel for model response
      Throws:
      IOException - if there is an error when connecting to the OpenAI API.
    • generateImages

      public BaseRemoteModel generateImages(Map<String,Object> params) throws IOException
      Generate image from openai image model.
      Specified by:
      generateImages in interface ImageModelInterface
      Parameters:
      params - should include prompt, n, size prompt: text of the required action or the question. n: number of the generated images. size: 256x256, 512x512, or 1024x1024.
      Returns:
      BaseRemoteModel
      Throws:
      IOException - if there is an error when connecting to the OpenAI API.