fix: chat stream data too long
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import Inner from './inner';
|
import Inner from './inner';
|
||||||
|
|
||||||
interface LabelSelectorProps {
|
interface LabelSelectorProps {
|
||||||
@@ -45,12 +45,10 @@ const LabelSelector: React.FC<LabelSelectorProps> = ({
|
|||||||
}
|
}
|
||||||
}, [labels]);
|
}, [labels]);
|
||||||
|
|
||||||
const handleLabelListChange = useCallback(
|
const handleLabelListChange = (list: { key: string; value: string }[]) => {
|
||||||
(list: { key: string; value: string }[]) => {
|
setLabelList(list);
|
||||||
setLabelList(list);
|
};
|
||||||
},
|
|
||||||
[setLabelList]
|
|
||||||
);
|
|
||||||
const handleLabelsChange = (data: Record<string, any>) => {
|
const handleLabelsChange = (data: Record<string, any>) => {
|
||||||
console.log('handleLabelsChange', data);
|
console.log('handleLabelsChange', data);
|
||||||
setLabelsData(data);
|
setLabelsData(data);
|
||||||
@@ -74,7 +72,7 @@ const LabelSelector: React.FC<LabelSelectorProps> = ({
|
|||||||
const [key, value] = line.split('=').map((part) => part.trim());
|
const [key, value] = line.split('=').map((part) => part.trim());
|
||||||
return { key, value };
|
return { key, value };
|
||||||
});
|
});
|
||||||
console.log(lines, parsedData);
|
console.log('onPaste', lines, parsedData);
|
||||||
|
|
||||||
setLabelList((prevPairs) => {
|
setLabelList((prevPairs) => {
|
||||||
const newPairs = [...prevPairs];
|
const newPairs = [...prevPairs];
|
||||||
|
|||||||
@@ -123,4 +123,4 @@ const LabelItem: React.FC<LabelItemProps> = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default React.memo(LabelItem);
|
export default LabelItem;
|
||||||
|
|||||||
@@ -366,8 +366,6 @@ const AddModal: FC<AddModalProps> = (props) => {
|
|||||||
evaluateStateRef.current.state === EvaluateProccess.model &&
|
evaluateStateRef.current.state === EvaluateProccess.model &&
|
||||||
item.evaluated
|
item.evaluated
|
||||||
) {
|
) {
|
||||||
handleShowCompatibleAlert(item.evaluateResult);
|
|
||||||
|
|
||||||
const newFormValues = {
|
const newFormValues = {
|
||||||
...(manual
|
...(manual
|
||||||
? { ...defaultFormValues }
|
? { ...defaultFormValues }
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ import SearchInput from './search-input';
|
|||||||
import SearchResult from './search-result';
|
import SearchResult from './search-result';
|
||||||
|
|
||||||
const filterOptions = [
|
const filterOptions = [
|
||||||
|
{ label: 'FP8', value: 'fp8' },
|
||||||
{ label: 'AWQ', value: 'awq' },
|
{ label: 'AWQ', value: 'awq' },
|
||||||
{ label: 'GPTQ', value: 'gptq' },
|
{ label: 'GPTQ', value: 'gptq' }
|
||||||
{ label: 'GGUF', value: 'gguf' }
|
|
||||||
];
|
];
|
||||||
const PaginationMain = styled(Pagination)`
|
const PaginationMain = styled(Pagination)`
|
||||||
.ant-pagination-slash {
|
.ant-pagination-slash {
|
||||||
@@ -541,8 +541,10 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
|
|||||||
onChange={handleFilterChange}
|
onChange={handleFilterChange}
|
||||||
options={filterOptions}
|
options={filterOptions}
|
||||||
size="middle"
|
size="middle"
|
||||||
placeholder={intl.formatMessage({ id: 'common.input.type' })}
|
placeholder={intl.formatMessage({
|
||||||
style={{ width: 120 }}
|
id: 'models.form.quantization'
|
||||||
|
})}
|
||||||
|
style={{ width: 130 }}
|
||||||
></BaseSelect>
|
></BaseSelect>
|
||||||
</span>
|
</span>
|
||||||
<PaginationMain
|
<PaginationMain
|
||||||
|
|||||||
@@ -29,3 +29,13 @@ export async function deleteUser(id: number) {
|
|||||||
method: 'DELETE'
|
method: 'DELETE'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateUserStatus(params: {
|
||||||
|
id: number;
|
||||||
|
data: { is_active: boolean };
|
||||||
|
}) {
|
||||||
|
return request(`${USERS_API}/${params.id}/activation`, {
|
||||||
|
method: 'PATCH',
|
||||||
|
data: params.data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,6 +23,16 @@ const actionList: Global.ActionItem[] = [
|
|||||||
key: 'edit',
|
key: 'edit',
|
||||||
icon: icons.EditOutlined
|
icon: icons.EditOutlined
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Active Account',
|
||||||
|
key: 'active',
|
||||||
|
icon: icons.EditOutlined
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Deactivate Account',
|
||||||
|
key: 'inactive',
|
||||||
|
icon: icons.EditOutlined
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'common.button.delete',
|
label: 'common.button.delete',
|
||||||
key: 'delete',
|
key: 'delete',
|
||||||
@@ -40,8 +50,14 @@ const useUsersColumns = ({
|
|||||||
|
|
||||||
const setActions = useMemoizedFn((record: ListItem) => {
|
const setActions = useMemoizedFn((record: ListItem) => {
|
||||||
return actionList.filter((action) => {
|
return actionList.filter((action) => {
|
||||||
if (initialState?.currentUser?.id === record.id) {
|
if (action.key === 'delete') {
|
||||||
return action.key !== 'delete';
|
return initialState?.currentUser?.id !== record.id;
|
||||||
|
}
|
||||||
|
if (action.key === 'active') {
|
||||||
|
return !record.is_active && initialState?.currentUser?.id !== record.id;
|
||||||
|
}
|
||||||
|
if (action.key === 'inactive') {
|
||||||
|
return record.is_active && initialState?.currentUser?.id !== record.id;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,30 +3,33 @@ import qs from 'query-string';
|
|||||||
|
|
||||||
const extractStreamRegx = /(data|error):\s*({.*?})(?=\n|$)/g;
|
const extractStreamRegx = /(data|error):\s*({.*?})(?=\n|$)/g;
|
||||||
|
|
||||||
const extractJSON = (dataStr: string) => {
|
const extractJSON = (
|
||||||
let match;
|
dataStr: string
|
||||||
|
): { results: any[]; remaining: string } => {
|
||||||
const results: any[] = [];
|
const results: any[] = [];
|
||||||
|
if (!dataStr) return { results, remaining: '' };
|
||||||
|
|
||||||
if (!dataStr) {
|
const parts = dataStr.split(/\n\n/);
|
||||||
return results;
|
let remaining = '';
|
||||||
}
|
|
||||||
while ((match = extractStreamRegx.exec(dataStr)) !== null) {
|
for (let i = 0; i < parts.length; i++) {
|
||||||
try {
|
const part = parts[i].trim();
|
||||||
const type = match[1]; // "data" or "error"
|
if (!part) continue;
|
||||||
console.log('type========', type);
|
if (!part.startsWith('data:') && !part.startsWith('error:')) {
|
||||||
const jsonData = JSON.parse(match[2]);
|
remaining += part;
|
||||||
if (type === 'error') {
|
|
||||||
results.push({ error: jsonData });
|
|
||||||
} else {
|
|
||||||
results.push(jsonData);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('JSON parse error:', err, 'for match:', match[2]);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const jsonStr = part.slice(5).trim();
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(jsonStr);
|
||||||
|
results.push(parsed);
|
||||||
|
} catch {
|
||||||
|
remaining += part;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return { results, remaining };
|
||||||
};
|
};
|
||||||
|
|
||||||
const errorHandler = async (res: any) => {
|
const errorHandler = async (res: any) => {
|
||||||
@@ -181,10 +184,11 @@ export const readStreamData = async (
|
|||||||
bufferManager.add({ error: jsonData });
|
bufferManager.add({ error: jsonData });
|
||||||
textBuffer = ''; // Clear buffer after processing error
|
textBuffer = ''; // Clear buffer after processing error
|
||||||
} else {
|
} else {
|
||||||
extractJSON(textBuffer).forEach((data) => {
|
const { results, remaining } = extractJSON(textBuffer);
|
||||||
|
results.forEach((data) => {
|
||||||
bufferManager.add(data);
|
bufferManager.add(data);
|
||||||
});
|
});
|
||||||
textBuffer = ''; // Clear buffer after processing
|
textBuffer = remaining; // Clear buffer after processing
|
||||||
}
|
}
|
||||||
|
|
||||||
throttledCallback();
|
throttledCallback();
|
||||||
@@ -195,10 +199,11 @@ export const readStreamData = async (
|
|||||||
if (done) {
|
if (done) {
|
||||||
textBuffer += decoder.decode();
|
textBuffer += decoder.decode();
|
||||||
if (textBuffer) {
|
if (textBuffer) {
|
||||||
extractJSON(textBuffer).forEach((data) => bufferManager.add(data));
|
const { results, remaining } = extractJSON(textBuffer);
|
||||||
|
results.forEach((data) => bufferManager.add(data));
|
||||||
}
|
}
|
||||||
isReading = false;
|
|
||||||
bufferManager.flush();
|
bufferManager.flush();
|
||||||
|
isReading = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user