Interface IOpenAIClientHelper

All Known Implementing Classes:
OpenAIClientHelper

public interface IOpenAIClientHelper
Defines helper methods for interacting with the OpenAI service. This interface provides functionality for processing chat completion requests and parsing responses returned by the OpenAI API.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    The frequency penalty parameter for discouraging repeated phrases.
    static final int
    The maximum number of tokens allowed in a single request.
    static final double
    The presence penalty parameter for encouraging diverse topic generation.
    static final String
    The stop sequence used to terminate AI responses.
    static final double
    The temperature parameter for controlling the randomness of AI responses.
  • Method Summary

    Modifier and Type
    Method
    Description
    convertResponseToObject(String serializedResponseBody)
    Converts a serialized JSON response body from the OpenAI service into an IChatMessage.
    Creates an HTTP request body for a chat completion request to the OpenAI service.
  • Field Details

    • MAX_TOKENS

      static final int MAX_TOKENS
      The maximum number of tokens allowed in a single request.
      See Also:
    • TEMPERATURE

      static final double TEMPERATURE
      The temperature parameter for controlling the randomness of AI responses.
      See Also:
    • FREQUENCY_PENALTY

      static final double FREQUENCY_PENALTY
      The frequency penalty parameter for discouraging repeated phrases.
      See Also:
    • PRESENCE_PENALTY

      static final double PRESENCE_PENALTY
      The presence penalty parameter for encouraging diverse topic generation.
      See Also:
    • STOP

      static final String STOP
      The stop sequence used to terminate AI responses.
      See Also:
  • Method Details

    • convertResponseToObject

      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.
      Parameters:
      serializedResponseBody - the JSON response body as a String.
      Returns:
      the first IChatMessage extracted from the response.
    • createRequestBody

      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.
      Parameters:
      messages - a list of IChatMessage objects representing the chat context.
      Returns:
      a HttpRequest.BodyPublisher object containing the serialized request body.