Initialize querychat with any compliant data source.
Parameters
Name
Type
Description
Default
data_source
IntoFrame | sqlalchemy.Engine
Either a Narwhals-compatible data frame (e.g., Polars or Pandas) or a SQLAlchemy engine containing the table to query against.
required
table_name
str
If a data_source is a data frame, a name to use to refer to the table in SQL queries (usually the variable name of the data frame, but it doesn’t have to be). If a data_source is a SQLAlchemy engine, the table_name is the name of the table in the database to query against.
required
greeting
str | Path
A string in Markdown format, containing the initial message. If a pathlib.Path object is passed, querychat will read the contents of the path into a string with .read_text().
None
data_description
str | Path
Description of the data in plain text or Markdown. If a pathlib.Path object is passed, querychat will read the contents of the path into a string with .read_text().
None
extra_instructions
str | Path
Additional instructions for the chat model. If a pathlib.Path object is passed, querychat will read the contents of the path into a string with .read_text().
None
prompt_template
Path
Path to or a string of a custom prompt file. If not provided, the default querychat template will be used. This should be a Markdown file that contains the system prompt template. The mustache template can use the following variables: - {db_engine}: The database engine used (e.g., “DuckDB”) - {schema}: The schema of the data source, generated by data_source.get_schema() - {data_description}: The optional data description provided - {extra_instructions}: Any additional instructions provided
None
system_prompt_override
str
A custom system prompt to use instead of the default. If provided, data_description, extra_instructions, and prompt_template will be silently ignored.
None
create_chat_callback
CreateChatCallback
A function that creates a chat object
None
Returns
Name
Type
Description
QueryChatConfig
A QueryChatConfig object that can be passed to server()