if (FALSE) {
# Make sure to set your API key first
# Sys.setenv(OPENROUTER_API_KEY = "your_api_key_here")
# First turn of the conversation
first_turn <- get_llm_response(
user_prompt = "What are the three main benefits of using R for data analysis?",
model_id = "x-ai/grok-3-mini",
system_prompt = "You are a helpful assistant who provides concise answers."
)
cat("--- Initial Response ---\n")
cat(first_turn$response)
cat(paste0("\n--- Total Cost: $",
format(first_turn$cost$total_cost, scientific = FALSE), " ---\n"))
# Follow-up question using the context from the first turn
second_turn <- get_llm_response(
user_prompt = "Can you elaborate on the second benefit you mentioned?",
model_id = "x-ai/grok-3-mini",
context = first_turn$context
)
cat("\n\n--- Follow-up Response ---\n")
cat(second_turn$response)
cat(paste0("\n--- Total Cost: $", format(second_turn$cost$total_cost,
scientific = FALSE), " ---\n"))
}
Run the code above in your browser using DataLab