Class GptOpsHelper

java.lang.Object
org.odinware.odinrunes.GptOpsHelper

public class GptOpsHelper extends Object
The GptOpsHelper class provides utility methods for building requests to chat-based language processing models, regardless of the specific GPT provider. It interacts with GPT models to perform chat-based language processing tasks and handles response streaming and JSON processing. This class can be used with different GPT providers by implementing the RequestBuilder interface to build custom requests. It also includes methods for counting words in a JSONArray and extracting valid JSON objects from a response stream. Basic Usage: 1. Use the buildCustomRequest method to build a custom Request object based on a specific RequestBuilder implementation. 2. Use the streamResponse method to stream the response from the GPT provider and process the partial responses in real-time.
  • Constructor Details

    • GptOpsHelper

      public GptOpsHelper()
  • Method Details

    • buildCustomRequest

      public static okhttp3.Request buildCustomRequest(WellsOfWisdom wellsOfWisdom, Context context, org.json.JSONArray odinMessages, org.json.JSONObject gptSettingsJsonObject) throws Exception
      Builds and returns a custom Request object based on the provided RequestBuilder implementation. This method allows for flexibility in constructing requests for different GPT providers, models, or configurations.
      Parameters:
      wellsOfWisdom - The RequestBuilder implementation to use for building the custom Request object.
      context - The Context object containing the captured data and chat history.
      odinMessages - The JSONArray containing the history of Odin's messages.
      Returns:
      A custom Request object based on the provided RequestBuilder implementation.
      Throws:
      Exception
    • streamResponse

      public static void streamResponse(TextHelper odinSays, Context context, org.json.JSONObject gptSettingsJsonObject)
      Streams the response from the GPT provider and processes the partial responses in real-time. The response data is written to the specified TextHelper object to capture the conversation history. This method handles the formatting of the response JSON and extracts the necessary information.
      Parameters:
      odinSays - The TextHelper object to write the response data to.
      context - The Context object containing the captured data and chat history.
    • countWordsInJSONArray

      public static int countWordsInJSONArray(org.json.JSONArray messages)
      Counts the number of words in a JSONArray. This method converts the JSONArray to a single JSON-formatted string and splits it into words using non-alphanumeric characters as delimiters.
      Parameters:
      messages - The JSONArray containing the chat messages.
      Returns:
      The number of words in the JSONArray.