11from __future__ import annotations
22
3- import warnings
4- from copy import deepcopy
5- from dataclasses import dataclass
6- from typing import TYPE_CHECKING , Optional , Union
3+ from typing import TYPE_CHECKING , Any , Optional , Union
74
85from shiny import Inputs , Outputs , Session , module , ui
96
10- from ._querychat_impl import (
11- init_impl ,
12- server_impl ,
13- system_prompt_impl ,
14- ui_impl ,
15- )
16-
177if TYPE_CHECKING :
188 from pathlib import Path
199
2414 from .datasource import DataSource
2515
2616
27- @dataclass
28- class QueryChatConfig :
29- """
30- Configuration class for querychat.
31-
32- Warning:
33- -------
34- This class only exists as the return value of `init()`, which is deprecated,
35- and so will likely be removed in a future release. New code should use
36- `QueryChat()`.
37-
38- """
39-
40- data_source : DataSource
41- system_prompt : str
42- greeting : Optional [str ]
43- client : chatlas .Chat
44-
45-
4617def init (
4718 data_source : IntoFrame | sqlalchemy .Engine ,
4819 table_name : str ,
@@ -53,84 +24,38 @@ def init(
5324 prompt_template : Optional [str | Path ] = None ,
5425 system_prompt_override : Optional [str ] = None ,
5526 client : Optional [Union [chatlas .Chat , str ]] = None ,
56- ) -> QueryChatConfig :
27+ ):
5728 """
5829 Initialize querychat with any compliant data source.
5930
60- .. deprecated:: 0.3.0
61- Use :class:`QueryChat` instead. This function will be removed in
62- a future release.
63-
64- Warning:
65- -------
66- This function is deprecated and will be removed in a future release.
67- Use ``QueryChat()`` instead.
68-
31+ **Deprecated.** Use `QueryChat()` instead.
6932 """
70- warn_deprecated (
71- "init() is deprecated and will be removed in a future release. "
72- "Use QueryChat() instead."
73- )
74- res = init_impl (
75- data_source ,
76- table_name ,
77- greeting = greeting ,
78- data_description = data_description ,
79- extra_instructions = extra_instructions ,
80- prompt_template = prompt_template ,
81- system_prompt_override = system_prompt_override ,
82- client = client ,
83- )
84- return QueryChatConfig (** res )
33+ raise RuntimeError ("init() is deprecated. Use QueryChat() instead." )
8534
8635
8736@module .ui
8837def mod_ui (** kwargs ) -> ui .TagList :
8938 """
9039 Create the UI for the querychat component.
9140
92- .. deprecated:: 0.3.0
93- Use :meth:`QueryChat.ui()` instead. This function will be removed in
94- a future release.
95-
41+ **Deprecated.** Use `QueryChat.ui()` instead.
9642 """
97- warn_deprecated (
98- "ui() is deprecated and will be removed in a future release. "
99- "Use QueryChat.ui() instead."
100- )
101- return ui_impl (** kwargs )
43+ raise RuntimeError ("mod_ui() is deprecated. Use QueryChat.ui() instead." )
10244
10345
10446@module .server
10547def mod_server (
10648 input : Inputs ,
10749 output : Outputs ,
10850 session : Session ,
109- querychat_config : QueryChatConfig ,
51+ querychat_config : Any ,
11052):
11153 """
11254 Initialize the querychat server.
11355
114- .. deprecated:: 0.3.0
115- Use :meth:`QueryChat.server()` instead. This function will be removed in
116- a future release.
117-
56+ **Deprecated.** Use `QueryChat.server()` instead.
11857 """
119- warnings .warn (
120- "server() is deprecated and will be removed in a future release. "
121- "Use QueryChat.server() instead." ,
122- FutureWarning ,
123- stacklevel = 2 ,
124- )
125- return server_impl (
126- input ,
127- output ,
128- session ,
129- data_source = querychat_config .data_source ,
130- system_prompt = querychat_config .system_prompt ,
131- greeting = querychat_config .greeting ,
132- client = querychat_config .client ,
133- )
58+ raise RuntimeError ("mod_server() is deprecated. Use QueryChat.server() instead." )
13459
13560
13661def sidebar (
@@ -142,22 +67,9 @@ def sidebar(
14267 """
14368 Create a sidebar containing the querychat UI.
14469
145- .. deprecated:: 0.3.0
146- Use :meth:`QueryChat.sidebar()` instead. This function will be removed in
147- a future release.
148-
70+ **Deprecated.** Use `QueryChat.sidebar()` instead.
14971 """
150- warn_deprecated (
151- "sidebar() is deprecated and will be removed in a future release. "
152- "Use QueryChat.sidebar() instead."
153- )
154- return ui .sidebar (
155- mod_ui (id ),
156- width = width ,
157- height = height ,
158- class_ = "querychat-sidebar" ,
159- ** kwargs ,
160- )
72+ raise RuntimeError ("sidebar() is deprecated. Use QueryChat.sidebar() instead." )
16173
16274
16375def system_prompt (
@@ -172,28 +84,10 @@ def system_prompt(
17284 Create a system prompt for the chat model based on a data source's schema
17385 and optional additional context and instructions.
17486
175- .. deprecated:: 0.3.0
176- Use :meth:`QueryChat.set_system_prompt` instead. This function will be
177- removed in a future release.
178-
179- Warning:
180- -------
181- This function is deprecated and will be removed in a future release.
182- Use ``QueryChat.set_system_prompt()`` instead.
183-
87+ **Deprecated.** Use `QueryChat.set_system_prompt()` instead.
18488 """
185- warnings .warn (
186- "system_prompt() is deprecated and will be removed in a future release. "
187- "Use QueryChat.set_system_prompt() instead." ,
188- FutureWarning ,
189- stacklevel = 2 ,
190- )
191- return system_prompt_impl (
192- data_source ,
193- data_description = data_description ,
194- extra_instructions = extra_instructions ,
195- categorical_threshold = categorical_threshold ,
196- prompt_template = prompt_template ,
89+ raise RuntimeError (
90+ "system_prompt() is deprecated. Use QueryChat.set_system_prompt() instead."
19791 )
19892
19993
@@ -209,43 +103,6 @@ def greeting(
209103
210104 **Deprecated.** Use `QueryChat.generate_greeting()` instead.
211105 """
212- warn_deprecated (
213- "greeting() is deprecated and will be removed in a future release. "
214- "Use QueryChat.generate_greeting() instead."
215- )
216-
217- not_querychat_config = (
218- not hasattr (querychat_config , "client" )
219- and not hasattr (querychat_config , "greeting" )
220- and not hasattr (querychat_config , "system_prompt" )
221- )
222-
223- if not_querychat_config :
224- raise TypeError ("`querychat_config` must be a QueryChatConfig object." )
225-
226- greeting_text = querychat_config .greeting
227- has_greeting = greeting_text is not None and len (greeting_text .strip ()) > 0
228-
229- if has_greeting :
230- return greeting_text
231-
232- if not generate :
233- return None
234-
235- chat = deepcopy (querychat_config .client )
236- chat .system_prompt = querychat_config .system_prompt
237-
238- prompt = "Please give me a friendly greeting. Include a few sample prompts in a two-level bulleted list."
239-
240- if stream :
241- return chat .stream_async (prompt , ** kwargs )
242- else :
243- return chat .chat (prompt , ** kwargs )
244-
245-
246- def warn_deprecated (msg : str ) -> None :
247- warnings .warn (
248- msg ,
249- FutureWarning ,
250- stacklevel = 3 ,
106+ raise RuntimeError (
107+ "greeting() is deprecated. Use QueryChat.generate_greeting() instead."
251108 )
0 commit comments