Skip to content

Commit

Permalink
enhance step button
Browse files Browse the repository at this point in the history
  • Loading branch information
willydouhard committed May 22, 2023
1 parent 15b36f4 commit 610e172
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,32 @@ export default function DetailsButton({
}: Props) {
const pSettings = useRecoilValue(projectSettingsState);

const nested = !!message.subMessages?.length;
const nestedCount = message.subMessages?.length;
const nested = !!nestedCount;

const tool = nested ? message.subMessages![0].author : undefined;
const tool = nested
? message.subMessages![nestedCount - 1].author
: undefined;

const show =
nested || (loading && (!message.content || message.authorIsUser));
const isRunningEmptyStep = loading && !message.content;
const isRunningUserMessage = loading && message.authorIsUser;

const show = nested || isRunningEmptyStep || isRunningUserMessage;

if (!show || pSettings?.hideCot) {
return null;
}

const text = loading ? (tool ? `Using ${tool}` : 'Running') : `Used ${tool}`;
// Don't count empty steps
const stepCount = nestedCount
? message.subMessages!.filter((m) => !!m.content).length
: 0;

const text = loading
? tool
? `Using ${tool}`
: 'Running'
: `Took ${stepCount} step${stepCount <= 1 ? '' : 's'}`;

let id = '';
if (tool) {
Expand Down
4 changes: 1 addition & 3 deletions src/chainlit/frontend/src/components/chat/stopButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import CloseIcon from '@mui/icons-material/Close';
import { Box } from '@mui/material';
import { useRecoilState, useRecoilValue } from 'recoil';
import { loadingState, sessionState } from 'state/chat';
import { projectSettingsState } from 'state/project';
import GreyButton from 'components/greyButton';

export default function StopButton() {
const [loading, setLoading] = useRecoilState(loadingState);
const pSettings = useRecoilValue(projectSettingsState);
const session = useRecoilValue(sessionState);

if (!loading || pSettings?.hideCot) {
if (!loading) {
return null;
}

Expand Down

0 comments on commit 610e172

Please sign in to comment.