Create a QueryChat object for exploring GEO
metadata with an LLM. Use geo_chat() to create the chat object,
geo_shiny() to launch the Shiny app, and geo_console() to start a console
chat.
Arguments
- client
Optional chat client. Can be:
An ellmer::Chat object
A string to pass to
ellmer::chat()(e.g.,"openai/gpt-4o")NULL(default): Uses thequerychat.clientoption, theQUERYCHAT_CLIENTenvironment variable, or defaults toellmer::chat_openai()
- data_source
A data.frame or a database connection containing GEO metadata, typically from
geo_meta()orgeo_search().- table_name
A string specifying the table name to use in SQL queries. If
data_sourceis a data.frame, this is the name to refer to it by in queries (typically the variable name). If not provided, will be inferred from the variable name for data.frame inputs. For database connections, this parameter is required.- ...
Arguments passed on to
querychat::querychatidOptional module ID for the QueryChat instance. If not provided, will be auto-generated from
table_name. The ID is used to namespace the Shiny module.greetingOptional initial message to display to users. Can be a character string (in Markdown format) or a file path. If not provided, a greeting will be generated at the start of each conversation using the LLM, which adds latency and cost. Use
$generate_greeting()to create a greeting to save and reuse.toolsWhich querychat tools to include in the chat client, by default.
"filter"includes the tools for filtering and resetting the dashboard and"query"includes the tool for executing SQL queries. Usetools = "filter"when you only want the dashboard filtering tools, or when you want to disable the querying tool entirely to prevent the LLM from seeing any of the data in your dataset. The legacy name"update"is still accepted as an alias for"filter".data_descriptionOptional description of the data in plain text or Markdown. Can be a string or a file path. This provides context to the LLM about what the data represents.
categorical_thresholdFor text columns, the maximum number of unique values to consider as a categorical variable. Default is 20.
extra_instructionsOptional additional instructions for the chat model in plain text or Markdown. Can be a string or a file path.
cleanupWhether or not to automatically run
$cleanup()when the Shiny session/app stops. By default, cleanup only occurs ifQueryChatis created within a Shiny app. Set toTRUEto always clean up, orFALSEto never clean up automatically.In
querychat_app(), in-memory databases created for data frames are always cleaned up.bookmark_storeThe bookmarking storage method. Passed to
shiny::enableBookmarking(). If"url"or"server", the chat state (including current query) will be bookmarked. Default is"url".
Value
A QueryChat object configured with
data_source, an LLM client, and GEO-specific instructions.
Details
geo_chat() intentionally does not serialize all rows or build a large data
prompt. Instead, it delegates schema summarization, SQL querying, and
dashboard filtering to QueryChat.
The three exported helpers differ only in how far they take the
QueryChat workflow:
geo_chat()creates and returns theQueryChatobject. Use it when you want to inspect the generated prompt, customize the object, embed it in another Shiny app, or launch the app/console later withqc$app()orqc$console().geo_shiny()creates the sameQueryChatobject and immediately launches its Shiny app. Use it for interactive browser-based filtering and exploration.geo_console()creates the sameQueryChatobject and immediately starts its console chat. Use it for command-line exploration without opening a Shiny app.
The default instructions guide the assistant to query, and filter GEO metadata, identify relevant studies.
Examples
if (requireNamespace("querychat", quietly = TRUE) &&
requireNamespace("duckdb", quietly = TRUE)) {
records <- data.frame(
Accession = c("GSE1", "GSE2"),
Title = c("human diabetes study", "mouse liver study"),
Type = c("Expression profiling by array", "RNA-seq"),
Samples = c(12L, 8L)
)
chat <- geo_chat(NULL, records, cleanup = TRUE)
chat$cleanup()
}