Class OpenAIClient
java.lang.Object
com.developer.nefarious.zjoule.plugin.chat.openai.OpenAIClient
- All Implemented Interfaces:
IAIClient
Implements the
IAIClient
interface for interacting with OpenAI-based models.
The OpenAIClient
handles chat completion requests, message creation,
and management of chat message history.-
Constructor Summary
ConstructorDescriptionOpenAIClient
(IAuthClient authClient, IMemoryMessageHistory memoryMessageHistory, IMemoryObject<String> memoryResourceGroup, IMemoryObject<Deployment> memoryDeployment, IOpenAIClientHelper openAIClientHelper) Constructs a newOpenAIClient
with the required dependencies. -
Method Summary
Modifier and TypeMethodDescriptionchatCompletion
(List<IChatMessage> messages) Sends a chat completion request to the OpenAI service and retrieves the AI-generated response.createMessage
(Role role, String userPrompt) Creates a chat message with the specified role and content.Retrieves the chat message history stored in memory.void
setMessageHistory
(List<IChatMessage> chatMessages) Stores the chat message history in memory.
-
Constructor Details
-
OpenAIClient
public OpenAIClient(IAuthClient authClient, IMemoryMessageHistory memoryMessageHistory, IMemoryObject<String> memoryResourceGroup, IMemoryObject<Deployment> memoryDeployment, IOpenAIClientHelper openAIClientHelper) Constructs a newOpenAIClient
with the required dependencies.- Parameters:
authClient
- the authentication client for retrieving tokens and service URLs.memoryMessageHistory
- the memory component for managing chat history.memoryResourceGroup
- the memory component for resource group information.memoryDeployment
- the memory component for deployment details.openAIClientHelper
- the helper for constructing requests and processing responses.
-
-
Method Details
-
chatCompletion
public IChatMessage chatCompletion(List<IChatMessage> messages) throws IOException, InterruptedException Sends a chat completion request to the OpenAI service and retrieves the AI-generated response.- Specified by:
chatCompletion
in interfaceIAIClient
- Parameters:
messages
- the list ofIChatMessage
objects representing the chat context.- Returns:
- the AI-generated response as an
IChatMessage
. - Throws:
IOException
- if an I/O error occurs during the request.InterruptedException
- if the operation is interrupted.
-
createMessage
Creates a chat message with the specified role and content.- Specified by:
createMessage
in interfaceIAIClient
- Parameters:
role
- the role of the message (e.g.,Role.USER
,Role.SYSTEM
).userPrompt
- the content of the message.- Returns:
- a new
OpenAIChatMessage
instance.
-
getMessageHistory
Retrieves the chat message history stored in memory.- Specified by:
getMessageHistory
in interfaceIAIClient
- Returns:
- a list of
IChatMessage
objects representing the chat history.
-
setMessageHistory
Stores the chat message history in memory.- Specified by:
setMessageHistory
in interfaceIAIClient
- Parameters:
chatMessages
- the list ofIChatMessage
objects to save as chat history.
-