Skip to content

Commit bed4182

Browse files
cpsievertgadenbuie
andauthored
feat(pkg-r): website improvements (#162)
Co-authored-by: cpsievert <[email protected]> Co-authored-by: Garrick Aden-Buie <[email protected]>
1 parent c5e63ed commit bed4182

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1315
-560
lines changed

README.md

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,7 @@
1-
# querychat: Chat with your data in any language
1+
# querychat <a href="https://posit-dev.github.io/querychat/"><img src="pkg-r/man/figures/logo.png" align="right" height="138" alt="querychat website" /></a>
22

3-
querychat is a multilingual package that allows you to chat with your data using natural language queries. It's available for:
3+
QueryChat facilitates safe and reliable natural language exploration of tabular data, powered by SQL and large language models (LLMs).
44

5-
- [R - Shiny](pkg-r/README.md)
6-
- [Python - Shiny for Python](pkg-py/README.md)
5+
To get started, see the [official website](https://posit-dev.github.io/querychat/).
76

8-
## Overview
9-
10-
Imagine typing questions like these directly into your dashboard, and seeing the results in realtime:
11-
12-
* "Show only penguins that are not species Gentoo and have a bill length greater than 50mm."
13-
* "Show only blue states with an incidence rate greater than 100 per 100,000 people."
14-
* "What is the average mpg of cars with 6 cylinders?"
15-
16-
querychat is a drop-in component for Shiny that allows users to query a data frame using natural language. The results are available as a reactive data frame, so they can be easily used from Shiny outputs, reactive expressions, downloads, etc.
17-
18-
| ![Animation of a dashboard being filtered by a chatbot in the sidebar](animation.gif) |
19-
|-|
20-
21-
[Live demo](https://jcheng.shinyapps.io/sidebot/)
22-
23-
**This is not as terrible an idea as you might think!** We need to be very careful when bringing LLMs into data analysis, as we all know that they are prone to hallucinations and other classes of errors. querychat is designed to excel in reliability, transparency, and reproducibility by using this one technique: denying it raw access to the data, and forcing it to write SQL queries instead.
24-
25-
## How it works
26-
27-
### Powered by LLMs
28-
29-
querychat's natural language chat experience is powered by LLMs (like GPT-4o, Claude 3.5 Sonnet, etc.) that support function/tool calling capabilities.
30-
31-
### Powered by SQL
32-
33-
querychat doesn't send the raw data to the LLM, asking it to guess summary statistics. Instead, the LLM generates precise SQL queries to filter the data or directly calculate statistics. This is crucial for ensuring relability, transparency, and reproducibility:
34-
35-
- **Reliability:** Today's LLMs are excellent at writing SQL, but bad at direct calculation.
36-
- **Transparency:** querychat always displays the SQL to the user, so it can be vetted instead of blindly trusted.
37-
- **Reproducibility:** The SQL query can be easily copied and reused.
38-
39-
Currently, querychat uses DuckDB for its SQL engine when working with data frames. For database sources, it uses the native SQL dialect of the connected database.
40-
41-
## Language-specific Documentation
42-
43-
For detailed information on how to use querychat in your preferred language, see the language-specific READMEs:
44-
45-
- [R Documentation](pkg-r/README.md)
46-
- [Python Documentation](pkg-py/README.md)
7+
Or, the README for [R](pkg-r/README.md) and [Python](pkg-py/README.md).

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224
<h1 class="package-title">querychat</h1>
225225
<p class="package-subtitle">Chat with your data in any language</p>
226226
<p class="package-description">
227-
A drop-in component for Shiny that allows you to chat with your data using natural language queries.
227+
querychat facilitates safe and reliable natural language exploration of tabular data, powered by SQL and large language models (LLMs).
228228
Available for both R and Python.
229229
</p>
230230
<img src="animation.gif"

pkg-py/README.md

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,50 @@
1-
# querychat for Python
1+
# querychat <a href="https://posit-dev.github.io/querychat/py/"><img src="https://posit-dev.github.io/querychat/images/querychat.png" align="right" height="138" alt="querychat website" /></a>
22

3-
Please see [the package documentation site](https://posit-dev.github.io/querychat/py/index.html) for installation, setup, and usage.
3+
<p>
4+
<!-- badges start -->
5+
<a href="https://pypi.org/project/querychat/"><img alt="PyPI" src="https://img.shields.io/pypi/v/querychat?logo=python&logoColor=white&color=orange"></a>
6+
<a href="https://choosealicense.com/licenses/mit/"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="MIT License"></a>
7+
<a href="https://pypi.org/project/querychat"><img src="https://img.shields.io/pypi/pyversions/querychat.svg" alt="versions"></a>
8+
<a href="https://github.com/posit-dev/querychat"><img src="https://github.com/posit-dev/querychat/actions/workflows/test.yml/badge.svg?branch=main" alt="Python Tests"></a>
9+
<!-- badges end -->
10+
</p>
411

5-
If you are looking for querychat python examples,
6-
you can find them in the `examples/` directory.
12+
13+
QueryChat facilitates safe and reliable natural language exploration of tabular data, powered by SQL and large language models (LLMs). For analysts, it offers an intuitive web application where they can quickly ask questions of their data and receive verifiable data-driven answers. For software developers, QueryChat provides a comprehensive Python API to access core functionality -- including chat UI, generated SQL statements, resulting data, and more. This capability enables the seamless integration of natural language querying into bespoke data applications.
714

815
## Installation
916

10-
You can install the package from PyPI using pip:
17+
Install the latest stable release [from PyPI](https://pypi.org/project/querychat/):
1118

1219
```bash
1320
pip install querychat
1421
```
1522

16-
Or you can install querychat directly from GitHub:
23+
## Quick start
1724

18-
```bash
19-
pip install "querychat @ git+https://github.com/posit-dev/querychat"
25+
The main entry point is the [`QueryChat` class](https://posit-dev.github.io/querychat/py/reference/QueryChat.html). It requires a [data source](https://posit-dev.github.io/querychat/py/data-sources.html) (e.g., pandas, polars, etc) and a name for the data.
26+
27+
```python
28+
from querychat import QueryChat
29+
from querychat.data import titanic
30+
31+
qc = QueryChat(titanic(), "titanic")
32+
app = qc.app()
33+
# app.run()
2034
```
35+
36+
<p align="center">
37+
<img src="docs/images/quickstart.png" alt="QueryChat interface showing natural language queries" width="85%">
38+
</p>
39+
40+
## Custom apps
41+
42+
Build your own custom web apps with natural language querying capabilities, such as [this one](https://github.com/posit-conf-2025/llm/blob/main/_solutions/25_querychat/25_querychat_02-end-app.R) which provides a bespoke interface for exploring Airbnb listings:
43+
44+
<p align="center">
45+
<img src="docs/images/airbnb.png" alt="A custom app for exploring Airbnb listings, powered by QueryChat." width="85%">
46+
</p>
47+
48+
## Learn more
49+
50+
See the [website](https://posit-dev.github.io/querychat/py) to learn more.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from querychat.data import titanic
2+
from querychat.express import QueryChat
3+
from seaborn import load_dataset
4+
from shiny.express import render, ui
5+
6+
penguins = load_dataset("penguins")
7+
8+
qc_titanic = QueryChat(titanic(), "titanic")
9+
qc_penguins = QueryChat(penguins, "penguins")
10+
11+
with ui.sidebar():
12+
with ui.panel_conditional("input.navbar == 'Titanic'"):
13+
qc_titanic.ui()
14+
with ui.panel_conditional("input.navbar == 'Penguins'"):
15+
qc_penguins.ui()
16+
17+
with ui.nav_panel("Titanic"):
18+
@render.data_frame
19+
def titanic_table():
20+
return qc_titanic.df()
21+
22+
with ui.nav_panel("Penguins"):
23+
@render.data_frame
24+
def penguins_table():
25+
return qc_penguins.df()
26+
27+
ui.page_opts(
28+
id="navbar",
29+
title="Multiple Datasets with querychat",
30+
fillable=True,
31+
)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import plotly.express as px
2+
from faicons import icon_svg
3+
from querychat.data import titanic
4+
from querychat.express import QueryChat
5+
from shiny.express import render, ui
6+
from shinywidgets import render_plotly
7+
8+
qc = QueryChat(titanic(), "titanic")
9+
qc.sidebar()
10+
11+
with ui.layout_column_wrap(fill=False):
12+
with ui.value_box(showcase=icon_svg("users")):
13+
"Passengers"
14+
15+
@render.text
16+
def count():
17+
return str(len(qc.df()))
18+
19+
with ui.value_box(showcase=icon_svg("heart")):
20+
"Survival Rate"
21+
22+
@render.text
23+
def survival():
24+
rate = qc.df()["survived"].mean() * 100
25+
return f"{rate:.1f}%"
26+
27+
with ui.value_box(showcase=icon_svg("coins")):
28+
"Avg Fare"
29+
30+
@render.text
31+
def fare():
32+
avg = qc.df()["fare"].mean()
33+
return f"${avg:.2f}"
34+
35+
with ui.layout_columns():
36+
with ui.card():
37+
with ui.card_header():
38+
"Data Table"
39+
40+
@render.text
41+
def table_title():
42+
return f" - {qc.title()}" if qc.title() else ""
43+
44+
@render.data_frame
45+
def data_table():
46+
return qc.df()
47+
48+
with ui.card():
49+
ui.card_header("Survival by Class")
50+
51+
@render_plotly
52+
def survival_by_class():
53+
df = qc.df()
54+
summary = df.groupby("pclass")["survived"].mean().reset_index()
55+
return px.bar(
56+
summary,
57+
x="pclass",
58+
y="survived",
59+
labels={"pclass": "Class", "survived": "Survival Rate"},
60+
)
61+
62+
with ui.layout_columns():
63+
with ui.card():
64+
ui.card_header("Age Distribution")
65+
66+
@render_plotly
67+
def age_dist():
68+
df = qc.df()
69+
return px.histogram(df, x="age", nbins=30)
70+
71+
with ui.card():
72+
ui.card_header("Fare by Class")
73+
74+
@render_plotly
75+
def fare_by_class():
76+
df = qc.df()
77+
return px.box(df, x="pclass", y="fare", color="survived")
78+
79+
ui.page_opts(
80+
title="Titanic Survival Analysis",
81+
fillable=True,
82+
class_="bslib-page-dashboard",
83+
)

pkg-py/docs/_quarto.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ quartodoc:
7272
sidebar: reference/_sidebar.yml
7373
css: reference/_styles-quartodoc.css
7474
sections:
75-
- title: The Querychat class
75+
- title: The QueryChat class
7676
desc: The starting point for any QueryChat session
7777
contents:
7878
- name: QueryChat

0 commit comments

Comments
 (0)