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")
Method clone_deep()
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 to_api_format()
Convert to API format
Converts the message history to a format suitable for various API calls.
Method remove_message()
Remove a Message by Index
Removes a message from the message history at the specified index.
Method print()
Prints the current message history in a structured format.
By default, this function respects the tidyllm_print_metadata
option.
If the option is set to TRUE
, metadata for each message (if available) will be printed.
Users can override the default behavior by explicitly passing a value to the .meta
parameter.
Usage
LLMMessage$print(.meta = getOption("tidyllm_print_metadata", FALSE))