shinychat 0.2.2__py3-none-any.whl → 0.2.4__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 +6 -11
- shinychat/_chat_normalize.py +9 -4
- shinychat/_chat_types.py +5 -16
- {shinychat-0.2.2.dist-info → shinychat-0.2.4.dist-info}/METADATA +1 -1
- {shinychat-0.2.2.dist-info → shinychat-0.2.4.dist-info}/RECORD +8 -8
- {shinychat-0.2.2.dist-info → shinychat-0.2.4.dist-info}/WHEEL +0 -0
- {shinychat-0.2.2.dist-info → shinychat-0.2.4.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.4'
|
32
|
+
__version_tuple__ = version_tuple = (0, 2, 4)
|
33
33
|
|
34
34
|
__commit_id__ = commit_id = None
|
shinychat/_chat.py
CHANGED
@@ -20,15 +20,7 @@ from typing import (
|
|
20
20
|
)
|
21
21
|
from weakref import WeakValueDictionary
|
22
22
|
|
23
|
-
from htmltools import
|
24
|
-
HTML,
|
25
|
-
HTMLDependency,
|
26
|
-
Tag,
|
27
|
-
TagAttrValue,
|
28
|
-
TagChild,
|
29
|
-
TagList,
|
30
|
-
css,
|
31
|
-
)
|
23
|
+
from htmltools import HTML, Tag, TagAttrValue, TagChild, TagList, css
|
32
24
|
from shiny import reactive
|
33
25
|
from shiny._deprecated import warn_deprecated
|
34
26
|
from shiny.bookmark import BookmarkState, RestoreState
|
@@ -1001,9 +993,12 @@ class Chat:
|
|
1001
993
|
if icon is not None:
|
1002
994
|
msg["icon"] = str(icon)
|
1003
995
|
|
996
|
+
# Register deps with the session and get the dictionary format
|
997
|
+
# for client-side rendering
|
1004
998
|
deps = message.html_deps
|
1005
999
|
if deps:
|
1006
|
-
|
1000
|
+
processed = self._session._process_ui(TagList(*deps))
|
1001
|
+
msg["html_deps"] = processed["deps"]
|
1007
1002
|
|
1008
1003
|
# print(msg)
|
1009
1004
|
|
@@ -1766,7 +1761,7 @@ def chat_ui(
|
|
1766
1761
|
message_tags.append(
|
1767
1762
|
Tag(
|
1768
1763
|
"shiny-chat-message",
|
1769
|
-
*
|
1764
|
+
*msg.html_deps,
|
1770
1765
|
content=msg.content,
|
1771
1766
|
icon=icon_attr,
|
1772
1767
|
data_role=msg.role,
|
shinychat/_chat_normalize.py
CHANGED
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
3
3
|
import sys
|
4
4
|
from functools import singledispatch
|
5
5
|
|
6
|
-
from htmltools import HTML, Tagifiable
|
6
|
+
from htmltools import HTML, Tagifiable
|
7
7
|
|
8
8
|
from ._chat_normalize_chatlas import tool_request_contents, tool_result_contents
|
9
9
|
from ._chat_types import ChatMessage
|
@@ -163,10 +163,15 @@ try:
|
|
163
163
|
|
164
164
|
@message_content.register
|
165
165
|
def _(message: Turn):
|
166
|
-
|
166
|
+
from chatlas import ContentToolResult
|
167
|
+
content = ""
|
167
168
|
for x in message.contents:
|
168
|
-
|
169
|
-
|
169
|
+
content += message_content(x).content
|
170
|
+
if all(isinstance(x, ContentToolResult) for x in message.contents):
|
171
|
+
role = "assistant"
|
172
|
+
else:
|
173
|
+
role = message.role
|
174
|
+
return ChatMessage(content=content, role=role)
|
170
175
|
|
171
176
|
@message_content_chunk.register
|
172
177
|
def _(chunk: Turn):
|
shinychat/_chat_types.py
CHANGED
@@ -3,8 +3,7 @@ from __future__ import annotations
|
|
3
3
|
from dataclasses import dataclass
|
4
4
|
from typing import Literal, TypedDict
|
5
5
|
|
6
|
-
from htmltools import HTML,
|
7
|
-
from shiny.session import get_current_session
|
6
|
+
from htmltools import HTML, HTMLDependency, TagChild, TagList
|
8
7
|
|
9
8
|
from ._typing_extensions import NotRequired
|
10
9
|
|
@@ -26,28 +25,18 @@ class ChatMessage:
|
|
26
25
|
):
|
27
26
|
self.role: Role = role
|
28
27
|
|
29
|
-
is_html = isinstance(content, (Tag, TagList, HTML, Tagifiable))
|
30
|
-
|
31
28
|
# content _can_ be a TagChild, but it's most likely just a string (of
|
32
29
|
# markdown), so only process it if it's not a string.
|
33
30
|
deps = []
|
34
31
|
if not isinstance(content, str):
|
35
|
-
|
36
|
-
|
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"]]
|
42
|
-
content = res["html"]
|
43
|
-
|
44
|
-
if is_html:
|
32
|
+
ui = TagList(content).render()
|
33
|
+
content, deps = ui["html"], ui["dependencies"]
|
45
34
|
# Code blocks with `{=html}` infostrings are rendered as-is by a
|
46
35
|
# custom rendering method in markdown-stream.ts
|
47
36
|
content = f"\n\n````````{{=html}}\n{content}\n````````\n\n"
|
48
37
|
|
49
38
|
self.content = content
|
50
|
-
self.html_deps = deps
|
39
|
+
self.html_deps: list[HTMLDependency] = deps
|
51
40
|
|
52
41
|
|
53
42
|
# A message once transformed have been applied
|
@@ -58,7 +47,7 @@ class TransformedMessage:
|
|
58
47
|
role: Role
|
59
48
|
transform_key: Literal["content_client", "content_server"]
|
60
49
|
pre_transform_key: Literal["content_client", "content_server"]
|
61
|
-
html_deps: list[
|
50
|
+
html_deps: list[HTMLDependency] | None = None
|
62
51
|
|
63
52
|
@classmethod
|
64
53
|
def from_chat_message(cls, message: ChatMessage) -> "TransformedMessage":
|
@@ -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=NRw4Jle4n9v_DD2wtplRqflGCvX8OU5eAjycYY0vY3Y,704
|
3
|
+
shinychat/_chat.py,sha256=oe2-zdWGTpjkjzP_v7W96JcK40q_ONRx2QMHO5Xh5TY,65937
|
4
4
|
shinychat/_chat_bookmark.py,sha256=E8okr1dkN4VNDtORyPVZnCXihmfV9jFGD6UQq4Z2p5s,3027
|
5
|
-
shinychat/_chat_normalize.py,sha256=
|
5
|
+
shinychat/_chat_normalize.py,sha256=7mzVcb2MPGJpjbMIyrrbxTD0NZ727oB3l4f4k8h84Ls,10170
|
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=_4MyXhM4GKYhSi6TOWgrw0zEG5N7F3z2LIIze2tEa0w,2549
|
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.4.dist-info/METADATA,sha256=SSpgQOYwBRvMeqpu6yJnK4Z8mmJJH0C5hnJnqge98kg,3203
|
29
|
+
shinychat-0.2.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
30
|
+
shinychat-0.2.4.dist-info/licenses/LICENSE,sha256=oB2X1GZjjWFbXGMjbtPLWg29aj7BzjbecsnG7yEaY8U,1078
|
31
|
+
shinychat-0.2.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|