Class OpenAIService

java.lang.Object
io.codemodder.plugins.llm.OpenAIService

public class OpenAIService extends Object
A custom service class to wrap the OpenAIClient
  • Method Details

    • fromOpenAI

      public static OpenAIService fromOpenAI(String token)
      Creates a new OpenAIService instance with the given OpenAI token.
      Parameters:
      token - the token to use
      Returns:
      the new instance
    • fromAzureOpenAI

      public static OpenAIService fromAzureOpenAI(String token, String endpoint)
      Creates a new OpenAIService instance with the given Azure OpenAI token and endpoint.
      Parameters:
      token - the token to use
      endpoint - the endpoint to use
      Returns:
      the new instance
    • noServiceAvailable

      public static OpenAIService noServiceAvailable()
    • isServiceAvailable

      public boolean isServiceAvailable()
      Returns whether the service is available.
      Returns:
      whether the service is available
    • providerName

      public String providerName()
    • getJSONCompletion

      public String getJSONCompletion(List<com.azure.ai.openai.models.ChatRequestMessage> messages, Model modelOrDeploymentName)
      Gets the completion for the given messages.
      Parameters:
      messages - the messages
      modelOrDeploymentName - the model or deployment name
      Returns:
      the completion
    • getResponseForPrompt

      public <T> T getResponseForPrompt(List<com.azure.ai.openai.models.ChatRequestMessage> messages, Model modelName, Class<T> responseType) throws IOException
      Returns an object of the given type based on the completion for the given messages.
      Parameters:
      messages - the messages
      modelName - the model name
      Returns:
      the completion
      Throws:
      IOException