Skip to content

Commit 529a30a

Browse files
authored
send final streamed mesage (#533)
* send final streamed mesage * disable feedback buttons while streaming * fix disabled human feedback while streaming * bump version * update changelog
1 parent 52224fd commit 529a30a

File tree

5 files changed

+53
-34
lines changed

5 files changed

+53
-34
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1313
### Fixed
1414

1515
- Now properly displaying empty messages with inlined elements
16+
- Too many values to unpack error in langchain callback
17+
- Final streamed answer is not annotable with human feedback
1618

1719
## [0.7.600rc0] - 2023-11-08
1820

backend/chainlit/langchain/callbacks.py

+6
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,12 @@ def _on_run_update(self, run: Run) -> None:
602602
msg.language = language
603603
msg.prompt = current_prompt
604604
self._run_sync(msg.update())
605+
606+
if self.final_stream and self.has_streamed_final_answer:
607+
self.final_stream.content = completion
608+
self.final_stream.language = language
609+
self.final_stream.prompt = current_prompt
610+
self._run_sync(self.final_stream.send())
605611
return
606612

607613
outputs = run.outputs or {}

backend/chainlit/message.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ async def update(
7979
Update a message already sent to the UI.
8080
"""
8181
trace_event("update_message")
82-
82+
if self.streaming:
83+
self.streaming = False
8384
msg_dict = self.to_dict()
8485
asyncio.create_task(self._persist_update(msg_dict))
8586
await context.emitter.update_message(msg_dict)
@@ -129,11 +130,11 @@ async def send(self):
129130
if config.code.author_rename:
130131
self.author = await config.code.author_rename(self.author)
131132

132-
msg_dict = await self._create()
133-
134133
if self.streaming:
135134
self.streaming = False
136135

136+
msg_dict = await self._create()
137+
137138
await context.emitter.send_message(msg_dict)
138139

139140
return self.id

backend/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "chainlit"
3-
version = "0.7.601rc0"
3+
version = "0.7.602rc0"
44
keywords = ['LLM', 'Agents', 'gen ai', 'chat ui', 'chatbot ui', 'langchain']
55
description = "A faster way to build chatbot UIs."
66
authors = ["Chainlit"]

libs/components/src/messages/components/FeedbackButtons.tsx

+40-30
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ interface Props {
2929

3030
const FeedbackButtons = ({ message }: Props) => {
3131
const { onFeedbackUpdated } = useContext(MessageContext);
32-
3332
const [showFeedbackDialog, setShowFeedbackDialog] = useState<number>();
3433
const [commentInput, setCommentInput] = useState<string>();
3534

@@ -69,6 +68,8 @@ const FeedbackButtons = ({ message }: Props) => {
6968
}
7069
};
7170

71+
const disabled = !!message.streaming;
72+
7273
const buttons = useMemo(() => {
7374
const iconSx = {
7475
width: ICON_SIZE,
@@ -82,51 +83,60 @@ const FeedbackButtons = ({ message }: Props) => {
8283
const baseButtons = [
8384
() => (
8485
<Tooltip title="Negative feedback">
85-
<Button
86-
className={`negative-feedback-${feedback === -1 ? 'on' : 'off'}`}
87-
onClick={() => {
88-
handleFeedbackClick(-1);
89-
}}
90-
size="small"
91-
>
92-
<DownIcon sx={iconSx} />
93-
</Button>
86+
<span>
87+
<Button
88+
disabled={disabled}
89+
className={`negative-feedback-${feedback === -1 ? 'on' : 'off'}`}
90+
onClick={() => {
91+
handleFeedbackClick(-1);
92+
}}
93+
size="small"
94+
>
95+
<DownIcon sx={iconSx} />
96+
</Button>
97+
</span>
9498
</Tooltip>
9599
),
96100
() => (
97101
<Tooltip title="Positive feedback">
98-
<Button
99-
className={`positive-feedback-${feedback === 1 ? 'on' : 'off'}`}
100-
onClick={() => {
101-
handleFeedbackClick(1);
102-
}}
103-
size="small"
104-
>
105-
<UpIcon sx={iconSx} />
106-
</Button>
102+
<span>
103+
<Button
104+
disabled={disabled}
105+
className={`positive-feedback-${feedback === 1 ? 'on' : 'off'}`}
106+
onClick={() => {
107+
handleFeedbackClick(1);
108+
}}
109+
size="small"
110+
>
111+
<UpIcon sx={iconSx} />
112+
</Button>
113+
</span>
107114
</Tooltip>
108115
)
109116
];
110117

111118
if (comment) {
112119
baseButtons.push(() => (
113120
<Tooltip title="Feedback comment">
114-
<Button
115-
onClick={() => {
116-
setShowFeedbackDialog(feedback);
117-
setCommentInput(comment);
118-
}}
119-
className="feedback-comment-edit"
120-
size="small"
121-
>
122-
<StickyNote2Outlined sx={iconSx} />
123-
</Button>
121+
<span>
122+
<Button
123+
disabled={disabled}
124+
onClick={() => {
125+
setShowFeedbackDialog(feedback);
126+
setCommentInput(comment);
127+
}}
128+
className="feedback-comment-edit"
129+
size="small"
130+
>
131+
<StickyNote2Outlined sx={iconSx} />
132+
</Button>
133+
</span>
124134
</Tooltip>
125135
));
126136
}
127137

128138
return baseButtons;
129-
}, [feedback, comment]);
139+
}, [feedback, comment, disabled]);
130140

131141
return (
132142
<>

0 commit comments

Comments
 (0)