Skip to content

Commit

Permalink
Release/1.1.300 (#1040)
Browse files Browse the repository at this point in the history
* enhance conversation spacing and make copilot expandable

* fix non ascii characters for chat profiles
  • Loading branch information
willydouhard authored May 29, 2024
1 parent 15b7b99 commit 7d2a5a7
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 37 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

Nothing unreleased!

## [1.1.300rc2] - 2024-05-28

### Added

- Expand copilot button

### Fix

- Reworked message padding and spacing
- Chat profile should now support non-ASCII characters (like chinese)

## [1.1.300rc1] - 2024-05-28

### Fix
Expand Down
5 changes: 4 additions & 1 deletion backend/chainlit/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import time
import uuid
from urllib.parse import unquote
from typing import Any, Dict, Literal

from chainlit.action import Action
Expand Down Expand Up @@ -138,6 +139,8 @@ def emit_call_fn(event: Literal["ask", "call_fn"], data, timeout):

client_type = environ.get("HTTP_X_CHAINLIT_CLIENT_TYPE")
http_referer = environ.get("HTTP_REFERER")
url_encoded_chat_profile = environ.get("HTTP_X_CHAINLIT_CHAT_PROFILE")
chat_profile = unquote(url_encoded_chat_profile) if url_encoded_chat_profile else None

ws_session = WebsocketSession(
id=session_id,
Expand All @@ -148,7 +151,7 @@ def emit_call_fn(event: Literal["ask", "call_fn"], data, timeout):
user_env=user_env,
user=user,
token=token,
chat_profile=environ.get("HTTP_X_CHAINLIT_CHAT_PROFILE"),
chat_profile=chat_profile,
thread_id=environ.get("HTTP_X_CHAINLIT_THREAD_ID"),
languages=environ.get("HTTP_ACCEPT_LANGUAGE"),
http_referer=http_referer,
Expand Down
2 changes: 1 addition & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "chainlit"
version = "1.1.300rc1"
version = "1.1.300rc2"
keywords = [
'LLM',
'Agents',
Expand Down
8 changes: 0 additions & 8 deletions frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
max-width: 100%;
}

.markdown-body *:first-child:not(h1):not(h2):not(h3):not(h4):not(h5):not(h6) {
margin-top: 0;
}

.markdown-body *:last-child {
margin-bottom: 0;
}

.markdown-body p {
white-space: break-spaces;
}
1 change: 0 additions & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ type ThemOverride = {

declare global {
interface Window {
renderingCodeBlock?: boolean;
theme?: {
default: string;
light?: ThemOverride;
Expand Down
24 changes: 24 additions & 0 deletions frontend/src/assets/expand.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import SvgIcon, { SvgIconProps } from '@mui/material/SvgIcon';

const ExpandIcon = (props: SvgIconProps) => {
return (
<SvgIcon
{...props}
style={{
strokeLinecap: 'round',
strokeLinejoin: 'round',
strokeWidth: 2,
fill: 'none',
stroke: 'currentColor'
}}
viewBox="0 0 24 24"
>
<polyline points="15 3 21 3 21 9" />
<polyline points="9 21 3 21 3 15" />
<line x1="21" x2="14" y1="3" y2="10" />
<line x1="3" x2="10" y1="21" y2="14" />
</SvgIcon>
);
};

export default ExpandIcon;
24 changes: 24 additions & 0 deletions frontend/src/assets/minimize.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import SvgIcon, { SvgIconProps } from '@mui/material/SvgIcon';

const MinimizeIcon = (props: SvgIconProps) => {
return (
<SvgIcon
{...props}
style={{
strokeLinecap: 'round',
strokeLinejoin: 'round',
strokeWidth: 2,
fill: 'none',
stroke: 'currentColor'
}}
viewBox="0 0 24 24"
>
<polyline points="4 14 10 14 10 20" />
<polyline points="20 10 14 10 14 4" />
<line x1="14" x2="21" y1="10" y2="3" />
<line x1="3" x2="10" y1="21" y2="14" />
</SvgIcon>
);
};

export default MinimizeIcon;
9 changes: 7 additions & 2 deletions frontend/src/components/molecules/BlinkingCursor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ const blink = keyframes`

export const CURSOR_PLACEHOLDER = '\u200B';

export default function BlinkingCursor() {
interface Props {
whitespace?: boolean;
}

export default function BlinkingCursor({ whitespace }: Props) {
return (
<Box
component="span"
Expand All @@ -26,7 +30,8 @@ export default function BlinkingCursor() {
height: '12px',
backgroundColor: 'text.primary',
borderRadius: '50%',
animation: `1s ease-in-out 0.1s ${blink} infinite`
animation: `1s ease-in-out 0.1s ${blink} infinite`,
ml: whitespace ? '0.5em' : 0
}}
/>
);
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/components/molecules/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ function Markdown({ refElements, allowHtml, latex, children }: Props) {
return rehypePlugins;
}, [allowHtml, latex]);

window.renderingCodeBlock = false;

const remarkPlugins = useMemo(() => {
let remarkPlugins: PluggableList = [cursorPlugin, remarkGfm as any];

Expand Down Expand Up @@ -126,7 +124,6 @@ function Markdown({ refElements, allowHtml, latex, children }: Props) {
return <InlineCode {...props} />;
},
pre({ ...props }) {
window.renderingCodeBlock = true;
return <Code {...props} />;
},
table({ children, ...props }) {
Expand Down Expand Up @@ -173,7 +170,7 @@ function Markdown({ refElements, allowHtml, latex, children }: Props) {
return <TableBody {...props}>{children}</TableBody>;
},
// @ts-expect-error custom plugin
blinkingCursor: () => <BlinkingCursor />
blinkingCursor: () => <BlinkingCursor whitespace />
}}
>
{children}
Expand Down
19 changes: 8 additions & 11 deletions frontend/src/components/molecules/messages/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ const Message = memo(
const isAsk = message.waitForAnswer;
const isUserMessage = message.type === 'user_message';

const forceDisplayCursor =
isLast && isRunning && (!message.streaming || window.renderingCodeBlock);
const forceDisplayCursor = isLast && isRunning && !message.streaming;
return (
<Box
sx={{
Expand Down Expand Up @@ -80,10 +79,9 @@ const Message = memo(
<Box
sx={{
px: 2.5,
py: 1,
borderRadius: '1.5rem',
backgroundColor: 'background.paper',
maxWidth: '90%',
maxWidth: '70%',
ml: 'auto'
}}
>
Expand All @@ -98,7 +96,7 @@ const Message = memo(
/>
</Box>
{forceDisplayCursor && (
<Box my={1}>
<Box mt={1}>
<BlinkingCursor />
</Box>
)}
Expand Down Expand Up @@ -129,16 +127,15 @@ const Message = memo(
{!isRunning && isLast && isAsk && (
<AskUploadButton onError={onError} />
)}
<Box my={1} />
{forceDisplayCursor && (
<Box position="absolute" bottom={0}>
<BlinkingCursor />
</Box>
)}
{actions?.length ? (
<MessageActions message={message} actions={actions} />
) : null}
<MessageButtons message={message} />
{forceDisplayCursor && (
<Box my={0.5}>
<BlinkingCursor />
</Box>
)}
</Stack>
</Stack>
)}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/molecules/messages/ToolCalls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function ToolCalls({ message, elements, isRunning }: Props) {
}

return (
<Stack width="100%" direction="column" gap={1} mb={1}>
<Stack width="100%" direction="column" gap={1}>
{toolCalls.map((toolCall, index) => (
<ToolCall
key={index}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const MessageActions = ({ message, actions }: Props) => {

const show = displayedActions.length || drawerActions.length;

if (!show) {
if (!show || message.streaming) {
return null;
}

Expand Down
1 change: 1 addition & 0 deletions libs/copilot/src/chat/body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ const Chat = () => {
setAutoScroll={setAutoScroll}
>
<WelcomeScreen hideLogo />
<Box my={1} />
<Messages />
</ScrollContainer>
<InputBox
Expand Down
22 changes: 19 additions & 3 deletions libs/copilot/src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { Stack } from '@mui/material';
import { IconButton, Stack } from '@mui/material';

import ExpandIcon from '@chainlit/app/src/assets/expand';
import MinimizeIcon from '@chainlit/app/src/assets/minimize';
import { Logo } from '@chainlit/app/src/components/atoms/logo';

import ChatProfiles from './ChatProfiles';
import NewChatButton from './NewChatButton';

const Header = (): JSX.Element => (
interface Props {
expanded: boolean;
setExpanded: (expanded: boolean) => void;
}

const Header = ({ expanded, setExpanded }: Props): JSX.Element => (
<Stack
px={2}
py={1.5}
Expand All @@ -14,7 +21,16 @@ const Header = (): JSX.Element => (
justifyContent="space-between"
bgcolor="background.paper"
>
<Logo style={{ maxHeight: '25px' }} />
<Stack direction="row" alignItems="center" spacing={0.5}>
<Logo style={{ maxHeight: '25px' }} />
<IconButton onClick={() => setExpanded(!expanded)}>
{expanded ? (
<MinimizeIcon sx={{ width: 16, height: 16 }} />
) : (
<ExpandIcon sx={{ width: 16, height: 16 }} />
)}
</IconButton>
</Stack>
<Stack direction="row" alignItems="center" spacing={1}>
<ChatProfiles />
<NewChatButton />
Expand Down
6 changes: 4 additions & 2 deletions libs/copilot/src/popover.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Chat from 'chat';
import { useState } from 'react';

import { Box } from '@mui/material';
import Fade from '@mui/material/Fade';
Expand All @@ -11,6 +12,7 @@ interface Props {
}

export default function PopOver({ anchorEl }: Props) {
const [expanded, setExpanded] = useState(false);
return (
<Popper
id="chainlit-copilot-popover"
Expand All @@ -22,7 +24,7 @@ export default function PopOver({ anchorEl }: Props) {
flexDirection: 'column',
inset: 'auto auto 14px -24px !important',
height: 'min(730px, calc(100vh - 100px))',
width: 'min(400px, 80vw)',
width: expanded ? '80vw' : 'min(400px, 80vw)',
overflow: 'hidden',
borderRadius: '12px',
background: (theme) => theme.palette.background.default,
Expand All @@ -40,7 +42,7 @@ export default function PopOver({ anchorEl }: Props) {
width: '100%'
}}
>
<Header />
<Header expanded={expanded} setExpanded={setExpanded} />
<Chat />
</Box>
</Fade>
Expand Down
5 changes: 3 additions & 2 deletions libs/react-client/src/useChatSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ const useChatSession = () => {
const [chatProfile, setChatProfile] = useRecoilState(chatProfileState);
const idToResume = useRecoilValue(threadIdToResumeState);
const setCurrentThreadId = useSetRecoilState(currentThreadIdState);

const _connect = useCallback(
({
client,
Expand All @@ -86,7 +85,9 @@ const useChatSession = () => {
'X-Chainlit-Session-Id': sessionId,
'X-Chainlit-Thread-Id': idToResume || '',
'user-env': JSON.stringify(userEnv),
'X-Chainlit-Chat-Profile': chatProfile || ''
'X-Chainlit-Chat-Profile': chatProfile
? encodeURIComponent(chatProfile)
: ''
}
});
setSession((old) => {
Expand Down

0 comments on commit 7d2a5a7

Please sign in to comment.