Skip to content

Commit 3c2bbf8

Browse files
cpsievertCopilot
andauthored
feat(pkg-py): Add new QueryChat() API; hard deprecate old API (#101)
* feat(pkg-py): First pass at new QueryChat() API * Update changelog * Fix format check * Officially deprecate old API * Fix import lint * Consistent wording * Fix TypeError message Co-authored-by: Copilot <[email protected]> * Address feedback * Update changelog * Fix kwargs passed twice issue * Hard deprecate old API; update to latest chatlas * 3.9 typing support * Simplify state * Update changelog * fix name shadowing * Address feedback --------- Co-authored-by: Copilot <[email protected]>
1 parent 375e621 commit 3c2bbf8

File tree

13 files changed

+992
-840
lines changed

13 files changed

+992
-840
lines changed

pkg-py/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [UNRELEASED]
99

10+
### Changes
11+
12+
* The entire functional API (i.e., `init()`, `sidebar()`, `server()`, etc) has been hard deprecated in favor of a simpler OOP-based API. Namely, the new `QueryChat()` class is now the main entry point (instead of `init()`) and has methods to replace old functions (e.g., `.sidebar()`, `.server()`, etc). (#101)
13+
14+
## [UNRELEASED]
15+
1016
### New features
1117

1218
* The `.sql` query and `.title` returned from `querychat.server()` are now reactive values, meaning you can now `.set()` their value, and `.df()` will update accordingly. (#98)

pkg-py/src/querychat/__init__.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
from querychat._greeting import greeting
2-
from querychat.querychat import (
3-
init,
4-
sidebar,
5-
system_prompt,
6-
)
7-
from querychat.querychat import (
8-
mod_server as server,
9-
)
10-
from querychat.querychat import (
11-
mod_ui as ui,
12-
)
1+
from ._deprecated import greeting, init, sidebar, system_prompt
2+
from ._deprecated import mod_server as server
3+
from ._deprecated import mod_ui as ui
4+
from ._querychat import QueryChat
135

14-
__all__ = ["greeting", "init", "server", "sidebar", "system_prompt", "ui"]
6+
__all__ = (
7+
"QueryChat",
8+
# TODO(lifecycle): Remove these deprecated functions when we reach v1.0
9+
"greeting",
10+
"init",
11+
"server",
12+
"sidebar",
13+
"system_prompt",
14+
"ui",
15+
)
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING, Any, Optional, Union
4+
5+
from shiny import Inputs, Outputs, Session, module, ui
6+
7+
if TYPE_CHECKING:
8+
from pathlib import Path
9+
10+
import chatlas
11+
import sqlalchemy
12+
from narwhals.stable.v1.typing import IntoFrame
13+
14+
from .datasource import DataSource
15+
16+
17+
def init(
18+
data_source: IntoFrame | sqlalchemy.Engine,
19+
table_name: str,
20+
*,
21+
greeting: Optional[str | Path] = None,
22+
data_description: Optional[str | Path] = None,
23+
extra_instructions: Optional[str | Path] = None,
24+
prompt_template: Optional[str | Path] = None,
25+
system_prompt_override: Optional[str] = None,
26+
client: Optional[Union[chatlas.Chat, str]] = None,
27+
):
28+
"""
29+
Initialize querychat with any compliant data source.
30+
31+
**Deprecated.** Use `QueryChat()` instead.
32+
"""
33+
raise RuntimeError("init() is deprecated. Use QueryChat() instead.")
34+
35+
36+
@module.ui
37+
def mod_ui(**kwargs) -> ui.TagList:
38+
"""
39+
Create the UI for the querychat component.
40+
41+
**Deprecated.** Use `QueryChat.ui()` instead.
42+
"""
43+
raise RuntimeError("mod_ui() is deprecated. Use QueryChat.ui() instead.")
44+
45+
46+
@module.server
47+
def mod_server(
48+
input: Inputs,
49+
output: Outputs,
50+
session: Session,
51+
querychat_config: Any,
52+
):
53+
"""
54+
Initialize the querychat server.
55+
56+
**Deprecated.** Use `QueryChat.server()` instead.
57+
"""
58+
raise RuntimeError("mod_server() is deprecated. Use QueryChat.server() instead.")
59+
60+
61+
def sidebar(
62+
id: str,
63+
width: int = 400,
64+
height: str = "100%",
65+
**kwargs,
66+
) -> ui.Sidebar:
67+
"""
68+
Create a sidebar containing the querychat UI.
69+
70+
**Deprecated.** Use `QueryChat.sidebar()` instead.
71+
"""
72+
raise RuntimeError("sidebar() is deprecated. Use QueryChat.sidebar() instead.")
73+
74+
75+
def system_prompt(
76+
data_source: DataSource,
77+
*,
78+
data_description: Optional[str | Path] = None,
79+
extra_instructions: Optional[str | Path] = None,
80+
categorical_threshold: int = 10,
81+
prompt_template: Optional[str | Path] = None,
82+
) -> str:
83+
"""
84+
Create a system prompt for the chat model based on a data source's schema
85+
and optional additional context and instructions.
86+
87+
**Deprecated.** Use `QueryChat.set_system_prompt()` instead.
88+
"""
89+
raise RuntimeError(
90+
"system_prompt() is deprecated. Use QueryChat.set_system_prompt() instead."
91+
)
92+
93+
94+
def greeting(
95+
querychat_config,
96+
*,
97+
generate: bool = True,
98+
stream: bool = False,
99+
**kwargs,
100+
) -> str | None:
101+
"""
102+
Generate or retrieve a greeting message.
103+
104+
**Deprecated.** Use `QueryChat.generate_greeting()` instead.
105+
"""
106+
raise RuntimeError(
107+
"greeting() is deprecated. Use QueryChat.generate_greeting() instead."
108+
)

pkg-py/src/querychat/_greeting.py

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)