ui: chart btn
This commit is contained in:
parent
24a220bc51
commit
b35a9af8a6
4 changed files with 37 additions and 23 deletions
|
|
@ -35,6 +35,7 @@ export default class KaiService extends AiService {
|
|||
feedback: boolean | null;
|
||||
supports_visualization: boolean;
|
||||
chart: string;
|
||||
chart_data: string;
|
||||
}[]
|
||||
> => {
|
||||
const r = await this.client.get(`/kai/${projectId}/chats/${threadId}`);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,10 @@ export interface Message {
|
|||
text: string;
|
||||
isUser: boolean;
|
||||
messageId: string;
|
||||
/** filters to get chart */
|
||||
chart: string;
|
||||
/** chart data */
|
||||
chart_data: string;
|
||||
supports_visualization: boolean;
|
||||
feedback: boolean | null;
|
||||
duration: number;
|
||||
|
|
@ -115,6 +118,7 @@ class KaiStore {
|
|||
feedback: m.feedback,
|
||||
chart: m.chart,
|
||||
supports_visualization: m.supports_visualization,
|
||||
chart_data: m.chart_data,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
|
@ -173,6 +177,7 @@ class KaiStore {
|
|||
feedback: null,
|
||||
chart: '',
|
||||
supports_visualization: msg.supports_visualization,
|
||||
chart_data: '',
|
||||
};
|
||||
this.addMessage(msgObj);
|
||||
this.setProcessingStage(null);
|
||||
|
|
@ -219,6 +224,7 @@ class KaiStore {
|
|||
duration: 0,
|
||||
supports_visualization: false,
|
||||
chart: '',
|
||||
chart_data: '',
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -273,6 +279,8 @@ class KaiStore {
|
|||
this.chatManager = null;
|
||||
}
|
||||
};
|
||||
|
||||
getMessageChart = (msgId: string, projectId: string) => { }
|
||||
}
|
||||
|
||||
export const kaiStore = new KaiStore();
|
||||
|
|
|
|||
|
|
@ -61,17 +61,14 @@ function ChatLog({
|
|||
>
|
||||
<div className={'flex flex-col gap-4 w-2/3 min-h-max'}>
|
||||
{messages.map((msg, index) => (
|
||||
<ChatMsg
|
||||
key={index}
|
||||
text={msg.text}
|
||||
isUser={msg.isUser}
|
||||
userName={userLetter}
|
||||
messageId={msg.messageId}
|
||||
duration={msg.duration}
|
||||
feedback={msg.feedback}
|
||||
siteId={projectId}
|
||||
canEdit={processingStage === null && msg.isUser && index === lastHumanMsgInd}
|
||||
/>
|
||||
<React.Fragment key={msg.messageId ?? index}>
|
||||
<ChatMsg
|
||||
userName={userLetter}
|
||||
siteId={projectId}
|
||||
message={msg}
|
||||
canEdit={processingStage === null && msg.isUser && index === lastHumanMsgInd}
|
||||
/>
|
||||
</React.Fragment>
|
||||
))}
|
||||
{processingStage ? (
|
||||
<ChatNotice
|
||||
|
|
|
|||
|
|
@ -10,31 +10,26 @@ import {
|
|||
ListRestart,
|
||||
FileDown,
|
||||
Clock,
|
||||
ChartLine,
|
||||
} from 'lucide-react';
|
||||
import { Button, Tooltip } from 'antd';
|
||||
import { kaiStore } from '../KaiStore';
|
||||
import { kaiStore, Message } from '../KaiStore';
|
||||
import { toast } from 'react-toastify';
|
||||
import { durationFormatted } from 'App/date';
|
||||
|
||||
export function ChatMsg({
|
||||
text,
|
||||
isUser,
|
||||
userName,
|
||||
messageId,
|
||||
duration,
|
||||
feedback,
|
||||
siteId,
|
||||
canEdit,
|
||||
message,
|
||||
}: {
|
||||
text: string;
|
||||
isUser: boolean;
|
||||
messageId: string;
|
||||
message: Message;
|
||||
userName?: string;
|
||||
duration?: number;
|
||||
feedback: boolean | null;
|
||||
siteId: string;
|
||||
canEdit?: boolean;
|
||||
siteId: string;
|
||||
}) {
|
||||
const [loadingChart, setLoadingChart] = React.useState(false);
|
||||
const { text, isUser, messageId, duration, feedback, supports_visualization, chart_data } = message;
|
||||
const [isProcessing, setIsProcessing] = React.useState(false);
|
||||
const bodyRef = React.useRef<HTMLDivElement>(null);
|
||||
const onRetry = () => {
|
||||
|
|
@ -74,6 +69,12 @@ export function ChatMsg({
|
|||
setIsProcessing(false);
|
||||
});
|
||||
};
|
||||
|
||||
const getChart = () => {
|
||||
setLoadingChart(true);
|
||||
kaiStore.getMessageChart(messageId, siteId)
|
||||
setLoadingChart(false);
|
||||
}
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
|
|
@ -132,6 +133,13 @@ export function ChatMsg({
|
|||
>
|
||||
<ThumbsDown size={16} />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
tooltip="Visualize this answer"
|
||||
onClick={getChart}
|
||||
processing={loadingChart}
|
||||
>
|
||||
<ChartLine size={16}/>
|
||||
</IconButton>
|
||||
<CopyButton
|
||||
getHtml={() => bodyRef.current?.innerHTML}
|
||||
content={text}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue