| chat_session | R Documentation |
Creates a chat session that maintains conversation history internally. Returns a list of functions for interacting with the session.
chat_session(model = NULL, system_prompt = NULL,
provider = c("openai", "anthropic", "moonshot", "ollama"), ...)
model |
Character. Model name. |
system_prompt |
Character or NULL. System prompt. |
provider |
Character. Provider: "openai", "anthropic", "moonshot", or "ollama". |
... |
Additional parameters passed to chat(). |
A list with functions:
chat(message) |
Send a message, returns response text |
stream(message) |
Stream a response, returns response text |
stream_async(message) |
Async stream for shinychat (returns string) |
last_turn() |
Get the last response as list(role, text) |
history() |
Get full conversation history |
clear() |
Clear conversation history |
## Not run:
# Create a session
session <- chat_session(model = "gpt-4o", system_prompt = "You are helpful.")
# Chat (history maintained automatically)
response <- session$chat("Hello")
response2 <- session$chat("Tell me more")
# Get last response
last <- session$last_turn()
last$text
# Clear and start over
session$clear()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.