| create_chat_session | R Documentation |
Factory function to create a new ChatSession object.
create_chat_session(
model = NULL,
system_prompt = NULL,
tools = NULL,
hooks = NULL,
max_steps = 10,
metadata = NULL,
agent = NULL
)
model |
A LanguageModelV1 object or model string ID. |
system_prompt |
Optional system prompt. |
tools |
Optional list of Tool objects. |
hooks |
Optional HookHandler object. |
max_steps |
Maximum tool execution steps. Default 10. |
metadata |
Optional session metadata (list). |
agent |
Optional Agent object to initialize from. |
A ChatSession object.
if (interactive()) {
# Create a chat session
chat <- create_chat_session(
model = "openai:gpt-4o",
system_prompt = "You are a helpful R programming assistant."
)
# Create from an existing agent
agent <- create_agent("MathAgent", "Does math", system_prompt = "You are a math wizard.")
chat <- create_chat_session(model = "openai:gpt-4o", agent = agent)
# Send messages
response <- chat$send("How do I read a CSV file?")
print(response$text)
# Continue the conversation (history is maintained)
response <- chat$send("What about Excel files?")
# Check stats
print(chat$stats())
# Save session
chat$save("my_session.rds")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.