Skip to content

Commit d94b871

Browse files
authored
Release/1.1.300 (#1041)
* enhance conversation spacing and make copilot expandable * fix non ascii characters for chat profiles * add input streaming support
1 parent 7d2a5a7 commit d94b871

File tree

12 files changed

+72
-29
lines changed

12 files changed

+72
-29
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88

99
Nothing unreleased!
1010

11+
## [1.1.300rc3] - 2024-05-28
12+
13+
### Added
14+
15+
- Input streaming for tool calls
16+
1117
## [1.1.300rc2] - 2024-05-28
1218

1319
### Added

backend/chainlit/emitter.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ async def stream_start(self, step_dict: StepDict):
105105
"""Stub method to send a stream start signal to the UI."""
106106
pass
107107

108-
async def send_token(self, id: str, token: str, is_sequence=False):
108+
async def send_token(self, id: str, token: str, is_sequence=False, is_input=False):
109109
"""Stub method to send a message token to the UI."""
110110
pass
111111

@@ -353,10 +353,11 @@ def stream_start(self, step_dict: StepDict):
353353
step_dict,
354354
)
355355

356-
def send_token(self, id: str, token: str, is_sequence=False):
356+
def send_token(self, id: str, token: str, is_sequence=False, is_input=False):
357357
"""Send a message token to the UI."""
358358
return self.emit(
359-
"stream_token", {"id": id, "token": token, "isSequence": is_sequence}
359+
"stream_token",
360+
{"id": id, "token": token, "isSequence": is_sequence, "isInput": is_input},
360361
)
361362

362363
def set_chat_settings(self, settings: Dict[str, Any]):

backend/chainlit/step.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def step(
5151
tags: Optional[List[str]] = None,
5252
disable_feedback: bool = True,
5353
language: Optional[str] = None,
54-
show_input: Union[bool, str] = False,
54+
show_input: Union[bool, str] = "json",
5555
):
5656
"""Step decorator for async and sync functions."""
5757

@@ -160,7 +160,7 @@ def __init__(
160160
tags: Optional[List[str]] = None,
161161
disable_feedback: bool = True,
162162
language: Optional[str] = None,
163-
show_input: Union[bool, str] = False,
163+
show_input: Union[bool, str] = "json",
164164
):
165165
trace_event(f"init {self.__class__.__name__} {type}")
166166
time.sleep(0.001)
@@ -356,15 +356,21 @@ async def send(self):
356356

357357
return self
358358

359-
async def stream_token(self, token: str, is_sequence=False):
359+
async def stream_token(self, token: str, is_sequence=False, is_input=False):
360360
"""
361361
Sends a token to the UI.
362362
Once all tokens have been streamed, call .send() to end the stream and persist the step if persistence is enabled.
363363
"""
364364
if is_sequence:
365-
self.output = token
365+
if is_input:
366+
self.input = token
367+
else:
368+
self.output = token
366369
else:
367-
self.output += token
370+
if is_input:
371+
self.input += token
372+
else:
373+
self.output += token
368374

369375
assert self.id
370376

@@ -377,7 +383,7 @@ async def stream_token(self, token: str, is_sequence=False):
377383
await context.emitter.stream_start(step_dict)
378384
else:
379385
await context.emitter.send_token(
380-
id=self.id, token=token, is_sequence=is_sequence
386+
id=self.id, token=token, is_sequence=is_sequence, is_input=is_input
381387
)
382388

383389
# Handle parameter less decorator

backend/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "chainlit"
3-
version = "1.1.300rc2"
3+
version = "1.1.300rc3"
44
keywords = [
55
'LLM',
66
'Agents',

frontend/src/components/atoms/elements/InlinedElements.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const InlinedElements = ({ elements }: Props) => {
4242
);
4343

4444
return (
45-
<Stack gap={1} mt={1}>
45+
<Stack gap={1} mb={2}>
4646
{elementsByType.image?.length ? (
4747
<InlinedImageList items={elementsByType.image} />
4848
) : null}

frontend/src/components/atoms/elements/Plotly.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ const _PlotlyElement = ({ element }: Props) => {
3737
layout={state.layout}
3838
frames={state.frames}
3939
config={state.config}
40-
style={{ width: '100%', height: '100%' }}
40+
style={{
41+
width: '100%',
42+
height: '100%',
43+
borderRadius: '1rem',
44+
overflow: 'hidden'
45+
}}
4146
useResizeHandler={true}
4247
/>
4348
</Suspense>

frontend/src/components/molecules/messages/ToolCall.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function ToolCall({ steps, elements, isRunning }: Props) {
2929
);
3030
}, [steps, isRunning]);
3131

32-
const hasOutput = steps.some((step) => step.output);
32+
const hasOutput = steps.some((step) => step.output || step.input);
3333
const isError = steps.length ? steps[steps.length - 1].isError : false;
3434

3535
if (!steps.length) {
@@ -102,7 +102,7 @@ export default function ToolCall({ steps, elements, isRunning }: Props) {
102102
}}
103103
>
104104
{steps
105-
.filter((step) => step.output)
105+
.filter((step) => step.output || step.input)
106106
.map((step) => (
107107
<MessageContent
108108
key={step.id}

frontend/src/components/molecules/messages/components/MessageContent.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const MessageContent = memo(
2929
let lineCount = 0;
3030
let contentLength = 0;
3131

32-
const content =
32+
const outputContent =
3333
message.streaming && message.output
3434
? message.output + CURSOR_PLACEHOLDER
3535
: message.output;
@@ -41,7 +41,7 @@ const MessageContent = memo(
4141
} = prepareContent({
4242
elements,
4343
id: message.id,
44-
content: content,
44+
content: outputContent,
4545
language: message.language
4646
});
4747

@@ -61,11 +61,15 @@ const MessageContent = memo(
6161
let inputMarkdown;
6262

6363
if (message.input && message.showInput) {
64+
const inputContent =
65+
message.streaming && message.input
66+
? message.input + CURSOR_PLACEHOLDER
67+
: message.input;
6468
const { preparedContent: input, refElements: inputRefElements } =
6569
prepareContent({
6670
elements,
6771
id: message.id,
68-
content: message.input,
72+
content: inputContent,
6973
language:
7074
typeof message.showInput === 'string'
7175
? message.showInput
@@ -114,7 +118,7 @@ const MessageContent = memo(
114118
return (
115119
<Stack width="100%" direction="row" className="message-content">
116120
<Box width="100%">
117-
{output ? messageContent : null}
121+
{!!inputMarkdown || output ? messageContent : null}
118122
<InlinedElements elements={outputInlinedElements} />
119123
</Box>
120124
</Stack>

frontend/src/components/organisms/chat/dropScreen.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ export default function DropScreen() {
1212
zIndex: 10
1313
}}
1414
>
15-
<Stack alignItems="center" gap={2} color="grey.400">
16-
<ImageIcon sx={{ width: '100px', height: '100px' }} />
17-
<Typography fontWeight={600} fontSize="1.5rem">
15+
<Stack alignItems="center" gap={2}>
16+
<ImageIcon
17+
sx={{ width: '100px', height: '100px', color: 'grey.400' }}
18+
/>
19+
<Typography color="grey.200" fontWeight={600} fontSize="1.5rem">
1820
<Translator path="components.organisms.chat.dropScreen.dropYourFilesHere" />
1921
</Typography>
2022
</Stack>

libs/react-client/src/useChatData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface IToken {
1616
id: number | string;
1717
token: string;
1818
isSequence: boolean;
19+
isInput: boolean;
1920
}
2021

2122
const useChatData = () => {

0 commit comments

Comments
 (0)