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 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:
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()Greetings with multiple tables
The generated greeting is schema-aware: querychat shares the schema of the relevant tables with the model so the opening message can describe the data it’s about to help you explore. Tables passed to QueryChat() are included in the greeting automatically.
Tables added later with add_table() or add_tables() are not included by default — pass include_in_greeting=True to opt them in:
qc = QueryChat(orders, "orders") # included automatically
qc.add_table(customers, "customers") # not included by default
qc.add_table(products, "products", include_in_greeting=True) # opted in
qc.greeter.tables
#> ['orders', 'products']For add_tables(), include_in_greeting can also be a list of names selecting which of the added tables to include:
qc.add_tables(engine, include_in_greeting=["orders", "customers"])You can also set the included tables directly, or swap in a custom greeting template, through qc.greeter:
qc.greeter.tables = ["orders", "customers"]
qc.greeter.prompt = "my-greeting-template.md"