Skip to content

Conversation

npelikan
Copy link
Contributor

@npelikan npelikan commented Sep 3, 2025

In the current version of querychat, any attempt by the sidebot to use the query() tool leads to the following error, when using a SQLAlchemySource.

/data/connect/apps/21/46/python/env/lib/python3.12/site-packages/chatlas/_chat.py:2260: ToolFailureWarning:
Calling tool 'query' led to an error: df must be a Narwhals DataFrame or LazyFrame
Traceback (most recent call last):
  File "/data/connect/apps/21/46/python/env/lib/python3.12/site-packages/chatlas/_chat.py", line 2237, in _invoke_tool_async
    res = await func(**request.arguments)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/connect/apps/21/46/python/env/lib/python3.12/site-packages/querychat/querychat.py", line 624, in query
    tbl_html = df_to_html(result_df, maxrows=5)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/connect/apps/21/46/python/env/lib/python3.12/site-packages/querychat/querychat.py", line 236, in df_to_html
    raise TypeError("df must be a Narwhals DataFrame or LazyFrame")
TypeError: df must be a Narwhals DataFrame or LazyFrame

This is because SQLAlchemySource.execute_query() ALWAYS returns a pandas DataFrame. This fixes that by converting pandas DataFrames (or other compliant objects) to Narwhals.

jcheng5 and others added 30 commits April 3, 2025 22:47
...instead of requiring explicit DataSource subclass creation
…provements

Plus some improvements:
- Cleaner .md file reading code in example apps
- Use GPT-4.1 by default, not GPT-4 😬
- Make sqlalchemy required
fix: No longer need to manually calls session$ns() with shinychat (#1
update to use s3 classes to simplify the code
npelikan and others added 27 commits June 27, 2025 08:12
Previously, the examples/app-database.R would shown an error on
startup because the initial query was "", which was then sent
as a SQL query to RSQLite. The get_lazy_data code path accounted
for the "" query, so we decided to make the eager code path just
call the lazy code path, then collect().

Also fixed a formatting issue with the table.
It seems like dbplyr tables-as-queries can be a bit... temperamental. This should fix that by explicitly declaring sql always.
@gadenbuie
Copy link
Contributor

Something went a bit awry with the commits in this PR (I think because you're using your main branch in your fork), so I started a new PR with the relevant commits in #79.

@gadenbuie gadenbuie closed this Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants