Class OpenAIWellsOfWisdom

java.lang.Object
org.odinware.odinrunes.OpenAIWellsOfWisdom
All Implemented Interfaces:
WellsOfWisdom

public class OpenAIWellsOfWisdom extends Object implements WellsOfWisdom
The OllamaWellsOfWisdom class is responsible for constructing a valid HTTP request to the OpenAI gpt-3.5-turbo API for chat completions. It implements the WellsOfWisdom interface.

Before building the request, it takes a provided context, messages, and GPT settings, and constructs a JSON payload with the appropriate format required by the OpenAI GPT API.

Once the request is built, it includes the appropriate headers and authentication information. It returns the constructed request object.

  • Constructor Details

    • OpenAIWellsOfWisdom

      public OpenAIWellsOfWisdom()
  • Method Details

    • buildRequest

      public okhttp3.Request buildRequest(Context context, org.json.JSONArray odinMessages, org.json.JSONObject gptSettingsJsonObject) throws Exception
      Constructs an HTTP request to the OpenAI API using the provided context and OpenAI messages.
      Specified by:
      buildRequest in interface WellsOfWisdom
      Parameters:
      context - The context containing captured data.
      odinMessages - The messages exchanged between the user and the assistant.
      gptSettingsJsonObject - The settings for the GPT model.
      Returns:
      A built HTTP request object, or null if no new prompt is present.
      Throws:
      Exception - If there is an error while building the request.
    • executeRequest

      public okhttp3.Response executeRequest(okhttp3.Request request)
      Description copied from interface: WellsOfWisdom
      Executes a HTTP request and returns the Response object.
      Specified by:
      executeRequest in interface WellsOfWisdom
      Parameters:
      request - The context containing captured data and user options.
      Returns:
      A built HTTP response object, or null if no response.
    • readFromResponseStream

      public String readFromResponseStream(okhttp3.Response response)
      Description copied from interface: WellsOfWisdom
      Reads from the Response object.
      Specified by:
      readFromResponseStream in interface WellsOfWisdom
      Parameters:
      response - The response object.
      Returns:
      A string generated by the gpt provider and read from the HTTP response object.