shinychat 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- shinychat/__version.py +2 -2
- shinychat/_chat.py +15 -28
- shinychat/_chat_normalize.py +4 -0
- shinychat/_chat_types.py +8 -4
- {shinychat-0.2.0.dist-info → shinychat-0.2.2.dist-info}/METADATA +1 -1
- {shinychat-0.2.0.dist-info → shinychat-0.2.2.dist-info}/RECORD +8 -8
- {shinychat-0.2.0.dist-info → shinychat-0.2.2.dist-info}/WHEEL +0 -0
- {shinychat-0.2.0.dist-info → shinychat-0.2.2.dist-info}/licenses/LICENSE +0 -0
shinychat/__version.py
CHANGED
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
28
28
|
commit_id: COMMIT_ID
|
29
29
|
__commit_id__: COMMIT_ID
|
30
30
|
|
31
|
-
__version__ = version = '0.2.
|
32
|
-
__version_tuple__ = version_tuple = (0, 2,
|
31
|
+
__version__ = version = '0.2.2'
|
32
|
+
__version_tuple__ = version_tuple = (0, 2, 2)
|
33
33
|
|
34
34
|
__commit_id__ = commit_id = None
|
shinychat/_chat.py
CHANGED
@@ -22,7 +22,7 @@ from weakref import WeakValueDictionary
|
|
22
22
|
|
23
23
|
from htmltools import (
|
24
24
|
HTML,
|
25
|
-
|
25
|
+
HTMLDependency,
|
26
26
|
Tag,
|
27
27
|
TagAttrValue,
|
28
28
|
TagChild,
|
@@ -595,6 +595,7 @@ class Chat:
|
|
595
595
|
* A dictionary with `content` and `role` keys. The `content` key can contain
|
596
596
|
content as described above, and the `role` key can be "assistant" or
|
597
597
|
"user".
|
598
|
+
* More generally, any type registered with :func:`shinychat.message_content`.
|
598
599
|
|
599
600
|
**NOTE:** content may include specially formatted **input suggestion** links
|
600
601
|
(see note below).
|
@@ -829,6 +830,7 @@ class Chat:
|
|
829
830
|
* A dictionary with `content` and `role` keys. The `content` key can contain
|
830
831
|
content as described above, and the `role` key can be "assistant" or
|
831
832
|
"user".
|
833
|
+
* More generally, any type registered with :func:`shinychat.message_content_chunk`.
|
832
834
|
|
833
835
|
**NOTE:** content may include specially formatted **input suggestion** links
|
834
836
|
(see note below).
|
@@ -1588,7 +1590,9 @@ class ChatExpress(Chat):
|
|
1588
1590
|
def ui(
|
1589
1591
|
self,
|
1590
1592
|
*,
|
1591
|
-
messages: Optional[
|
1593
|
+
messages: Optional[
|
1594
|
+
Iterable[str | TagChild | ChatMessageDict | ChatMessage | Any]
|
1595
|
+
] = None,
|
1592
1596
|
placeholder: str = "Enter a message...",
|
1593
1597
|
width: CssUnit = "min(680px, 100%)",
|
1594
1598
|
height: CssUnit = "auto",
|
@@ -1690,12 +1694,14 @@ class ChatExpress(Chat):
|
|
1690
1694
|
def chat_ui(
|
1691
1695
|
id: str,
|
1692
1696
|
*,
|
1693
|
-
messages: Optional[
|
1697
|
+
messages: Optional[
|
1698
|
+
Iterable[str | TagChild | ChatMessageDict | ChatMessage | Any]
|
1699
|
+
] = None,
|
1694
1700
|
placeholder: str = "Enter a message...",
|
1695
1701
|
width: CssUnit = "min(680px, 100%)",
|
1696
1702
|
height: CssUnit = "auto",
|
1697
1703
|
fill: bool = True,
|
1698
|
-
icon_assistant: HTML | Tag | TagList
|
1704
|
+
icon_assistant: Optional[HTML | Tag | TagList] = None,
|
1699
1705
|
**kwargs: TagAttrValue,
|
1700
1706
|
) -> Tag:
|
1701
1707
|
"""
|
@@ -1722,6 +1728,7 @@ def chat_ui(
|
|
1722
1728
|
interpreted as markdown as long as they're not inside HTML.
|
1723
1729
|
* A dictionary with `content` and `role` keys. The `content` key can contain a
|
1724
1730
|
content as described above, and the `role` key can be "assistant" or "user".
|
1731
|
+
* More generally, any type registered with :func:`shinychat.message_content`.
|
1725
1732
|
|
1726
1733
|
**NOTE:** content may include specially formatted **input suggestion** links
|
1727
1734
|
(see :method:`~shiny.ui.Chat.append_message` for more info).
|
@@ -1755,34 +1762,14 @@ def chat_ui(
|
|
1755
1762
|
if messages is None:
|
1756
1763
|
messages = []
|
1757
1764
|
for x in messages:
|
1758
|
-
|
1759
|
-
content: TagChild = None
|
1760
|
-
if not isinstance(x, dict):
|
1761
|
-
content = x
|
1762
|
-
else:
|
1763
|
-
if "content" not in x:
|
1764
|
-
raise ValueError(
|
1765
|
-
"Each message dictionary must have a 'content' key."
|
1766
|
-
)
|
1767
|
-
|
1768
|
-
content = x["content"]
|
1769
|
-
if "role" in x:
|
1770
|
-
role = x["role"]
|
1771
|
-
|
1772
|
-
# `content` is most likely a string, so avoid overhead in that case
|
1773
|
-
# (it's also important that we *don't escape HTML* here).
|
1774
|
-
if isinstance(content, str):
|
1775
|
-
ui: RenderedHTML = {"html": content, "dependencies": []}
|
1776
|
-
else:
|
1777
|
-
ui = TagList(content).render()
|
1778
|
-
|
1765
|
+
msg = message_content(x)
|
1779
1766
|
message_tags.append(
|
1780
1767
|
Tag(
|
1781
1768
|
"shiny-chat-message",
|
1782
|
-
|
1783
|
-
content=
|
1769
|
+
*[HTMLDependency(**d) for d in msg.html_deps],
|
1770
|
+
content=msg.content,
|
1784
1771
|
icon=icon_attr,
|
1785
|
-
data_role=role,
|
1772
|
+
data_role=msg.role,
|
1786
1773
|
)
|
1787
1774
|
)
|
1788
1775
|
|
shinychat/_chat_normalize.py
CHANGED
@@ -44,6 +44,8 @@ def message_content(message):
|
|
44
44
|
"""
|
45
45
|
if isinstance(message, (str, HTML)) or message is None:
|
46
46
|
return ChatMessage(content=message)
|
47
|
+
if isinstance(message, ChatMessage):
|
48
|
+
return message
|
47
49
|
if isinstance(message, dict):
|
48
50
|
if "content" not in message:
|
49
51
|
raise ValueError("Message dictionary must have a 'content' key")
|
@@ -90,6 +92,8 @@ def message_content_chunk(chunk):
|
|
90
92
|
"""
|
91
93
|
if isinstance(chunk, (str, HTML)) or chunk is None:
|
92
94
|
return ChatMessage(content=chunk)
|
95
|
+
if isinstance(chunk, ChatMessage):
|
96
|
+
return chunk
|
93
97
|
if isinstance(chunk, dict):
|
94
98
|
if "content" not in chunk:
|
95
99
|
raise ValueError("Chunk dictionary must have a 'content' key")
|
shinychat/_chat_types.py
CHANGED
@@ -4,7 +4,7 @@ from dataclasses import dataclass
|
|
4
4
|
from typing import Literal, TypedDict
|
5
5
|
|
6
6
|
from htmltools import HTML, Tag, TagChild, Tagifiable, TagList
|
7
|
-
from shiny.session import
|
7
|
+
from shiny.session import get_current_session
|
8
8
|
|
9
9
|
from ._typing_extensions import NotRequired
|
10
10
|
|
@@ -32,10 +32,14 @@ class ChatMessage:
|
|
32
32
|
# markdown), so only process it if it's not a string.
|
33
33
|
deps = []
|
34
34
|
if not isinstance(content, str):
|
35
|
-
session =
|
36
|
-
|
35
|
+
session = get_current_session()
|
36
|
+
if session and not session.is_stub_session():
|
37
|
+
res = session._process_ui(content)
|
38
|
+
deps = res["deps"]
|
39
|
+
else:
|
40
|
+
res = TagList(content).render()
|
41
|
+
deps = [d.as_dict() for d in res["dependencies"]]
|
37
42
|
content = res["html"]
|
38
|
-
deps = res["deps"]
|
39
43
|
|
40
44
|
if is_html:
|
41
45
|
# Code blocks with `{=html}` infostrings are rendered as-is by a
|
@@ -1,12 +1,12 @@
|
|
1
1
|
shinychat/__init__.py,sha256=wT_dA5RTwONRhUx2MpVKu9o-eLkSqUDX8sU9W2GQYLY,316
|
2
|
-
shinychat/__version.py,sha256=
|
3
|
-
shinychat/_chat.py,sha256=
|
2
|
+
shinychat/__version.py,sha256=o3ZTescp-19Z9cvBGq9dQnbppljgzdUYUf98Nov0spY,704
|
3
|
+
shinychat/_chat.py,sha256=xI32fiiDPx8UCGES1klfneqmxiEWdSWY2F0V0g42pd4,65831
|
4
4
|
shinychat/_chat_bookmark.py,sha256=E8okr1dkN4VNDtORyPVZnCXihmfV9jFGD6UQq4Z2p5s,3027
|
5
|
-
shinychat/_chat_normalize.py,sha256=
|
5
|
+
shinychat/_chat_normalize.py,sha256=zItuC1OXK-f_mqwfMPW2cWqlWyI8eKiHjBk_cUSA34s,9984
|
6
6
|
shinychat/_chat_normalize_chatlas.py,sha256=6iMObxHHSPZ0odWiWNTRUX52Vt8q0ocRaWvsdRjw9zk,12925
|
7
7
|
shinychat/_chat_provider_types.py,sha256=gsBPAs0uro1YcepS1xEiCXyh4JMhpE7kjs28_LSspk0,4328
|
8
8
|
shinychat/_chat_tokenizer.py,sha256=m-YS8j5TC5oJ2uTsIus04_NRYeldFbpHzsoanL2EA-E,1868
|
9
|
-
shinychat/_chat_types.py,sha256=
|
9
|
+
shinychat/_chat_types.py,sha256=52UGHq1WSMkf11snrC_cDx0q0DC_WXharN41nDorZLA,2920
|
10
10
|
shinychat/_html_deps_py_shiny.py,sha256=GeI_6dox592BalSmKdGTdQ3Nz9FgaqSOf1eJ-jxuX_k,1189
|
11
11
|
shinychat/_markdown_stream.py,sha256=-NgjYDdFDE6wcn3KJ3HLvACVdYs-QZBqV33NXjLPFfU,12490
|
12
12
|
shinychat/_typing_extensions.py,sha256=-PeNqGFdlfWF3Bg6oYCfeFzrh6gJ4WbwKxkrBFEPP4o,1685
|
@@ -25,7 +25,7 @@ shinychat/www/markdown-stream/markdown-stream.css,sha256=m-yRlzTkX36piqx1T8Nvx18
|
|
25
25
|
shinychat/www/markdown-stream/markdown-stream.css.map,sha256=afnnfIkD6AuwmHWnzYKDR2qpn8GBzBdqsQ8QY2wH5Xc,9191
|
26
26
|
shinychat/www/markdown-stream/markdown-stream.js,sha256=mcbHHYdKP1tSBAhV830UPOo36q4NBcs6VOvN_i3xC7g,272842
|
27
27
|
shinychat/www/markdown-stream/markdown-stream.js.map,sha256=P7IdHoJhgJ_M9VlIHhzmzwDurBvIIS3FAkfsV86cMz0,1119239
|
28
|
-
shinychat-0.2.
|
29
|
-
shinychat-0.2.
|
30
|
-
shinychat-0.2.
|
31
|
-
shinychat-0.2.
|
28
|
+
shinychat-0.2.2.dist-info/METADATA,sha256=YX1F15v16SQxoQBcHEOn24UJ0pbQSM_1bE58_4rStJM,3203
|
29
|
+
shinychat-0.2.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
30
|
+
shinychat-0.2.2.dist-info/licenses/LICENSE,sha256=oB2X1GZjjWFbXGMjbtPLWg29aj7BzjbecsnG7yEaY8U,1078
|
31
|
+
shinychat-0.2.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|