Greet users
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 is slow, wasteful, and non-deterministic. Instead, you should create a greeting file and pass it when creating your QueryChat object:
titanic-app.py
from querychat import QueryChat
from querychat.data import titanic
from pathlib import Path
app_dir = Path(__file__).parent
qc = QueryChat(titanic(), "titanic", greeting=app_dir / "greeting.md")
app = qc.app()You can provide suggestions to the user by using the <span class="suggestion"> </span> tag:
* **Filter and sort the data:**
* <span class="suggestion">Show only survivors</span>
* <span class="suggestion">Filter to first class passengers under 30</span>
* <span class="suggestion">Sort by fare from highest to lowest</span>
* **Answer questions about the data:**
* <span class="suggestion">What was the survival rate by gender?</span>
* <span class="suggestion">What's the average age of children who survived?</span>
* <span class="suggestion">How many passengers were traveling alone?</span>These suggestions appear in the greeting and automatically populate the chat text box when clicked. You can see this behavior in our querychat template.
Generate a greeting
If you need help coming up with a greeting, you can use the .generate_greeting() method:
penguins-greeting.py
from palmerpenguins import load_penguins
from querychat import QueryChat
from pathlib import Path
# Create QueryChat object with your dataset
qc = QueryChat(load_penguins(), "penguins")
# Generate a greeting (this calls the LLM)
greeting_text = qc.generate_greeting()
#> 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
with open("penguins_greeting.md", "w") as f:
f.write(greeting_text)This approach generates a greeting once and saves it for reuse, avoiding the latency and cost of generating it for every user.
penguins-app.py
from palmerpenguins import load_penguins
from querychat import QueryChat
from pathlib import Path
# Then use the saved greeting in your app
app_dir = Path(__file__).parent
qc = QueryChat(
load_penguins(),
"penguins",
greeting=app_dir / "penguins_greeting.md",
)
app = qc.app()