Package edu.tufts.hrilab.llm.openai
Class OpenaiClient
java.lang.Object
edu.tufts.hrilab.llm.openai.OpenaiClient
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchatCompletion(Symbol prompt) Generates a chat completion using the OpenAI service and a prompt string.chatCompletion(Symbol model, Symbol prompt) Generates a chat completion response using OpenAI's API with the specified model and prompt.chatCompletion(Symbol model, Chat chat) Performs a chat completion using OpenAI with a provided model and the messages in the given chat.chatCompletion(Symbol model, List<Message> messages) Performs an OpenAI chat completion using the specified model and the given list of messages.chatCompletion(Chat chat) Performs a chat completion using OpenAI with the set model and the given chat messages.chatCompletion(String prompt) chatCompletion(String model, Chat chat) chatCompletion(String model, String prompt) chatCompletion(String model, List<Message> messages) chatCompletion(List<Message> messages) Performs an OpenAI chat completion using the default model and the given list of messages.completion(Symbol prompt) completion(Symbol modelSym, Symbol prompt) completion(Symbol modelSym, Prompt prompt) Calls the OpenAI API to generate a completion based on the given model and prompt.completion(OpenaiCompletionRequestBody requestBody) Sends a POST request to the OpenAI completion endpoint with the given request body and API key.completion(Prompt prompt) Calls the OpenAI API to generate a completion based on the given prompt.completion(String prompt) completion(String modelStr, String prompt) voidsetEndpoint(String endpoint) voidvisionCompletion(List<VisionMessage> vmessages) Performs an OpenAI chat completion using VisionMessage
-
Field Details
-
chatCompletionModels
-
-
Constructor Details
-
OpenaiClient
public OpenaiClient()
-
-
Method Details
-
setEndpoint
-
setModel
-
completion
Calls the OpenAI API to generate a completion based on the given prompt.- Parameters:
prompt- the prompt used to generate the completion- Returns:
- an OpenaiCompletionResponse object representing the response from the OpenAI completion endpoint
-
completion
-
completion
-
completion
Calls the OpenAI API to generate a completion based on the given model and prompt.- Parameters:
modelSym- the model to use when generating a completionprompt- the prompt used to generate the completion- Returns:
- an OpenaiCompletionResponse object representing the response from the OpenAI completion endpoint
-
completion
-
completion
-
completion
Sends a POST request to the OpenAI completion endpoint with the given request body and API key. https://platform.openai.com/docs/api-reference/completions- Parameters:
requestBody- the request body to send to the OpenAI completion endpoint- Returns:
- an OpenaiCompletionResponse object representing the response from the OpenAI completion endpoint
-
chatCompletion
Generates a chat completion using the OpenAI service and a prompt string.- Parameters:
prompt- the prompt string provided by the user- Returns:
- the OpenaiChatCompletionResponse containing the completed chat.
-
chatCompletion
-
chatCompletion
Generates a chat completion response using OpenAI's API with the specified model and prompt. Creates a list of two messages, one from the system and one from the user, to use as input for the chat completion.- Parameters:
model- the model to use for the chat completionprompt- the text prompt to use for the chat completion- Returns:
- an OpenaiChatCompletionResponse object representing the response from the OpenAI API
-
chatCompletion
-
chatCompletion
Performs an OpenAI chat completion using the default model and the given list of messages. This method creates a new OpenaiChatRequestBody object with the default model and the provided messages.- Parameters:
messages- a list of messages to be sent for chat completion- Returns:
- an OpenaiChatCompletionResponse object representing the response from OpenAI.
-
chatCompletion
Performs a chat completion using OpenAI with the set model and the given chat messages.- Parameters:
chat- the chat containing the messages to use for the completion- Returns:
- an OpenaiChatCompletionResponse object representing the response from OpenAI
-
chatCompletion
Performs a chat completion using OpenAI with a provided model and the messages in the given chat.- Parameters:
model- the model to use for the completionchat- the chat containing the messages to use for the completion- Returns:
- an OpenaiChatCompletionResponse object representing the response from OpenAI
-
chatCompletion
-
chatCompletion
Performs an OpenAI chat completion using the specified model and the given list of messages. This method creates a new OpenaiChatRequestBody object with the provided model and messages.- Parameters:
model- the model to use for the chat completionmessages- a list of messages to be sent for chat completion- Returns:
- an OpenaiChatCompletionResponse object representing the response from OpenAI
-
chatCompletion
-
visionCompletion
Performs an OpenAI chat completion using VisionMessage- Parameters:
vmessages- a list of messages to be sent for chat completion- Returns:
- an OpenaiChatCompletionResponse object representing the response from OpenAI
-