Package edu.tufts.hrilab.llm.openai
Class OpenaiClient
java.lang.Object
edu.tufts.hrilab.llm.openai.OpenaiClient
- All Implemented Interfaces:
LLMClient
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchatCompletion(Chat chat) Performs a chat completion using OpenAI with the set model and the given chat messages.chatCompletion(Chat chat, String model) Performs a chat completion using OpenAI with a provided model and the messages in the given chat.chatCompletion(Chat chat, List<ToolDefinition> tools) chatCompletion(String userPrompt) Generates a chat completion using the OpenAI service and a prompt string.chatCompletion(String userPrompt, String model) chatCompletion(String userPrompt, String model, String systemPrompt) chatCompletion(List<Message> messages) Performs an OpenAI chat completion using the default model and the given list of messages.chatCompletion(List<Message> messages, String model) Performs an OpenAI chat completion using the specified model and the given list of messages.chatCompletion(List<Message> messages, String model, List<ToolDefinition> tools) completion(OpenaiCompletionRequestBody requestBody) Sends a POST request to the OpenAI completion endpoint with the given request body and API key.completion(String userPrompt) Calls the OpenAI API to generate a completion based on the given prompt.completion(String userPrompt, String model) completion(String userPrompt, String model, String systemPrompt) voidsetEndpoint(String endpoint) voidvoidsetStopWords(String[] stopWords) voidsetTemperature(float temperature) streamingChatCompletion(Chat chat, List<ToolDefinition> tools, ai.thinkingrobots.trade.TRADEServiceInfo chunkHandlerService) visionCompletion(List<VisionMessage> vmessages) Performs an OpenAI chat completion using VisionMessage
-
Field Details
-
chatCompletionModels
-
-
Constructor Details
-
OpenaiClient
public OpenaiClient()
-
-
Method Details
-
setEndpoint
- Specified by:
setEndpointin interfaceLLMClient
-
setModel
-
setStopWords
- Specified by:
setStopWordsin interfaceLLMClient
-
setTemperature
public void setTemperature(float temperature) - Specified by:
setTemperaturein interfaceLLMClient
-
completion
Calls the OpenAI API to generate a completion based on the given prompt.- Specified by:
completionin interfaceLLMClient- Parameters:
userPrompt- the prompt used to generate the completion- Returns:
- an OpenaiCompletionResponse object representing the response from the OpenAI completion endpoint
-
completion
- Specified by:
completionin interfaceLLMClient
-
completion
- Specified by:
completionin interfaceLLMClient
-
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.- Specified by:
chatCompletionin interfaceLLMClient- Parameters:
userPrompt- the prompt string provided by the user- Returns:
- the OpenaiChatCompletionResponse containing the completed chat.
-
chatCompletion
- Specified by:
chatCompletionin interfaceLLMClient
-
chatCompletion
- Specified by:
chatCompletionin interfaceLLMClient
-
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.- Specified by:
chatCompletionin interfaceLLMClient- 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.- Specified by:
chatCompletionin interfaceLLMClient- Parameters:
chat- the chat containing the messages to use for the completion- Returns:
- an OpenaiChatCompletionResponse object representing the response from OpenAI
-
chatCompletion
-
chatCompletion
Performs a chat completion using OpenAI with a provided model and the messages in the given chat.- Specified by:
chatCompletionin interfaceLLMClient- Parameters:
chat- the chat containing the messages to use for the completionmodel- the model to use for the completion- Returns:
- an OpenaiChatCompletionResponse object representing the response from OpenAI
-
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
-
streamingChatCompletion
public Completion streamingChatCompletion(Chat chat, List<ToolDefinition> tools, ai.thinkingrobots.trade.TRADEServiceInfo chunkHandlerService)
-