From 8282f48cdb005a63f4b8bab5148ca0f2bddde89c Mon Sep 17 00:00:00 2001 From: jialin Date: Fri, 10 Jan 2025 15:31:28 +0800 Subject: [PATCH] fix: calc log lines --- .../logs-viewer/logs-pagination.tsx | 32 ++++++++++--------- src/components/logs-viewer/parse-worker.ts | 17 ++++++---- .../logs-viewer/virtual-log-list.tsx | 20 ++++++------ .../playground/components/ground-stt.tsx | 3 +- .../playground/components/params-settings.tsx | 11 ++++--- 5 files changed, 47 insertions(+), 36 deletions(-) diff --git a/src/components/logs-viewer/logs-pagination.tsx b/src/components/logs-viewer/logs-pagination.tsx index ef1b03f7..2d9ed6d0 100644 --- a/src/components/logs-viewer/logs-pagination.tsx +++ b/src/components/logs-viewer/logs-pagination.tsx @@ -31,22 +31,24 @@ const LogsPagination: React.FC = (props) => { return (
- - - + + + )} {page} /{' '} {total} diff --git a/src/components/logs-viewer/parse-worker.ts b/src/components/logs-viewer/parse-worker.ts index 7cfd1635..e179653f 100644 --- a/src/components/logs-viewer/parse-worker.ts +++ b/src/components/logs-viewer/parse-worker.ts @@ -23,8 +23,7 @@ const parseAnsi = (input: string, setId: () => number) => { let cursorCol = 0; let screen = [['']]; let lastIndex = 0; - - // let input = inputStr.replace(replaceLineRegex, '\n'); + let rawDataRows = 1; // handle the \r and \n characters in the text const handleText = (text: string) => { @@ -33,6 +32,7 @@ const parseAnsi = (input: string, setId: () => number) => { if (char === '\r') { cursorCol = 0; // move to the beginning of the line } else if (char === '\n') { + rawDataRows++; cursorRow++; // move to the next line cursorCol = 0; // move to the beginning of the line screen[cursorRow] = screen[cursorRow] || ['']; // create a new line if it does not exist @@ -138,20 +138,25 @@ const parseAnsi = (input: string, setId: () => number) => { uid: setId() }); - return result; + return { + data: result, + lines: rawDataRows + }; }; self.onmessage = function (event) { const { inputStr } = event.data; - const parsedData = Array.from(parseAnsi(inputStr, setId)); + const { data: parsedData, lines } = parseAnsi(inputStr, setId); const result = parsedData.map((item) => ({ content: item.content, uid: item.uid })); - console.log('result===', result); - self.postMessage(result); + self.postMessage({ + result, + lines + }); }; self.onerror = function (event) { diff --git a/src/components/logs-viewer/virtual-log-list.tsx b/src/components/logs-viewer/virtual-log-list.tsx index 8a7768ef..6cd7ce41 100644 --- a/src/components/logs-viewer/virtual-log-list.tsx +++ b/src/components/logs-viewer/virtual-log-list.tsx @@ -50,7 +50,8 @@ const LogsViewer: React.FC = forwardRef((props, ref) => { pos: 'bottom', page: 1 }); - const dataLenRef = useRef(0); + const dataLengthRef = useRef(0); + const lineCountRef = useRef(0); useImperativeHandle(ref, () => ({ abort() { @@ -71,9 +72,9 @@ const LogsViewer: React.FC = forwardRef((props, ref) => { ); logParseWorker.current.onmessage = (event: any) => { - const res = event.data; - console.log('res===', res); - setLogs(res); + const { result, lines } = event.data; + lineCountRef.current = lines; + setLogs(result); }; return () => { @@ -100,7 +101,6 @@ const LogsViewer: React.FC = forwardRef((props, ref) => { let result = ''; const totalPage = Math.ceil(list.length / pageSize); - console.log('loading== getLastPage ========', isLoadingMoreRef.current); pageRef.current = totalPage; totalPageRef.current = totalPage; @@ -122,7 +122,6 @@ const LogsViewer: React.FC = forwardRef((props, ref) => { const getCurrentPage = () => { const list = _.split(cacheDataRef.current.trim(), '\n'); const totalPage = Math.ceil(list.length / pageSize); - console.log('loading== getCurrentPage ========', isLoadingMoreRef.current); let newPage = pageRef.current; if (newPage < 1) { newPage = 1; @@ -208,7 +207,8 @@ const LogsViewer: React.FC = forwardRef((props, ref) => { pos: 'bottom', page: newPage }; - pageRef.current = newPage; + pageRef.current = totalPage; + totalPageRef.current = totalPage; logParseWorker.current.postMessage({ inputStr: nextPage }); @@ -216,7 +216,6 @@ const LogsViewer: React.FC = forwardRef((props, ref) => { const updateContent = (inputStr: string) => { const data = inputStr.replace(replaceLineRegex, '\n'); - dataLenRef.current = data.length; if (isClean(data)) { cacheDataRef.current = data; } else { @@ -259,7 +258,8 @@ const LogsViewer: React.FC = forwardRef((props, ref) => { isBottom, loadMoreDone: loadMoreDone.current, loading: loading, - loglen: dataLenRef.current + lineCount: lineCountRef.current, + dataLength: dataLengthRef.current }); if (isBottom) { scrollPosRef.current = { @@ -280,7 +280,7 @@ const LogsViewer: React.FC = forwardRef((props, ref) => { if ( loading || (logs.length > 0 && - dataLenRef.current < pageSize && + lineCountRef.current < pageSize && !loadMoreDone.current) || !enableScorllLoad ) { diff --git a/src/pages/playground/components/ground-stt.tsx b/src/pages/playground/components/ground-stt.tsx index c84a8b08..612a74b3 100644 --- a/src/pages/playground/components/ground-stt.tsx +++ b/src/pages/playground/components/ground-stt.tsx @@ -412,7 +412,8 @@ const GroundLeft: React.FC = forwardRef((props, ref) => { padding: '8px 14px', lineHeight: '20px', display: 'flex', - justifyContent: 'center' + justifyContent: 'center', + wordBreak: 'break-word' }} > {messageList.length ? ( diff --git a/src/pages/playground/components/params-settings.tsx b/src/pages/playground/components/params-settings.tsx index 17c293ad..4fc5efc9 100644 --- a/src/pages/playground/components/params-settings.tsx +++ b/src/pages/playground/components/params-settings.tsx @@ -36,7 +36,7 @@ const METAKEYS: Record = { top_p: 'top_p', n_ctx: 'n_ctx', n_slot: 'n_slot', - max_model_len: 'max_tokens' + max_model_len: 'max_model_len' }; const ParamsSettings: React.FC = ({ @@ -114,18 +114,21 @@ const ParamsSettings: React.FC = ({ if (obj.n_ctx && obj.n_slot) { defaultMaxTokens = _.divide(obj.n_ctx / 2, obj.n_slot); + } else if (obj.max_model_len) { + defaultMaxTokens = obj.max_model_len / 2; } form.setFieldsValue({ - ..._.omit(obj, ['n_ctx', 'n_slot']), + ..._.omit(obj, ['n_ctx', 'n_slot', 'max_model_len']), max_tokens: defaultMaxTokens }); + setMetaData({ ...obj, - max_tokens: _.divide(obj.n_ctx, obj.n_slot) + max_tokens: obj.max_model_len || _.divide(obj.n_ctx, obj.n_slot) }); return { - ..._.omit(obj, ['n_ctx', 'n_slot']), + ..._.omit(obj, ['n_ctx', 'n_slot', 'max_model_len']), max_tokens: defaultMaxTokens }; };