(feature)(chat-sdk) modify the method for obtaining similar questions and recommended drill-down dimensions; do not display assistant button when there is only one assistant (#514)

This commit is contained in:
williamhliu
2023-12-15 17:41:35 +08:00
committed by GitHub
parent 4dae84034e
commit 4b00c16eb7
9 changed files with 107 additions and 57 deletions

View File

@@ -311,10 +311,12 @@ const ChatFooter: ForwardRefRenderFunction<any, Props> = (
<div></div>
</div>
)}
<div className={styles.toolItem} onClick={onOpenAgents}>
<IconFont type="icon-zhinengzhuli" className={styles.toolIcon} />
<div></div>
</div>
{agentList?.length > 1 && (
<div className={styles.toolItem} onClick={onOpenAgents}>
<IconFont type="icon-zhinengzhuli" className={styles.toolIcon} />
<div></div>
</div>
)}
{!isMobile && (
<div className={styles.toolItem} onClick={onOpenShowcase}>
<IconFont type="icon-showcase" className={styles.toolIcon} />

View File

@@ -177,7 +177,7 @@ const Chat: ForwardRefRenderFunction<any, Props> = (
msg: item.queryText,
parseInfos: item.parseInfos,
parseTimeCost: item.parseTimeCost,
msgData: item.queryResult,
msgData: { ...(item.queryResult || {}), similarQueries: item.similarQueries },
score: item.score,
agentId: currentAgent?.id,
}));

View File

