Chat with your data: Querychat

Chatting with your data

Demo: querychat R

library(dotenv)
library(shiny)
library(bslib)
library(querychat)

# 1. Configure querychat. This is where you specify the dataset and can also
#    override options like the greeting message, system prompt, model, etc.
querychat_config <- querychat_init(mtcars)

ui <- page_sidebar(
  # 2. Use querychat_sidebar(id) in a bslib::page_sidebar.
  #    Alternatively, use querychat_ui(id) elsewhere if you don't want your
  #    chat interface to live in a sidebar.
  sidebar = querychat_sidebar("chat"),
  DT::DTOutput("dt")
)

server <- function(input, output, session) {

  # 3. Create a querychat object using the config from step 1.
  querychat <- querychat_server("chat", querychat_config)

  output$dt <- DT::renderDT({
    # 4. Use the filtered/sorted data frame anywhere you wish, via the
    #    querychat$df() reactive.
    DT::datatable(querychat$df())
  })
}

shinyApp(ui, server)

Demo: querychat Python

import querychat
from chatlas import ChatAnthropic
from seaborn import load_dataset
from shiny.express import render

# data -----
titanic = load_dataset("titanic")


# chatbot setup -----
def create_chat_callback(system_prompt):
    return ChatAnthropic(system_prompt=system_prompt)


querychat_config = querychat.init(
    titanic,
    "titanic",
    # greeting="""Hello! I'm here to help you explore the Titanic dataset.""",
    create_chat_callback=create_chat_callback,
)

chat = querychat.server("chat", querychat_config)

# shiny application -----

# querychat UI
querychat.sidebar("chat")


# querychat filtered dataframe
@render.data_frame
def data_table():
    return chat["df"]()

Your turn: Change querrychat LLM

  • Modify one of the querychat examples and swap it with another model
  • Try using one of the local Ollama models and compare with your neighbor
10:00

Extending querychat -> sidebot

Python template example code:

shiny create --mode core --github jcheng5/py-databot