fix: completion response handler
This commit is contained in:
@@ -83,14 +83,15 @@ const BarChart: React.FC<BarChartProps> = (props) => {
|
|||||||
},
|
},
|
||||||
|
|
||||||
style: {
|
style: {
|
||||||
fill: (params: any) => {
|
// fill: (params: any) => {
|
||||||
return (
|
// return (
|
||||||
params.color ||
|
// params.color ||
|
||||||
'linear-gradient(90deg,rgba(84, 204, 152,0.8) 0%,rgb(0, 168, 143,.7) 100%)'
|
// 'linear-gradient(90deg,rgba(84, 204, 152,0.8) 0%,rgb(0, 168, 143,.7) 100%)'
|
||||||
);
|
// );
|
||||||
},
|
// },
|
||||||
radiusTopLeft: 12,
|
// radiusTopLeft: 12,
|
||||||
radiusTopRight: 12,
|
// radiusTopRight: 12,
|
||||||
|
fill: 'rgba(84, 204, 152,0.8)',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
width: 20
|
width: 20
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ const BarChart: React.FC<BarChartProps> = (props) => {
|
|||||||
title: {
|
title: {
|
||||||
title,
|
title,
|
||||||
style: {
|
style: {
|
||||||
align: 'center',
|
align: 'start',
|
||||||
titleFontSize: 14,
|
titleFontSize: 14,
|
||||||
titleFill: 'rgba(0,0,0,0.88)',
|
titleFill: 'rgba(0,0,0,0.88)',
|
||||||
titleFontWeight: 500
|
titleFontWeight: 500
|
||||||
@@ -86,8 +86,8 @@ const BarChart: React.FC<BarChartProps> = (props) => {
|
|||||||
'linear-gradient(90deg,rgba(84, 204, 152,0.8) 0%,rgb(0, 168, 143,.7) 100%)'
|
'linear-gradient(90deg,rgba(84, 204, 152,0.8) 0%,rgb(0, 168, 143,.7) 100%)'
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
radiusTopLeft: 12,
|
// radiusTopLeft: 12,
|
||||||
radiusTopRight: 12,
|
// radiusTopRight: 12,
|
||||||
height: 20
|
height: 20
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
export default {
|
export default {
|
||||||
'menu.dashboard': '概览',
|
'menu.dashboard': '概览',
|
||||||
'menu.playground': '对话',
|
'menu.playground': '试验场',
|
||||||
'menu.models': '模型',
|
'menu.models': '模型',
|
||||||
'menu.resources': '资源',
|
'menu.resources': '资源',
|
||||||
'menu.apikeys': 'API 密钥',
|
'menu.apikeys': 'API 密钥',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
export default {
|
export default {
|
||||||
'playground.system.tips': '在这里输入系统消息...',
|
'playground.system.tips': '在这里输入系统消息...',
|
||||||
'playground.title': '对话',
|
'playground.title': '试验场',
|
||||||
'playground.system': '系统',
|
'playground.system': '系统',
|
||||||
'playground.user': '用户',
|
'playground.user': '用户',
|
||||||
'playground.assistant': '助手',
|
'playground.assistant': '助手',
|
||||||
|
|||||||
@@ -65,19 +65,19 @@ const SystemLoad = () => {
|
|||||||
<Row style={{ height: largeChartHeight, width: '100%' }}>
|
<Row style={{ height: largeChartHeight, width: '100%' }}>
|
||||||
<Col span={12} style={{ height: smallChartHeight }}>
|
<Col span={12} style={{ height: smallChartHeight }}>
|
||||||
<UitilBar
|
<UitilBar
|
||||||
title="GPU Compute Utilization"
|
title="GPU Utilization"
|
||||||
percent={_.round(data.gpu?.utilization_rate || 0, 1)}
|
percent={_.round(data.gpu?.utilization_rate || 0, 1)}
|
||||||
></UitilBar>
|
></UitilBar>
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={12} style={{ height: smallChartHeight }}>
|
<Col span={12} style={{ height: smallChartHeight }}>
|
||||||
<UitilBar
|
<UitilBar
|
||||||
title="GPU Memory Utilization"
|
title="VRAM Utilization"
|
||||||
percent={_.round(data.gpu_memory?.utilization_rate || 0, 1)}
|
percent={_.round(data.gpu_memory?.utilization_rate || 0, 1)}
|
||||||
></UitilBar>
|
></UitilBar>
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={12} style={{ height: smallChartHeight }}>
|
<Col span={12} style={{ height: smallChartHeight }}>
|
||||||
<UitilBar
|
<UitilBar
|
||||||
title="CPU Compute Utilization"
|
title="CPU Utilization"
|
||||||
percent={_.round(data.cpu?.utilization_rate || 0, 1)}
|
percent={_.round(data.cpu?.utilization_rate || 0, 1)}
|
||||||
></UitilBar>
|
></UitilBar>
|
||||||
</Col>
|
</Col>
|
||||||
|
|||||||
@@ -134,8 +134,7 @@ const Usage = () => {
|
|||||||
tokenList.push({
|
tokenList.push({
|
||||||
time: dayjs(item.timestamp * 1000).format('YYYY-MM-DD'),
|
time: dayjs(item.timestamp * 1000).format('YYYY-MM-DD'),
|
||||||
name: 'completion_token',
|
name: 'completion_token',
|
||||||
color:
|
color: 'rgba(84, 204, 152,0.8)',
|
||||||
'linear-gradient(90deg,rgba(84, 204, 152,0.8) 0%,rgb(0, 168, 143,.7) 100%)',
|
|
||||||
value: item.value
|
value: item.value
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -143,8 +142,7 @@ const Usage = () => {
|
|||||||
tokenList.push({
|
tokenList.push({
|
||||||
time: dayjs(item.timestamp * 1000).format('YYYY-MM-DD'),
|
time: dayjs(item.timestamp * 1000).format('YYYY-MM-DD'),
|
||||||
name: 'prompt_token',
|
name: 'prompt_token',
|
||||||
color:
|
color: 'rgba(0, 170, 173, 0.8)',
|
||||||
'linear-gradient(90deg,rgba(0, 170, 173, 0.8) 0%,rgba(0, 109, 193, 0.7) 100%)',
|
|
||||||
value: item.value
|
value: item.value
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -153,15 +151,13 @@ const Usage = () => {
|
|||||||
userList.push({
|
userList.push({
|
||||||
name: item.username,
|
name: item.username,
|
||||||
type: 'completion_token',
|
type: 'completion_token',
|
||||||
color:
|
color: 'rgba(84, 204, 152,0.8)',
|
||||||
'linear-gradient(90deg,rgba(84, 204, 152,0.8) 0%,rgb(0, 168, 143,.7) 100%)',
|
|
||||||
value: item.completion_token_count
|
value: item.completion_token_count
|
||||||
});
|
});
|
||||||
userList.push({
|
userList.push({
|
||||||
name: item.username,
|
name: item.username,
|
||||||
type: 'prompt_token',
|
type: 'prompt_token',
|
||||||
color:
|
color: 'rgba(0, 170, 173, 0.8)',
|
||||||
'linear-gradient(90deg,rgba(0, 170, 173, 0.8) 0%,rgba(0, 109, 193, 0.7) 100%)',
|
|
||||||
value: item.prompt_token_count
|
value: item.prompt_token_count
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -374,14 +374,15 @@ const Models: React.FC = () => {
|
|||||||
fetchData();
|
fetchData();
|
||||||
// createModelsDataByFetch();
|
// createModelsDataByFetch();
|
||||||
createModelEvent();
|
createModelEvent();
|
||||||
|
createModelsChunkRequest();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
chunkRequedtRef.current?.current?.cancel?.();
|
||||||
|
};
|
||||||
}, [queryParams]);
|
}, [queryParams]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// watch models list
|
// watch models list
|
||||||
createModelsChunkRequest();
|
|
||||||
return () => {
|
|
||||||
chunkRequedtRef.current?.current?.cancel?.();
|
|
||||||
};
|
|
||||||
}, [queryParams]);
|
}, [queryParams]);
|
||||||
|
|
||||||
const renderChildren = (list: any) => {
|
const renderChildren = (list: any) => {
|
||||||
|
|||||||
@@ -66,12 +66,7 @@ const MessageList: React.FC<MessageProps> = (props) => {
|
|||||||
setActiveIndex(messageList.length - 1);
|
setActiveIndex(messageList.length - 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
const joinMessage = (str: any) => {
|
const joinMessage = (chunk: any) => {
|
||||||
let data = str;
|
|
||||||
if (data.startsWith('data:')) {
|
|
||||||
data = data.substring('data:'.length);
|
|
||||||
}
|
|
||||||
const chunk = JSON.parse(data?.trim());
|
|
||||||
if (_.get(chunk, 'choices.0.finish_reason')) {
|
if (_.get(chunk, 'choices.0.finish_reason')) {
|
||||||
setTokenResult({
|
setTokenResult({
|
||||||
...chunk?.usage
|
...chunk?.usage
|
||||||
@@ -80,7 +75,7 @@ const MessageList: React.FC<MessageProps> = (props) => {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
contentRef.current =
|
contentRef.current =
|
||||||
contentRef.current + _.get(chunk, 'choices.0.delta.content');
|
contentRef.current + _.get(chunk, 'choices.0.delta.content', '');
|
||||||
setMessageList([
|
setMessageList([
|
||||||
...messageList,
|
...messageList,
|
||||||
{
|
{
|
||||||
@@ -120,11 +115,12 @@ const MessageList: React.FC<MessageProps> = (props) => {
|
|||||||
}
|
}
|
||||||
const { reader, decoder } = result;
|
const { reader, decoder } = result;
|
||||||
|
|
||||||
await readStreamData(reader, decoder, (data: any) => {
|
await readStreamData(reader, decoder, (chunk: any) => {
|
||||||
joinMessage(data);
|
joinMessage(chunk);
|
||||||
});
|
});
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log('error=====', error);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export const requestConfig: RequestConfig = {
|
|||||||
message.error(errMsg);
|
message.error(errMsg);
|
||||||
}
|
}
|
||||||
console.log('errorHandler+++++++++++++++', error, opts);
|
console.log('errorHandler+++++++++++++++', error, opts);
|
||||||
if (response.status === 401) {
|
if (response?.status === 401) {
|
||||||
clearAtomStorage(userAtom);
|
clearAtomStorage(userAtom);
|
||||||
|
|
||||||
history.push('/login', { replace: true });
|
history.push('/login', { replace: true });
|
||||||
|
|||||||
@@ -1,5 +1,26 @@
|
|||||||
import qs from 'query-string';
|
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
|
* @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 });
|
let chunk = decoder.decode(value, { stream: true });
|
||||||
console.log('chunk==========', chunk);
|
console.log('chunk==========', chunk);
|
||||||
callback(chunk);
|
extractJSON(chunk).forEach((data) => {
|
||||||
|
callback?.(data);
|
||||||
|
});
|
||||||
|
// callback(chunk);
|
||||||
await readStreamData(reader, decoder, callback);
|
await readStreamData(reader, decoder, callback);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user