(feature)(chat-sdk) add export log (#1482)

This commit is contained in:
williamhliu
2024-07-30 15:20:02 +08:00
committed by GitHub
parent 9a1fac5d4c
commit e571ca1f55
6 changed files with 157 additions and 45 deletions

View File

@@ -143,19 +143,6 @@ const ParseTip: React.FC<Props> = ({
const entityAlias = entity?.alias?.[0]?.split('.')?.[0];
const entityDimensions = entityInfo?.dimensions?.filter(
item =>
!['zyqk_song_id', 'song_name', 'singer_id', 'zyqk_cmpny_id'].includes(item.bizName) &&
!(
entityInfo?.dimensions?.some(dimension => dimension.bizName === 'singer_id') &&
item.bizName === 'singer_name'
) &&
!(
entityInfo?.dimensions?.some(dimension => dimension.bizName === 'zyqk_cmpny_id') &&
item.bizName === 'cmpny_name'
)
);
const getTipNode = () => {
const dimensionItems = dimensions?.filter(item => item.type === 'DIMENSION');
const itemValueClass = `${prefixCls}-tip-item-value`;
@@ -230,7 +217,7 @@ const ParseTip: React.FC<Props> = ({
)}
{queryMode !== 'TAG_ID' &&
!dimensions?.some(item => item.bizName?.includes('_id')) &&
entityDimensions
entityInfo?.dimensions
?.filter(dimension => dimension.value != null)
.map(dimension => (
<div className={`${prefixCls}-tip-item`} key={dimension.itemId}>

View File

@@ -3,10 +3,11 @@ import { format } from 'sql-formatter';
import { CopyToClipboard } from 'react-copy-to-clipboard';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { solarizedlight } from 'react-syntax-highlighter/dist/esm/styles/prism';
import { message } from 'antd';
import { Button, message } from 'antd';
import { PREFIX_CLS } from '../../common/constants';
import { CheckCircleFilled, UpOutlined } from '@ant-design/icons';
import { CheckCircleFilled, DownloadOutlined, UpOutlined } from '@ant-design/icons';
import { SqlInfoType } from '../../common/type';
import { exportTextFile } from '../../utils/utils';
type Props = {
llmReq?: any;
@@ -46,6 +47,99 @@ const SqlItem: React.FC<Props> = ({
const fewShots = (Object.values(llmResp?.sqlRespMap || {})[0] as any)?.fewShots || [];
const getSchemaMapText = () => {
return `
Schema映射
${schema?.fieldNameList?.length > 0 ? `名称:${schema.fieldNameList.join('、')}` : ''}${
linking?.length > 0
? `
取值:${linking
.map((item: any) => {
return `${item.fieldName}: ${item.fieldValue}`;
})
.join('、')}`
: ''
}${
priorExts
? `
附加:${priorExts}`
: ''
}${
schema?.terms?.length > 0
? `
术语:${schema.terms
.map((item: any) => {
return `${item.name}${item.alias?.length > 0 ? `(${item.alias.join(',')})` : ''}: ${
item.description
}`;
})
.join('、')}`
: ''
}
`;
};
const getFewShotText = () => {
return `
Few-shot示例${fewShots
.map((item: any, index: number) => {
return `
示例${index + 1}
问题:${item.question}
SQL
${format(item.sql)}
`;
})
.join('')}
`;
};
const getParsedS2SQLText = () => {
return `
${queryMode === 'LLM_S2SQL' || queryMode === 'PLAIN_TEXT' ? 'LLM' : 'Rule'}解析S2SQL
${format(sqlInfo.parsedS2SQL)}
`;
};
const getCorrectedS2SQLText = () => {
return `
修正S2SQL
${format(sqlInfo.correctedS2SQL)}
`;
};
const getQuerySQLText = () => {
return `
最终执行SQL
${format(sqlInfo.querySQL)}
`;
};
const onExportLog = () => {
let text = '';
if (llmReq) {
text += getSchemaMapText();
}
if (fewShots.length > 0) {
text += getFewShotText();
}
if (sqlInfo.parsedS2SQL) {
text += getParsedS2SQLText();
}
if (sqlInfo.correctedS2SQL) {
text += getCorrectedS2SQLText();
}
if (sqlInfo.querySQL) {
text += getQuerySQLText();
}
exportTextFile(text, 'file.txt');
};
return (
<div className={`${tipPrefixCls}-parse-tip`}>
<div className={`${tipPrefixCls}-title-bar`}>
@@ -123,6 +217,10 @@ const SqlItem: React.FC<Props> = ({
SQL
</div>
)}
<Button className={`${prefixCls}-export-log`} size="small" onClick={onExportLog}>
<DownloadOutlined />
</Button>
</div>
</div>
<div

View File

@@ -10,7 +10,7 @@ import {
SimilarQuestionType,
} from '../../common/type';
import { useEffect, useState } from 'react';
import { chatExecute, chatParse, queryData, queryEntityInfo, switchEntity } from '../../service';
import { chatExecute, chatParse, queryData, switchEntity } from '../../service';
import { PARSE_ERROR_TIP, PREFIX_CLS, SEARCH_EXCEPTION_TIP } from '../../common/constants';
import IconFont from '../IconFont';
import ParseTip from './ParseTip';
@@ -292,19 +292,12 @@ const ChatItem: React.FC<Props> = ({
}
};
const getEntityInfo = async (parseInfoValue: ChatContextType) => {
const res = await queryEntityInfo(parseInfoValue.queryId, parseInfoValue.id);
setEntityInfo(res.data);
};
const onSelectParseInfo = async (parseInfoValue: ChatContextType) => {
setParseInfo(parseInfoValue);
updateDimensionFitlers(parseInfoValue.dimensionFilters || []);
setDateInfo(parseInfoValue.dateInfo);
if (parseInfoValue.entityInfo) {
setEntityInfo(parseInfoValue.entityInfo);
} else {
getEntityInfo(parseInfoValue);
}
if (dataCache[parseInfoValue.id!]) {
const { tip, data } = dataCache[parseInfoValue.id!];

View File

@@ -541,6 +541,14 @@
padding: 0 !important;
background-color: transparent !important;
}
&-export-log {
margin-left: 20px;
width: fit-content;
font-weight: normal;
color: var(--text-color-secondary);
font-size: 13px !important;
}
}
.@{sql-item-prefix-cls}-copilot {