add_message_to_active_history {PacketLLM} | R Documentation |
Adds a message to the active conversation's history
Description
Appends a message with the specified role and content to the history list of the currently active conversation. Handles automatic title generation on the first user message and locks the conversation model upon adding the first assistant message.
Usage
add_message_to_active_history(role, content)
Arguments
role |
Character string. The role of the message author, must be one of "user", "assistant", or "system". |
content |
Character string. The content of the message. |
Value
A list indicating the result of the operation. Possible structures:
- list(type = "title_set", new_title = "...")
: If this was the first
user message and the title was automatically set.
- list(type = "assistant_locked_model")
: If this was the first assistant
message, causing the model to be locked.
- list(type = "message_added")
: If a message was added without
triggering title setting or model locking.
- list(type = "error", message = "...")
: If an error occurred (e.g.,
no active conversation, invalid role, conversation vanished).
Examples
# Setup
reset_history_manager()
conv_add_id <- create_new_conversation(activate = TRUE, title = "Initial Title")
# Add first user message (should set title)
result1 <- add_message_to_active_history(role = "user", content = "This is the very first post.")
print("Result after first user message:")
print(result1)
print(paste("New Title:", get_conversation_title(conv_add_id)))
# Add another user message (should just add message)
result2 <- add_message_to_active_history(role = "user", content = "Another question.")
print("Result after second user message:")
print(result2)
# Add first assistant message (should lock model)
result3 <- add_message_to_active_history(role = "assistant", content = "Here is the answer.")
print("Result after first assistant message:")
print(result3)
print(paste("Is model locked?", is_conversation_started(conv_add_id)))
# Add system message (just adds message)
result4 <- add_message_to_active_history(role = "system", content = "System notification.")
print("Result after system message:")
print(result4)
# Check final history
print("Final history:")
print(get_conversation_history(conv_add_id))
# Clean up
reset_history_manager()