-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
674104e
commit 4a8f016
Showing
24 changed files
with
831 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ChatContext } from '@/app/chat-context'; | ||
import { IChatDialogueMessageSchema } from '@/types/chat'; | ||
import classNames from 'classnames'; | ||
import { memo, useContext } from 'react'; | ||
import ReactMarkdown from 'react-markdown'; | ||
import markdownComponents from './chat-content/config'; | ||
import rehypeRaw from 'rehype-raw'; | ||
|
||
interface Props { | ||
content: IChatDialogueMessageSchema; | ||
} | ||
|
||
function formatMarkdownVal(val: string) { | ||
return val.replace(/<table(\w*=[^>]+)>/gi, '<table $1>').replace(/<tr(\w*=[^>]+)>/gi, '<tr $1>'); | ||
} | ||
|
||
function AgentContent({ content }: Props) { | ||
const { scene } = useContext(ChatContext); | ||
|
||
const isView = content.role === 'view'; | ||
|
||
return ( | ||
<div | ||
className={classNames('relative w-full p-2 md:p-4 rounded-xl break-words', { | ||
'bg-white dark:bg-[#232734]': isView, | ||
'lg:w-full xl:w-full pl-0': ['chat_with_db_execute', 'chat_dashboard'].includes(scene), | ||
})} | ||
> | ||
{isView ? ( | ||
<ReactMarkdown components={markdownComponents} rehypePlugins={[rehypeRaw]}> | ||
{formatMarkdownVal(content.context)} | ||
</ReactMarkdown> | ||
) : ( | ||
<div className="">{content.context}</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default memo(AgentContent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import ReactMarkdown from 'react-markdown'; | ||
import markdownComponents from './config'; | ||
import { renderModelIcon } from '../header/model-selector'; | ||
import { SwapRightOutlined } from '@ant-design/icons'; | ||
|
||
interface Props { | ||
data: { | ||
sender: string; | ||
receiver: string; | ||
model: string | null; | ||
markdown: string; | ||
}[]; | ||
} | ||
|
||
function AgentMessages({ data }: Props) { | ||
if (!data || !data.length) return null; | ||
|
||
return ( | ||
<> | ||
{data.map((item, index) => ( | ||
<div key={index} className="rounded my-4 md:my-6"> | ||
<div className="flex items-center mb-3 text-sm"> | ||
{item.model ? renderModelIcon(item.model) : <div className="rounded-full w-6 h-6 bg-gray-100" />} | ||
<div className="ml-2 opacity-70"> | ||
{item.sender} | ||
<SwapRightOutlined className="mx-2 text-base" /> | ||
{item.receiver} | ||
</div> | ||
</div> | ||
<div className="whitespace-normal text-sm"> | ||
<ReactMarkdown components={markdownComponents}>{item.markdown}</ReactMarkdown> | ||
</div> | ||
</div> | ||
))} | ||
</> | ||
); | ||
} | ||
|
||
export default AgentMessages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { CaretRightOutlined, CheckOutlined, ClockCircleOutlined } from '@ant-design/icons'; | ||
import { Collapse } from 'antd'; | ||
import ReactMarkdown from 'react-markdown'; | ||
import markdownComponents from './config'; | ||
|
||
interface Props { | ||
data: { | ||
name: string; | ||
num: number; | ||
status: 'complete' | 'todo'; | ||
agent: string; | ||
markdown: string; | ||
}[]; | ||
} | ||
|
||
function AgentPlans({ data }: Props) { | ||
if (!data || !data.length) return null; | ||
|
||
return ( | ||
<Collapse | ||
bordered | ||
className="my-3" | ||
expandIcon={({ isActive }) => <CaretRightOutlined rotate={isActive ? 90 : 0} />} | ||
items={data.map((item, index) => { | ||
return { | ||
key: index, | ||
label: ( | ||
<div className="whitespace-normal"> | ||
<span> | ||
{item.name} - {item.agent} | ||
</span> | ||
{item.status === 'complete' ? ( | ||
<CheckOutlined className="!text-green-500 ml-2" /> | ||
) : ( | ||
<ClockCircleOutlined className="!text-gray-500 ml-2" /> | ||
)} | ||
</div> | ||
), | ||
children: <ReactMarkdown components={markdownComponents}>{item.markdown}</ReactMarkdown>, | ||
}; | ||
})} | ||
/> | ||
); | ||
} | ||
|
||
export default AgentPlans; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Datum } from '@antv/ava'; | ||
import { Table, Tabs, TabsProps } from 'antd'; | ||
import React from 'react'; | ||
import { format } from 'sql-formatter'; | ||
import { AutoChart, BackEndChartType, getChartType } from '@/components/chart/autoChart'; | ||
import { CodePreview } from './code-preview'; | ||
|
||
function ChartView({ data, type, sql }: { data: Datum[]; type: BackEndChartType; sql: string }) { | ||
const columns = data?.[0] | ||
? Object.keys(data?.[0])?.map((item) => { | ||
return { | ||
title: item, | ||
dataIndex: item, | ||
key: item, | ||
}; | ||
}) | ||
: []; | ||
const ChartItem = { | ||
key: 'chart', | ||
label: 'Chart', | ||
children: <AutoChart data={data} chartType={getChartType(type)} />, | ||
}; | ||
const SqlItem = { | ||
key: 'sql', | ||
label: 'SQL', | ||
children: <CodePreview language="sql" code={format(sql, { language: 'mysql' }) as string} />, | ||
}; | ||
const DataItem = { | ||
key: 'data', | ||
label: 'Data', | ||
children: <Table dataSource={data} columns={columns} />, | ||
}; | ||
const TabItems: TabsProps['items'] = type === 'response_table' ? [DataItem, SqlItem] : [ChartItem, SqlItem, DataItem]; | ||
|
||
return <Tabs defaultActiveKey={type === 'response_table' ? 'data' : 'chart'} items={TabItems} size="small" />; | ||
} | ||
|
||
export default ChartView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.