Large Language Model Message Class
Large Language Model Message Class
Details
This class manages a history of messages and media interactions intended for use with large language models. It allows for adding messages, converting messages for API usage, and printing the history in a structured format.
Public fields
message_history
List to store all message interactions.
system_prompt
The system prompt used for a conversation
Methods
Method new()
Initializes the LLMMessage object with an optional system prompt.
Usage
LLMMessage$new(system_prompt = "You are a helpful assistant")
Returns
A new LLMMessage object. Deep Clone of LLMMessage Object
This method creates a deep copy of the LLMMessage
object. It ensures that
all internal states, including message histories and settings, are copied
so that the original object remains unchanged when mutations are applied
to the copy. This is particularly useful for maintaining immutability in
a tidyverse-like functional programming context where functions should
not have side effects on their inputs.
Method add_message()
Arguments
role
The role of the message sender (e.g., "user", "assistant").
content
The textual content of the message.
media
Optional; media content to attach to the message.
json
Is the message a raw string that contains a json response? Convert to API format
Converts the message history to a format suitable for various API calls.