From 197488bff6a97442ebbbd8f180e4e96c9858a830 Mon Sep 17 00:00:00 2001 From: jialin Date: Fri, 27 Sep 2024 19:19:09 +0800 Subject: [PATCH] fix: chat error message --- config/config.ts | 2 +- src/components/auto-tooltip/index.tsx | 2 +- src/components/seal-table/styles/cell.less | 4 ++++ .../llmodels/components/hf-model-file.tsx | 6 ++--- src/pages/llmodels/components/table-list.tsx | 7 ++++-- .../playground/components/ground-left.tsx | 13 ++++++---- .../multiple-chat/active-models.tsx | 10 ++++++-- .../components/multiple-chat/model-item.tsx | 23 +++++++++++------- .../components/reference-params.tsx | 24 ++++++++++++++++--- src/pages/playground/style/multiple-chat.less | 1 - src/utils/fetch-chunk-data.ts | 6 +++-- 11 files changed, 68 insertions(+), 30 deletions(-) diff --git a/config/config.ts b/config/config.ts index 36546891..9dbc3ccd 100644 --- a/config/config.ts +++ b/config/config.ts @@ -14,7 +14,7 @@ const isProduction = env === 'production'; const t = Date.now(); export default defineConfig({ proxy: { - ...proxy() + ...proxy('http://192.168.50.166:8080') }, history: { type: 'hash' diff --git a/src/components/auto-tooltip/index.tsx b/src/components/auto-tooltip/index.tsx index 7c2062e7..afa82eec 100644 --- a/src/components/auto-tooltip/index.tsx +++ b/src/components/auto-tooltip/index.tsx @@ -32,7 +32,7 @@ const AutoTooltip: React.FC = ({ const { scrollWidth, clientWidth } = contentRef.current; setIsOverflowing(scrollWidth > clientWidth); } - }, []); + }, [contentRef.current]); const debouncedCheckOverflow = useMemo( () => debounce(checkOverflow, 200), diff --git a/src/components/seal-table/styles/cell.less b/src/components/seal-table/styles/cell.less index 5103e915..99f048ab 100644 --- a/src/components/seal-table/styles/cell.less +++ b/src/components/seal-table/styles/cell.less @@ -6,6 +6,10 @@ justify-content: flex-start; height: 68px; + .cell-content { + max-width: 100%; + } + &-left { justify-content: flex-start; } diff --git a/src/pages/llmodels/components/hf-model-file.tsx b/src/pages/llmodels/components/hf-model-file.tsx index 6764252c..cb46777e 100644 --- a/src/pages/llmodels/components/hf-model-file.tsx +++ b/src/pages/llmodels/components/hf-model-file.tsx @@ -139,7 +139,7 @@ const HFModelFile: React.FC = forwardRef((props, ref) => { }); const list = _.filter(fileList, (file: any) => { - return filterReg.test(file.path) || _.includes(includeReg, file.path); + return filterRegGGUF.test(file.path) || _.includes(file.path, '.gguf'); }); return list; @@ -160,9 +160,7 @@ const HFModelFile: React.FC = forwardRef((props, ref) => { } ); const fileList = _.filter(_.get(data, ['Data', 'Files']), (file: any) => { - return ( - filterRegGGUF.test(file.Path) || _.includes(filterRegGGUF, file.Path) - ); + return filterRegGGUF.test(file.Path) || _.includes(file.Path, '.gguf'); }); const list = _.map(fileList, (item: any) => { diff --git a/src/pages/llmodels/components/table-list.tsx b/src/pages/llmodels/components/table-list.tsx index 2680e910..c41d96ec 100644 --- a/src/pages/llmodels/components/table-list.tsx +++ b/src/pages/llmodels/components/table-list.tsx @@ -1,3 +1,4 @@ +import AutoTooltip from '@/components/auto-tooltip'; import DeleteModal from '@/components/delete-modal'; import DropdownButtons from '@/components/drop-down-buttons'; import IconFont from '@/components/icon-font'; @@ -518,8 +519,10 @@ const Models: React.FC = ({ span={5} render={(text, record: ListItem) => { return ( - - {text} + + + {text} + {record.embedding_only && ( diff --git a/src/pages/playground/components/ground-left.tsx b/src/pages/playground/components/ground-left.tsx index 5b0ca089..335278b7 100644 --- a/src/pages/playground/components/ground-left.tsx +++ b/src/pages/playground/components/ground-left.tsx @@ -172,13 +172,17 @@ const GroundLeft: React.FC = forwardRef((props, ref) => { ...parameters, stream: true }; - const result = await fetchChunkedData({ + const result: any = await fetchChunkedData({ data: chatParams, url: CHAT_API, signal }); - if (!result) { + if (result?.error) { + setTokenResult({ + error: true, + errorMessage: result?.data?.message + }); return; } setMessageId(); @@ -186,10 +190,9 @@ const GroundLeft: React.FC = forwardRef((props, ref) => { await readStreamData(reader, decoder, (chunk: any) => { joinMessage(chunk); }); - setLoading(false); } catch (error) { - console.log('error=====', error); - + // console.log('error:', error); + } finally { setLoading(false); } }; diff --git a/src/pages/playground/components/multiple-chat/active-models.tsx b/src/pages/playground/components/multiple-chat/active-models.tsx index 37570f11..9707c9f8 100644 --- a/src/pages/playground/components/multiple-chat/active-models.tsx +++ b/src/pages/playground/components/multiple-chat/active-models.tsx @@ -15,9 +15,15 @@ interface ActiveModelsProps { const ActiveModels: React.FC = (props) => { const { spans, modelSelections, setModelRefs } = props; return ( - + {modelSelections.map((model, index) => ( - + ) => diff --git a/src/pages/playground/components/multiple-chat/model-item.tsx b/src/pages/playground/components/multiple-chat/model-item.tsx index c3cad8cc..41c3b8b1 100644 --- a/src/pages/playground/components/multiple-chat/model-item.tsx +++ b/src/pages/playground/components/multiple-chat/model-item.tsx @@ -65,7 +65,7 @@ const ModelItem: React.FC = forwardRef( const currentMessageRef = useRef([]); const modelScrollRef = useRef(null); - const { initialize } = useOverlayScroller(); + const { initialize, updateScrollerPosition } = useOverlayScroller(); const setMessageId = () => { messageId.current = messageId.current + 1; @@ -180,13 +180,17 @@ const ModelItem: React.FC = forwardRef( stream: true }; // ============== payload end ================ - const result = await fetchChunkedData({ + const result: any = await fetchChunkedData({ data: chatParams, url: CHAT_API, signal }); - if (!result) { + if (result?.error) { + setTokenResult({ + error: true, + errorMessage: result?.data?.message + }); return; } setMessageId(); @@ -194,8 +198,9 @@ const ModelItem: React.FC = forwardRef( await readStreamData(reader, decoder, (chunk: any) => { joinMessage(chunk); }); - setLoadingStatus(instanceId, false); } catch (error) { + // console.log('error:', error); + } finally { setLoadingStatus(instanceId, false); } }; @@ -338,6 +343,10 @@ const ModelItem: React.FC = forwardRef( } }, [modelScrollRef.current, initialize]); + useEffect(() => { + updateScrollerPosition(); + }, [messageList]); + useImperativeHandle(ref, () => { return { submit: handleSubmit, @@ -415,11 +424,7 @@ const ModelItem: React.FC = forwardRef( applyToAll={handleApplySystemChangeToAll} setSystemMessage={setSystemMessage} > -
+
{ const intl = useIntl(); const { usage } = props; - if (!usage) { + if (!usage || _.isEmpty(usage)) { return null; } - console.log('ReferenceParams usage:', usage); + if (usage.error) { + return ( + + + {usage?.errorMessage} + + } + banner + showIcon={false} + /> + ); + } return (
diff --git a/src/pages/playground/style/multiple-chat.less b/src/pages/playground/style/multiple-chat.less index 67cae0bf..7ad5f6d5 100644 --- a/src/pages/playground/style/multiple-chat.less +++ b/src/pages/playground/style/multiple-chat.less @@ -6,7 +6,6 @@ .chat-list { flex: 1; overflow-y: auto; - padding-bottom: 16px; padding-inline: var(--layout-content-inlinepadding); } diff --git a/src/utils/fetch-chunk-data.ts b/src/utils/fetch-chunk-data.ts index 6f35d3ad..99024676 100644 --- a/src/utils/fetch-chunk-data.ts +++ b/src/utils/fetch-chunk-data.ts @@ -47,8 +47,10 @@ export const fetchChunkedData = async (params: { } }); if (!response.ok) { - throw new Error('Network response was not ok'); - return null; + return { + error: true, + data: await response.json() + }; } const reader = response?.body?.getReader(); const decoder = new TextDecoder('utf-8');