@@ -55,18 +55,38 @@ def __init__(
55
55
on_click_source_info_callback : Optional [Callable ] = None ,
56
56
timestamp = None ,
57
57
show_timestamp = True ,
58
+ assistant_toolbar_visible = True , # hide the toolbar during streaming
58
59
):
59
60
css_class = f"message-content-{ self .role } "
60
61
self .content_pane = pn .pane .Markdown (
61
62
content ,
62
63
css_classes = ["message-content" , css_class ],
63
64
)
64
65
66
+ # we make this available on the instance so that we can update the value later
67
+ self .clipboard_button = CopyToClipboardButton (
68
+ value = self .content_pane .object , title = "Copy"
69
+ )
70
+
71
+ # we make this available on the instance so that we can toggle the visibility
72
+ self .assistant_toolbar = pn .Row (
73
+ self .clipboard_button ,
74
+ pn .widgets .Button (
75
+ name = "Source Info" ,
76
+ icon = "info-circle" ,
77
+ css_classes = ["source-info-button" ],
78
+ on_click = lambda event : self .on_click_source_info_callback (
79
+ event , self .sources
80
+ ),
81
+ ),
82
+ visible = assistant_toolbar_visible ,
83
+ )
84
+
65
85
if role == "assistant" :
66
86
assert sources is not None
67
87
object = pn .Column (
68
88
self .content_pane ,
69
- self ._copy_and_source_view_buttons () ,
89
+ self .assistant_toolbar ,
70
90
css_classes = ["message-content-assistant-with-buttons" ],
71
91
)
72
92
else :
@@ -92,22 +112,6 @@ def __init__(
92
112
)
93
113
self ._stylesheets .append ("css/chat_interface/chatmessage.css" )
94
114
95
- def _copy_and_source_view_buttons (self ) -> pn .Row :
96
- return pn .Row (
97
- CopyToClipboardButton (
98
- value = self .content_pane .object ,
99
- title = "Copy" ,
100
- ),
101
- pn .widgets .Button (
102
- name = "Source Info" ,
103
- icon = "info-circle" ,
104
- css_classes = ["source-info-button" ],
105
- on_click = lambda event : self .on_click_source_info_callback (
106
- event , self .sources
107
- ),
108
- ),
109
- )
110
-
111
115
# This cannot be a bound method, because it creates a reference cycle when trying
112
116
# to access the repr of the message. See
113
117
# https://github.com/Quansight/ragna/issues/359 for details.
@@ -288,11 +292,14 @@ async def chat_callback(
288
292
user = self .get_user_from_role ("assistant" ),
289
293
sources = answer ["sources" ],
290
294
on_click_source_info_callback = self .on_click_source_info_wrapper ,
295
+ assistant_toolbar_visible = False ,
291
296
)
292
297
yield message
293
298
294
299
async for chunk in answer_stream :
295
300
message .content_pane .object += chunk ["content" ]
301
+ message .clipboard_button .value = message .content_pane .object
302
+ message .assistant_toolbar .visible = True
296
303
297
304
except Exception :
298
305
yield RagnaChatMessage (
0 commit comments