diff --git a/src/components/charts/area.tsx b/src/components/charts/area.tsx new file mode 100644 index 00000000..e69de29b diff --git a/src/components/charts/column-bar.tsx b/src/components/charts/column-bar.tsx index d9200054..ca3f0e8b 100644 --- a/src/components/charts/column-bar.tsx +++ b/src/components/charts/column-bar.tsx @@ -83,14 +83,15 @@ const BarChart: React.FC = (props) => { }, style: { - fill: (params: any) => { - return ( - params.color || - 'linear-gradient(90deg,rgba(84, 204, 152,0.8) 0%,rgb(0, 168, 143,.7) 100%)' - ); - }, - radiusTopLeft: 12, - radiusTopRight: 12, + // fill: (params: any) => { + // return ( + // params.color || + // 'linear-gradient(90deg,rgba(84, 204, 152,0.8) 0%,rgb(0, 168, 143,.7) 100%)' + // ); + // }, + // radiusTopLeft: 12, + // radiusTopRight: 12, + fill: 'rgba(84, 204, 152,0.8)', align: 'center', width: 20 } diff --git a/src/components/charts/h-bar.tsx b/src/components/charts/h-bar.tsx index 4d6c9d15..dc3422d0 100644 --- a/src/components/charts/h-bar.tsx +++ b/src/components/charts/h-bar.tsx @@ -64,7 +64,7 @@ const BarChart: React.FC = (props) => { title: { title, style: { - align: 'center', + align: 'start', titleFontSize: 14, titleFill: 'rgba(0,0,0,0.88)', titleFontWeight: 500 @@ -86,8 +86,8 @@ const BarChart: React.FC = (props) => { 'linear-gradient(90deg,rgba(84, 204, 152,0.8) 0%,rgb(0, 168, 143,.7) 100%)' ); }, - radiusTopLeft: 12, - radiusTopRight: 12, + // radiusTopLeft: 12, + // radiusTopRight: 12, height: 20 } }; diff --git a/src/locales/zh-CN/menu.ts b/src/locales/zh-CN/menu.ts index b0dbe0fc..3e9b6d66 100644 --- a/src/locales/zh-CN/menu.ts +++ b/src/locales/zh-CN/menu.ts @@ -1,6 +1,6 @@ export default { 'menu.dashboard': '概览', - 'menu.playground': '对话', + 'menu.playground': '试验场', 'menu.models': '模型', 'menu.resources': '资源', 'menu.apikeys': 'API 密钥', diff --git a/src/locales/zh-CN/playground.ts b/src/locales/zh-CN/playground.ts index b92ab703..fab462d9 100644 --- a/src/locales/zh-CN/playground.ts +++ b/src/locales/zh-CN/playground.ts @@ -1,6 +1,6 @@ export default { 'playground.system.tips': '在这里输入系统消息...', - 'playground.title': '对话', + 'playground.title': '试验场', 'playground.system': '系统', 'playground.user': '用户', 'playground.assistant': '助手', diff --git a/src/pages/dashboard/components/system-load.tsx b/src/pages/dashboard/components/system-load.tsx index 7e6e1fa2..81c5434d 100644 --- a/src/pages/dashboard/components/system-load.tsx +++ b/src/pages/dashboard/components/system-load.tsx @@ -65,19 +65,19 @@ const SystemLoad = () => { diff --git a/src/pages/dashboard/components/usage.tsx b/src/pages/dashboard/components/usage.tsx index 77245dd1..cd607050 100644 --- a/src/pages/dashboard/components/usage.tsx +++ b/src/pages/dashboard/components/usage.tsx @@ -134,8 +134,7 @@ const Usage = () => { tokenList.push({ time: dayjs(item.timestamp * 1000).format('YYYY-MM-DD'), name: 'completion_token', - color: - 'linear-gradient(90deg,rgba(84, 204, 152,0.8) 0%,rgb(0, 168, 143,.7) 100%)', + color: 'rgba(84, 204, 152,0.8)', value: item.value }); }); @@ -143,8 +142,7 @@ const Usage = () => { tokenList.push({ time: dayjs(item.timestamp * 1000).format('YYYY-MM-DD'), name: 'prompt_token', - color: - 'linear-gradient(90deg,rgba(0, 170, 173, 0.8) 0%,rgba(0, 109, 193, 0.7) 100%)', + color: 'rgba(0, 170, 173, 0.8)', value: item.value }); }); @@ -153,15 +151,13 @@ const Usage = () => { userList.push({ name: item.username, type: 'completion_token', - color: - 'linear-gradient(90deg,rgba(84, 204, 152,0.8) 0%,rgb(0, 168, 143,.7) 100%)', + color: 'rgba(84, 204, 152,0.8)', value: item.completion_token_count }); userList.push({ name: item.username, type: 'prompt_token', - color: - 'linear-gradient(90deg,rgba(0, 170, 173, 0.8) 0%,rgba(0, 109, 193, 0.7) 100%)', + color: 'rgba(0, 170, 173, 0.8)', value: item.prompt_token_count }); }); diff --git a/src/pages/llmodels/index.tsx b/src/pages/llmodels/index.tsx index d2cfe2ee..cfdf1133 100644 --- a/src/pages/llmodels/index.tsx +++ b/src/pages/llmodels/index.tsx @@ -374,16 +374,17 @@ const Models: React.FC = () => { fetchData(); // createModelsDataByFetch(); createModelEvent(); - }, [queryParams]); - - useEffect(() => { - // watch models list createModelsChunkRequest(); + return () => { chunkRequedtRef.current?.current?.cancel?.(); }; }, [queryParams]); + useEffect(() => { + // watch models list + }, [queryParams]); + const renderChildren = (list: any) => { return ( diff --git a/src/pages/playground/components/ground-left.tsx b/src/pages/playground/components/ground-left.tsx index 5990daa9..20a169d3 100644 --- a/src/pages/playground/components/ground-left.tsx +++ b/src/pages/playground/components/ground-left.tsx @@ -66,12 +66,7 @@ const MessageList: React.FC = (props) => { setActiveIndex(messageList.length - 1); }; - const joinMessage = (str: any) => { - let data = str; - if (data.startsWith('data:')) { - data = data.substring('data:'.length); - } - const chunk = JSON.parse(data?.trim()); + const joinMessage = (chunk: any) => { if (_.get(chunk, 'choices.0.finish_reason')) { setTokenResult({ ...chunk?.usage @@ -80,7 +75,7 @@ const MessageList: React.FC = (props) => { return true; } contentRef.current = - contentRef.current + _.get(chunk, 'choices.0.delta.content'); + contentRef.current + _.get(chunk, 'choices.0.delta.content', ''); setMessageList([ ...messageList, { @@ -120,11 +115,12 @@ const MessageList: React.FC = (props) => { } const { reader, decoder } = result; - await readStreamData(reader, decoder, (data: any) => { - joinMessage(data); + await readStreamData(reader, decoder, (chunk: any) => { + joinMessage(chunk); }); setLoading(false); } catch (error) { + console.log('error=====', error); setLoading(false); } }; diff --git a/src/pages/playground/components/json b/src/pages/playground/components/json new file mode 100644 index 00000000..e69de29b diff --git a/src/request-config.ts b/src/request-config.ts index 540ce260..42b9604e 100644 --- a/src/request-config.ts +++ b/src/request-config.ts @@ -17,7 +17,7 @@ export const requestConfig: RequestConfig = { message.error(errMsg); } console.log('errorHandler+++++++++++++++', error, opts); - if (response.status === 401) { + if (response?.status === 401) { clearAtomStorage(userAtom); history.push('/login', { replace: true }); diff --git a/src/utils/fetch-chunk-data.ts b/src/utils/fetch-chunk-data.ts index e1f8814a..759efff6 100644 --- a/src/utils/fetch-chunk-data.ts +++ b/src/utils/fetch-chunk-data.ts @@ -1,5 +1,26 @@ import qs from 'query-string'; +const extractJSON = (dataStr: string) => { + const regex = /data:\s*({.*?})(?=\n|$)/g; + let match; + const results: any[] = []; + + if (!dataStr) { + return results; + } + + while ((match = regex.exec(dataStr)) !== null) { + try { + results.push(JSON.parse(match[1])); + } catch (error) { + console.error('JSON parse error:', error, 'for match:', match[1]); + + continue; + } + } + + return results; +}; /** * * @param params data: for post request, params: for get request @@ -48,6 +69,9 @@ export const readStreamData = async ( let chunk = decoder.decode(value, { stream: true }); console.log('chunk==========', chunk); - callback(chunk); + extractJSON(chunk).forEach((data) => { + callback?.(data); + }); + // callback(chunk); await readStreamData(reader, decoder, callback); };