Class OpenAIClientHelper

java.lang.Object
com.developer.nefarious.zjoule.plugin.chat.openai.OpenAIClientHelper
All Implemented Interfaces:
IOpenAIClientHelper

public class OpenAIClientHelper extends Object implements IOpenAIClientHelper
A helper class for the OpenAIClient that provides utility methods for creating HTTP request bodies and converting responses from the OpenAI service. Implements the IOpenAIClientHelper interface.
  • Constructor Details

    • OpenAIClientHelper

      public OpenAIClientHelper()
  • Method Details

    • convertResponseToObject

      public IChatMessage convertResponseToObject(String serializedResponseBody)
      Converts a serialized JSON response body from the OpenAI service into an IChatMessage. The method deserializes the response and extracts the first message returned by the AI.
      Specified by:
      convertResponseToObject in interface IOpenAIClientHelper
      Parameters:
      serializedResponseBody - the JSON response body as a String.
      Returns:
      the first IChatMessage extracted from the response.
    • createRequestBody

      public HttpRequest.BodyPublisher createRequestBody(List<IChatMessage> messages)
      Creates an HTTP request body for a chat completion request to the OpenAI service. The request body includes parameters such as:
      • Chat messages providing the context for the conversation.
      • Maximum number of tokens allowed for the response.
      • Temperature, frequency penalty, and presence penalty settings.
      • Stop sequences for terminating the response.
      Specified by:
      createRequestBody in interface IOpenAIClientHelper
      Parameters:
      messages - a list of IChatMessage objects representing the chat context.
      Returns:
      a HttpRequest.BodyPublisher object containing the serialized request body.