---
title: "Greet Users"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Greet Users}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
eval = FALSE
)
```
```{r}
library(querychat)
library(palmerpenguins)
```
## Provide a greeting
When the querychat UI first appears, you will usually want it to greet the user with some basic instructions. By default, these instructions are auto-generated every time a user arrives. In a production setting with multiple users/visitors, this approach has some downsides: it's slower, uses more API tokens, and produces different results each time. Instead, you should create a greeting file and pass it when creating your `QueryChat` object:
```{r}
qc <- querychat(
penguins,
greeting = "greeting.md"
)
qc$app() # Launch the app
```
You can provide suggestions to the user by using the ` ` tag:
```markdown
* **Filter and sort the data:**
* Show only Adelie penguins
* Filter to penguins with body mass over 4000g
* Sort by flipper length from longest to shortest
* **Answer questions about the data:**
* What is the average bill length by species?
* How many penguins are in each island?
* Which species has the largest average body mass?
```
These suggestions appear in the greeting and automatically populate the chat text box when clicked.
## Generate a greeting
If you need help coming up with a greeting, you can use the `$generate_greeting()` method:
```{r}
library(querychat)
# Create QueryChat object with your dataset
qc <- querychat(penguins)
# Generate a greeting (this calls the LLM)
greeting_text <- qc$generate_greeting(echo = "text")
#> Hello! I'm here to help you explore and analyze the penguins dataset.
#> Here are some example prompts you can try:
#> ...
# Save it for reuse
writeLines(greeting_text, "penguins_greeting.md")
```
This approach generates a greeting once and saves it for reuse, avoiding the latency and cost of generating it for every user.
```{r}
# Then use the saved greeting in your app
querychat_app(
penguins,
greeting = "penguins_greeting.md"
)
```