Skip to content

Commit

Permalink
feat(FR-433): wrap customTags contents with Collapse
Browse files Browse the repository at this point in the history
  • Loading branch information
agatha197 committed Jan 31, 2025
1 parent 445dd03 commit 368f253
Show file tree
Hide file tree
Showing 26 changed files with 157 additions and 84 deletions.
13 changes: 3 additions & 10 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"baseversion",
"cssinjs",
"cuda",
"deepseek",
"FGPU",
"filebrowser",
"Frgmt",
Expand All @@ -30,6 +31,7 @@
"shmem",
"Signout",
"superadmin",
"Talkativot",
"Tensorboard",
"textbox",
"Totp",
Expand All @@ -39,16 +41,7 @@
"Warboy",
"webcomponent",
"webui",
"wsproxy",
"ahooks",
"lucide",
"Signout",
"Totp",
"Keypairs",
"Hyperaccel",
"Tensorboard",
"Automount",
"Talkativot"
"wsproxy"
],
"flagWords": [
"데이터레이크",
Expand Down
6 changes: 3 additions & 3 deletions react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "24.09.0-alpha.1",
"private": true,
"dependencies": {
"@ai-sdk/openai": "^1.0.11",
"@ai-sdk/react": "^1.0.7",
"@ai-sdk/openai": "^1.1.5",
"@ai-sdk/react": "^1.1.7",
"@ant-design/cssinjs": "^1.22.0",
"@ant-design/icons": "^5.5.1",
"@ant-design/x": "^1.0.4",
Expand All @@ -23,7 +23,7 @@
"@uiw/codemirror-extensions-langs": "^4.23.6",
"@uiw/react-codemirror": "^4.23.6",
"ahooks": "^3.8.1",
"ai": "^4.0.22",
"ai": "^4.1.13",
"ansi_up": "^6.0.2",
"antd": "^5.22.2",
"antd-style": "^3.7.1",
Expand Down
81 changes: 40 additions & 41 deletions react/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 35 additions & 1 deletion react/src/components/lablupTalkativotUI/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import ChatMessageContent from './ChatMessageContent';
import { Message } from '@ai-sdk/react';
import { Attachments } from '@ant-design/x';
import { useThrottle } from 'ahooks';
import { Avatar, theme, Image } from 'antd';
import { Avatar, theme, Image, Collapse, Typography, Spin } from 'antd';
import dayjs from 'dayjs';
import localizedFormat from 'dayjs/plugin/localizedFormat';
import relativeTime from 'dayjs/plugin/relativeTime';
import _ from 'lodash';
import React from 'react';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';

dayjs.extend(localizedFormat);
dayjs.extend(relativeTime);
Expand All @@ -32,8 +33,12 @@ const ChatMessage: React.FC<{
isStreaming,
}) => {
const { token } = theme.useToken();
const { t } = useTranslation();
const [isHovered, setIsHovered] = useState(false);

const throttledMessageReasoning = useThrottle(message.reasoning, {
wait: 50,
});
const throttledMessageContent = useThrottle(message.content, { wait: 50 });

return (
Expand Down Expand Up @@ -113,8 +118,37 @@ const ChatMessage: React.FC<{
? token.colorBgContainer
: token.colorBgContainerDisabled,
maxWidth: '100%',
width: _.trim(message.reasoning) ? '100%' : 'auto',
}}
>
{_.trim(message.reasoning) && (
<Collapse
style={{
marginTop: token.margin,
width: '100%',
}}
items={[
{
key: 'reasoning',
label: _.isEmpty(throttledMessageContent) ? (
<Flex gap="xs">
<Typography.Text>{t('chatui.Thinking')}</Typography.Text>
<Spin size="small" />
</Flex>
) : (
<Typography.Text>
{t('chatui.ViewReasoning')}
</Typography.Text>
),
children: (
<ChatMessageContent>
{throttledMessageReasoning + (isStreaming ? '\n●' : '')}
</ChatMessageContent>
),
},
]}
/>
)}
<ChatMessageContent>
{throttledMessageContent + (isStreaming ? '\n●' : '')}
</ChatMessageContent>
Expand Down
21 changes: 13 additions & 8 deletions react/src/components/lablupTalkativotUI/LLMChatCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from '@ant-design/icons';
import { Attachments, AttachmentsProps, Sender } from '@ant-design/x';
import { useControllableValue } from 'ahooks';
import { streamText } from 'ai';
import { streamText, extractReasoningMiddleware, wrapLanguageModel } from 'ai';
import {
Alert,
Badge,
Expand Down Expand Up @@ -132,17 +132,22 @@ const LLMChatCard: React.FC<LLMChatCardProps> = ({
? customModelFormRef.current?.getFieldValue('token')
: apiKey) || 'dummy',
});
const result = await streamText({
const result = streamText({
abortSignal: init?.signal || undefined,
model: provider(
allowCustomModel
? customModelFormRef.current?.getFieldValue('modelId')
: modelId,
),
model: wrapLanguageModel({
model: provider(
allowCustomModel
? customModelFormRef.current?.getFieldValue('modelId')
: modelId,
),
middleware: extractReasoningMiddleware({ tagName: 'think' }),
}),
messages: body?.messages,
});
setStartTime(Date.now());
return result.toDataStreamResponse();
return result.toDataStreamResponse({
sendReasoning: true,
});
} else {
return fetch(input, init);
}
Expand Down
4 changes: 3 additions & 1 deletion resources/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,9 @@
"Attachments": "Anhänge",
"DropFileHere": "Datei hier ablegen",
"UploadFiles": "Dateien hochladen",
"UploadFilesDescription": "Klicken oder ziehen Sie Dateien zum Hochladen in diesen Bereich"
"UploadFilesDescription": "Klicken oder ziehen Sie Dateien zum Hochladen in diesen Bereich",
"Thinking": "Denken",
"ViewReasoning": "Argumentation anzeigen"
},
"time": {
"Day": "day",
Expand Down
4 changes: 3 additions & 1 deletion resources/i18n/el.json
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,9 @@
"Attachments": "Συνημμένα",
"DropFileHere": "Αποθέστε το αρχείο εδώ",
"UploadFiles": "Μεταφόρτωση αρχείων",
"UploadFilesDescription": "Κάντε κλικ ή σύρετε αρχεία σε αυτήν την περιοχή για μεταφόρτωση"
"UploadFilesDescription": "Κάντε κλικ ή σύρετε αρχεία σε αυτήν την περιοχή για μεταφόρτωση",
"Thinking": "Σκέψη",
"ViewReasoning": "Προβολή λογικής"
},
"time": {
"Day": "day",
Expand Down
4 changes: 3 additions & 1 deletion resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,9 @@
"Attachments": "Attachments",
"DropFileHere": "Drop file here",
"UploadFiles": "Upload files",
"UploadFilesDescription": "Click or drag files to this area to upload"
"UploadFilesDescription": "Click or drag files to this area to upload",
"Thinking": "Thinking",
"ViewReasoning": "View reasoning"
},
"time": {
"Day": "day",
Expand Down
4 changes: 3 additions & 1 deletion resources/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,9 @@
"Attachments": "Adjuntos",
"DropFileHere": "Suelta el archivo aquí",
"UploadFiles": "Subir archivos",
"UploadFilesDescription": "Haga clic o arrastre archivos a esta área para cargarlos"
"UploadFilesDescription": "Haga clic o arrastre archivos a esta área para cargarlos",
"Thinking": "Pensamiento",
"ViewReasoning": "Ver razonamiento"
},
"time": {
"Day": "day",
Expand Down
4 changes: 3 additions & 1 deletion resources/i18n/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,9 @@
"Attachments": "Liitteet",
"DropFileHere": "Pudota tiedosto tähän",
"UploadFiles": "Lataa tiedostoja",
"UploadFilesDescription": "Napsauta tai vedä tiedostoja tälle alueelle ladataksesi"
"UploadFilesDescription": "Napsauta tai vedä tiedostoja tälle alueelle ladataksesi",
"Thinking": "Ajattelu",
"ViewReasoning": "Näytä päättely"
},
"time": {
"Day": "day",
Expand Down
Loading

0 comments on commit 368f253

Please sign in to comment.