mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 12:37:55 +00:00
(feature)(chat-sdk) add Few-shot examples (#599)
This commit is contained in:
@@ -10,12 +10,13 @@ import { SqlInfoType } from '../../common/type';
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
llmReq?: any;
|
llmReq?: any;
|
||||||
|
llmResp?: any;
|
||||||
integrateSystem?: string;
|
integrateSystem?: string;
|
||||||
sqlInfo: SqlInfoType;
|
sqlInfo: SqlInfoType;
|
||||||
sqlTimeCost?: number;
|
sqlTimeCost?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const SqlItem: React.FC<Props> = ({ llmReq, integrateSystem, sqlInfo, sqlTimeCost }) => {
|
const SqlItem: React.FC<Props> = ({ llmReq, llmResp, integrateSystem, sqlInfo, sqlTimeCost }) => {
|
||||||
const [sqlType, setSqlType] = useState('');
|
const [sqlType, setSqlType] = useState('');
|
||||||
|
|
||||||
const tipPrefixCls = `${PREFIX_CLS}-item`;
|
const tipPrefixCls = `${PREFIX_CLS}-item`;
|
||||||
@@ -35,6 +36,8 @@ const SqlItem: React.FC<Props> = ({ llmReq, integrateSystem, sqlInfo, sqlTimeCos
|
|||||||
|
|
||||||
const { schema, linking, priorExts } = llmReq || {};
|
const { schema, linking, priorExts } = llmReq || {};
|
||||||
|
|
||||||
|
const fewShots = (Object.values(llmResp?.sqlRespMap || {})[0] as any)?.fewShots || [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`${tipPrefixCls}-parse-tip`}>
|
<div className={`${tipPrefixCls}-parse-tip`}>
|
||||||
<div className={`${tipPrefixCls}-title-bar`}>
|
<div className={`${tipPrefixCls}-title-bar`}>
|
||||||
@@ -64,6 +67,18 @@ const SqlItem: React.FC<Props> = ({ llmReq, integrateSystem, sqlInfo, sqlTimeCos
|
|||||||
Schema映射
|
Schema映射
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{fewShots.length > 0 && (
|
||||||
|
<div
|
||||||
|
className={`${tipPrefixCls}-content-option ${
|
||||||
|
sqlType === 'fewShots' ? `${tipPrefixCls}-content-option-active` : ''
|
||||||
|
}`}
|
||||||
|
onClick={() => {
|
||||||
|
setSqlType(sqlType === 'fewShots' ? '' : 'fewShots');
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Few-shot示例
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{sqlInfo.s2SQL && (
|
{sqlInfo.s2SQL && (
|
||||||
<div
|
<div
|
||||||
className={`${tipPrefixCls}-content-option ${
|
className={`${tipPrefixCls}-content-option ${
|
||||||
@@ -141,6 +156,37 @@ const SqlItem: React.FC<Props> = ({ llmReq, integrateSystem, sqlInfo, sqlTimeCos
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{sqlType === 'fewShots' && (
|
||||||
|
<div className={`${prefixCls}-code`}>
|
||||||
|
{fewShots.map((item: any, index: number) => {
|
||||||
|
return (
|
||||||
|
<div key={index} className={`${prefixCls}-few-shot-item`}>
|
||||||
|
<div className={`${prefixCls}-few-shot-title`}>示例{index + 1}:</div>
|
||||||
|
<div className={`${prefixCls}-few-shot-content`}>
|
||||||
|
<div className={`${prefixCls}-few-shot-content-item`}>
|
||||||
|
<div className={`${prefixCls}-few-shot-content-title`}>问题:</div>
|
||||||
|
<div className={`${prefixCls}-few-shot-content-text`}>
|
||||||
|
{item.questionAugmented}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className={`${prefixCls}-few-shot-content-item`}>
|
||||||
|
<div className={`${prefixCls}-few-shot-content-title`}>SQL:</div>
|
||||||
|
<div className={`${prefixCls}-few-shot-content-text`}>
|
||||||
|
<SyntaxHighlighter
|
||||||
|
className={`${prefixCls}-few-shot-code`}
|
||||||
|
language="sql"
|
||||||
|
style={solarizedlight}
|
||||||
|
>
|
||||||
|
{item.sql}
|
||||||
|
</SyntaxHighlighter>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{sqlType && sqlInfo[sqlType] && (
|
{sqlType && sqlInfo[sqlType] && (
|
||||||
<>
|
<>
|
||||||
<SyntaxHighlighter
|
<SyntaxHighlighter
|
||||||
|
|||||||
@@ -308,6 +308,8 @@ const ChatItem: React.FC<Props> = ({
|
|||||||
[`${prefixCls}-content-mobile`]: isMobile,
|
[`${prefixCls}-content-mobile`]: isMobile,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { llmReq, llmResp } = parseInfo?.properties?.CONTEXT || {};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={prefixCls}>
|
<div className={prefixCls}>
|
||||||
{!isMobile && integrateSystem !== 'wiki' && (
|
{!isMobile && integrateSystem !== 'wiki' && (
|
||||||
@@ -337,7 +339,8 @@ const ChatItem: React.FC<Props> = ({
|
|||||||
<>
|
<>
|
||||||
{!isMobile && parseInfo?.sqlInfo && isDeveloper && integrateSystem !== 'c2' && (
|
{!isMobile && parseInfo?.sqlInfo && isDeveloper && integrateSystem !== 'c2' && (
|
||||||
<SqlItem
|
<SqlItem
|
||||||
llmReq={parseInfo?.properties?.CONTEXT?.llmReq}
|
llmReq={llmReq}
|
||||||
|
llmResp={llmResp}
|
||||||
integrateSystem={integrateSystem}
|
integrateSystem={integrateSystem}
|
||||||
sqlInfo={parseInfo.sqlInfo}
|
sqlInfo={parseInfo.sqlInfo}
|
||||||
sqlTimeCost={parseTimeCost?.sqlTime}
|
sqlTimeCost={parseTimeCost?.sqlTime}
|
||||||
|
|||||||
@@ -487,6 +487,46 @@
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
color: var(--text-color);
|
color: var(--text-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&-few-shot-item {
|
||||||
|
margin-top: 10px;
|
||||||
|
|
||||||
|
&:first-child {
|
||||||
|
margin-top: 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-few-shot-title {
|
||||||
|
color: var(--text-color);
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-few-shot-content {
|
||||||
|
margin-top: 8px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
row-gap: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-few-shot-content-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-few-shot-content-title {
|
||||||
|
width: 50px;
|
||||||
|
color: var(--text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
&-few-shot-content-text {
|
||||||
|
line-height: 24px;
|
||||||
|
color: var(--text-color-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
&-few-shot-code {
|
||||||
|
padding: 0 !important;
|
||||||
|
background-color: transparent !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.@{sql-item-prefix-cls}-copilot {
|
.@{sql-item-prefix-cls}-copilot {
|
||||||
|
|||||||
Reference in New Issue
Block a user