@@ -140,6 +140,8 @@ export type MsgDataType = {
response: PluginResonseType;
parseInfos?: ChatContextType[];
queryTimeCost?: number;
similarQueries: SimilarQuestionType[];
recommendedDimensions: DrillDownDimensionType[];
};
export enum ParseStateEnum {
@@ -220,6 +222,7 @@ export type HistoryMsgItemType = {
createTime: string;
feedback: string;
score: number;
similarQueries: SimilarQuestionType[];
};
export type HistoryType = {
@@ -242,8 +245,8 @@ export type SendMsgParamsType = {
};
export type SimilarQuestionType = {
// queryId: number;
// parseId: number;
queryId: number;
parseId: number;
queryText: string;
};

View File

@@ -5,21 +5,21 @@ import { useEffect, useState } from 'react';
import { querySimilarQuestions } from '../../service';
type Props = {
// similarQuestions: SimilarQuestionType[];
queryText: string;
agentId?: number;
queryId?: number;
similarQueries?: SimilarQuestionType[];
defaultExpanded?: boolean;
onSelectQuestion: (question: SimilarQuestionType) => void;
};
const SimilarQuestions: React.FC<Props> = ({
// similarQuestions,
queryText,
agentId,
queryId,
similarQueries,
defaultExpanded,
onSelectQuestion,
}) => {
const [similarQuestions, setSimilarQuestions] = useState<SimilarQuestionType[]>([]);
const [similarQuestions, setSimilarQuestions] = useState<SimilarQuestionType[]>(
similarQueries || []
);
const [expanded, setExpanded] = useState(defaultExpanded || false);
const [loading, setLoading] = useState(false);
@@ -28,9 +28,9 @@ const SimilarQuestions: React.FC<Props> = ({
const initData = async () => {
setLoading(true);
const res = await querySimilarQuestions(queryText, agentId);
const res = await querySimilarQuestions(queryId!);
setLoading(false);
setSimilarQuestions(res.data || []);
setSimilarQuestions(res.data?.similarQueries || []);
};
useEffect(() => {

View File

@@ -97,7 +97,9 @@ const ChatItem: React.FC<Props> = ({
data = res.data;
tip = '';
}
setDataCache({ ...dataCache, [chatContext!.id!]: { tip, data } });
if (chatContext) {
setDataCache({ ...dataCache, [chatContext!.id!]: { tip, data } });
}
if (data) {
setData(data);
setExecuteTip('');
@@ -356,9 +358,9 @@ const ChatItem: React.FC<Props> = ({
)}
{(parseTip !== '' || (executeMode && !executeLoading)) && integrateSystem !== 'c2' && (
<SimilarQuestionItem
queryText={msg || msgData?.queryText || ''}
agentId={agentId}
queryId={parseInfo?.queryId}
defaultExpanded={parseTip !== '' || executeTip !== '' || integrateSystem === 'wiki'}
similarQueries={data?.similarQueries}
onSelectQuestion={onSelectQuestion}
/>
)}

View File

@@ -244,7 +244,7 @@
&-tip-content-option-disabled {
cursor: auto;
&:hover {
&:hover {
color: var(--text-color-secondary);
border-color: var(--border-color-base);
}
@@ -414,12 +414,14 @@
font-weight: normal;
}
.ant-select-selector, .ant-input-number-input {
.ant-select-selector,
.ant-input-number-input {
background-color: #f5f8fb !important;
border-color: #ececec !important;
}
.ant-select-selection-item, .ant-input-number-input {
.ant-select-selection-item,
.ant-input-number-input {
color: var(--chat-blue);
font-weight: 500;
}
@@ -447,7 +449,7 @@
margin-right: 10px;
cursor: pointer;
}
&-code {
margin-top: 10px !important;
padding: 6px 14px 8px !important;
@@ -455,7 +457,7 @@
border-radius: 4px !important;
background: #f5f8fb !important;
}
&-copy-btn {
position: absolute;
top: 24px;

View File

@@ -270,8 +270,7 @@ const ChatMsg: React.FC<Props> = ({ queryId, data, chartIndex, triggerResize })
)}
{existDrillDownDimension && (
<DrillDownDimensions
modelId={chatContext.modelId}
metricId={activeMetricField?.id || defaultMetricField?.id}
drillDownDimensions={data?.recommendedDimensions || []}
drillDownDimension={drillDownDimension}
secondDrillDownDimension={secondDrillDownDimension}
originDimensions={chatContext.dimensions}

View File

@@ -1,12 +1,10 @@
import { useEffect, useState } from 'react';
import { CLS_PREFIX } from '../../common/constants';
import { DrillDownDimensionType, FilterItemType } from '../../common/type';
import { queryDrillDownDimensions } from '../../service';
import DimensionSection from './DimensionSection';
type Props = {
modelId: number;
metricId?: number;
drillDownDimensions: DrillDownDimensionType[];
drillDownDimension?: DrillDownDimensionType;
secondDrillDownDimension?: DrillDownDimensionType;
originDimensions?: DrillDownDimensionType[];
@@ -18,8 +16,7 @@ type Props = {
const MAX_DIMENSION_COUNT = 20;
const DrillDownDimensions: React.FC<Props> = ({
modelId,
metricId,
drillDownDimensions,
drillDownDimension,
secondDrillDownDimension,
originDimensions,
@@ -32,9 +29,8 @@ const DrillDownDimensions: React.FC<Props> = ({
const prefixCls = `${CLS_PREFIX}-drill-down-dimensions`;
const initData = async () => {
const res = await queryDrillDownDimensions(modelId, metricId);
setDimensions(
res.data.dimensions
drillDownDimensions
.filter(
dimension =>
!dimensionFilters?.some(filter => filter.name === dimension.name) &&

View File

@@ -1,17 +1,31 @@
import axios from './axiosInstance';
import { ChatContextType, DrillDownDimensionType, EntityInfoType, HistoryType, MsgDataType, ParseDataType, SearchRecommendItem } from '../common/type';
import {
ChatContextType,
DrillDownDimensionType,
EntityInfoType,
HistoryMsgItemType,
HistoryType,
MsgDataType,
ParseDataType,
SearchRecommendItem,
} from '../common/type';
import { isMobile } from '../utils/utils';
const DEFAULT_CHAT_ID = 0;
const prefix = isMobile ? '/openapi' : '/api';
export function searchRecommend(queryText: string, chatId?: number, modelId?: number, agentId?: number) {
export function searchRecommend(
queryText: string,
chatId?: number,
modelId?: number,
agentId?: number
) {
return axios.post<SearchRecommendItem[]>(`${prefix}/chat/query/search`, {
queryText,
chatId: chatId || DEFAULT_CHAT_ID,
modelId,
agentId
agentId,
});
}
@@ -20,30 +34,40 @@ export function chatQuery(queryText: string, chatId?: number, modelId?: number,
queryText,
chatId: chatId || DEFAULT_CHAT_ID,
modelId,
queryFilters: filters ? {
filters
} : undefined,
queryFilters: filters
? {
filters,
}
: undefined,
});
}
export function chatParse(queryText: string, chatId?: number, modelId?: number, agentId?: number, filters?: any[]) {
export function chatParse(
queryText: string,
chatId?: number,
modelId?: number,
agentId?: number,
filters?: any[]
) {
return axios.post<ParseDataType>(`${prefix}/chat/query/parse`, {
queryText,
chatId: chatId || DEFAULT_CHAT_ID,
modelId,
agentId,
queryFilters: filters ? {
filters
} : undefined,
queryFilters: filters
? {
filters,
}
: undefined,
});
}
export function chatExecute(queryText: string, chatId: number, parseInfo: ChatContextType ) {
export function chatExecute(queryText: string, chatId: number, parseInfo: ChatContextType) {
return axios.post<MsgDataType>(`${prefix}/chat/query/execute`, {
queryText,
chatId: chatId || DEFAULT_CHAT_ID,
queryId: parseInfo.queryId,
parseId: parseInfo.id
parseId: parseInfo.id,
});
}
@@ -59,13 +83,21 @@ export function queryData(chatContext: Partial<ChatContextType>) {
return axios.post<MsgDataType>(`${prefix}/chat/query/queryData`, chatContext);
}
export function getHistoryMsg(current: number, chatId: number = DEFAULT_CHAT_ID, pageSize: number = 10) {
export function getHistoryMsg(
current: number,
chatId: number = DEFAULT_CHAT_ID,
pageSize: number = 10
) {
return axios.post<HistoryType>(`${prefix}/chat/manage/pageQueryInfo?chatId=${chatId}`, {
current,
pageSize,
});
}
export function querySimilarQuestions(queryId: number) {
return axios.get<HistoryMsgItemType>(`${prefix}/chat/manage/getChatQuery/${queryId}`);
}
export function queryEntities(entityId: string | number, modelId: number) {
return axios.post<any>(`${prefix}/chat/query/choice`, {
entityId,
@@ -74,21 +106,35 @@ export function queryEntities(entityId: string | number, modelId: number) {
}
export function updateQAFeedback(questionId: number, score: number) {
return axios.post<any>(`${prefix}/chat/manage/updateQAFeedback?id=${questionId}&score=${score}&feedback=`);
return axios.post<any>(
`${prefix}/chat/manage/updateQAFeedback?id=${questionId}&score=${score}&feedback=`
);
}
export function queryDrillDownDimensions(modelId: number, metricId?: number) {
return axios.get<{ dimensions: DrillDownDimensionType[] }>(`${prefix}/chat/recommend/metric/${modelId}${metricId ? `?metricId=${metricId}` : ''}`);
export function queryDimensionValues(
modelId: number,
bizName: string,
agentId: number,
elementID: number,
value: string
) {
return axios.post<any>(`${prefix}/chat/query/queryDimensionValue`, {
modelId,
bizName,
agentId,
elementID,
value,
});
}
export function queryDimensionValues(modelId: number, bizName: string, agentId: number, elementID: number, value: string) {
return axios.post<any>(`${prefix}/chat/query/queryDimensionValue`, { modelId, bizName, agentId, elementID, value});
}
export function querySimilarQuestions(queryText: string, agentId?: number) {
return axios.get<any>(`${prefix}/chat/manage/getSolvedQuery?queryText=${queryText}&agentId=${agentId || 0}`);
}
// export function querySimilarQuestions(queryText: string, agentId?: number) {
// return axios.get<any>(
// `${prefix}/chat/manage/getSolvedQuery?queryText=${queryText}&agentId=${agentId || 0}`
// );
// }
export function queryEntityInfo(queryId: number, parseId: number) {
return axios.get<EntityInfoType>(`${prefix}/chat/query/getEntityInfo?queryId=${queryId}&parseId=${parseId}`)
return axios.get<EntityInfoType>(
`${prefix}/chat/query/getEntityInfo?queryId=${queryId}&parseId=${parseId}`
);
}