fix: image stream data error
This commit is contained in:
@@ -71,9 +71,6 @@ const AutoImage: React.FC<
|
|||||||
}, [props.onLoad]);
|
}, [props.onLoad]);
|
||||||
|
|
||||||
const handleOnError = () => {
|
const handleOnError = () => {
|
||||||
console.log('error===img=========', {
|
|
||||||
src: props.src
|
|
||||||
});
|
|
||||||
setIsError(true);
|
setIsError(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { CloseCircleOutlined } from '@ant-design/icons';
|
import { CloseCircleOutlined } from '@ant-design/icons';
|
||||||
import { Progress, ProgressProps } from 'antd';
|
import { Progress, ProgressProps } from 'antd';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import { round } from 'lodash';
|
||||||
import ResizeObserver from 'rc-resize-observer';
|
import ResizeObserver from 'rc-resize-observer';
|
||||||
import React, { useCallback } from 'react';
|
import React, { useCallback } from 'react';
|
||||||
import AutoImage from './index';
|
import AutoImage from './index';
|
||||||
@@ -40,7 +41,7 @@ const SingleImage: React.FC<SingleImageProps> = (props) => {
|
|||||||
progress,
|
progress,
|
||||||
maxHeight,
|
maxHeight,
|
||||||
maxWidth,
|
maxWidth,
|
||||||
dataUrl,
|
dataUrl = '',
|
||||||
style,
|
style,
|
||||||
autoBgColor,
|
autoBgColor,
|
||||||
preview = true,
|
preview = true,
|
||||||
@@ -134,12 +135,12 @@ const SingleImage: React.FC<SingleImageProps> = (props) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Progress
|
<Progress
|
||||||
percent={progress}
|
percent={round(progress, 0)}
|
||||||
type="dashboard"
|
type="dashboard"
|
||||||
size={loadingSize}
|
size={loadingSize}
|
||||||
steps={{ count: 50, gap: 2 }}
|
steps={{ count: 50, gap: 2 }}
|
||||||
format={() => (
|
format={() => (
|
||||||
<span className="font-size-20">{progress}%</span>
|
<span className="font-size-20">{round(progress, 0)}%</span>
|
||||||
)}
|
)}
|
||||||
trailColor="var(--ant-color-fill-secondary)"
|
trailColor="var(--ant-color-fill-secondary)"
|
||||||
/>
|
/>
|
||||||
@@ -164,12 +165,14 @@ const SingleImage: React.FC<SingleImageProps> = (props) => {
|
|||||||
{progress && progress < 100 && (
|
{progress && progress < 100 && (
|
||||||
<span className="small-progress-wrap">
|
<span className="small-progress-wrap">
|
||||||
<Progress
|
<Progress
|
||||||
percent={progress}
|
percent={round(progress, 0)}
|
||||||
type="dashboard"
|
type="dashboard"
|
||||||
size="small"
|
size="small"
|
||||||
steps={{ count: 25, gap: 3 }}
|
steps={{ count: 25, gap: 3 }}
|
||||||
format={() => (
|
format={() => (
|
||||||
<span className="font-size-12">{progress}%</span>
|
<span className="font-size-12">
|
||||||
|
{round(progress, 0)}%
|
||||||
|
</span>
|
||||||
)}
|
)}
|
||||||
strokeColor="var(--color-white-secondary)"
|
strokeColor="var(--color-white-secondary)"
|
||||||
trailColor="var(--ant-color-fill-secondary)"
|
trailColor="var(--ant-color-fill-secondary)"
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||||
const overlayCanvasRef = useRef<HTMLCanvasElement>(null);
|
const overlayCanvasRef = useRef<HTMLCanvasElement>(null);
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const [lineWidth, setLineWidth] = useState<number>(30);
|
const [lineWidth, setLineWidth] = useState<number>(60);
|
||||||
const isDrawing = useRef<boolean>(false);
|
const isDrawing = useRef<boolean>(false);
|
||||||
const currentStroke = useRef<Point[]>([]);
|
const currentStroke = useRef<Point[]>([]);
|
||||||
const resizeObserver = useRef<ResizeObserver | null>(null);
|
const resizeObserver = useRef<ResizeObserver | null>(null);
|
||||||
|
|||||||
@@ -1,11 +1,18 @@
|
|||||||
import AutoTooltip from '@/components/auto-tooltip';
|
import AutoTooltip from '@/components/auto-tooltip';
|
||||||
import PageTools from '@/components/page-tools';
|
import PageTools from '@/components/page-tools';
|
||||||
|
import { modelCategoriesMap } from '@/pages/llmodels/config';
|
||||||
import { convertFileSize } from '@/utils';
|
import { convertFileSize } from '@/utils';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Col, Row, Table } from 'antd';
|
import { Col, Row, Table } from 'antd';
|
||||||
import { memo, useContext } from 'react';
|
import { memo, useContext } from 'react';
|
||||||
import { DashboardContext } from '../config/dashboard-context';
|
import { DashboardContext } from '../config/dashboard-context';
|
||||||
|
|
||||||
|
const NACategories = [
|
||||||
|
modelCategoriesMap.llm,
|
||||||
|
modelCategoriesMap.embedding,
|
||||||
|
modelCategoriesMap.reranker
|
||||||
|
];
|
||||||
|
|
||||||
const ActiveTable = () => {
|
const ActiveTable = () => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const data = useContext(DashboardContext).active_models || [];
|
const data = useContext(DashboardContext).active_models || [];
|
||||||
@@ -48,9 +55,13 @@ const ActiveTable = () => {
|
|||||||
key: 'token_count',
|
key: 'token_count',
|
||||||
ellipsis: true,
|
ellipsis: true,
|
||||||
render: (text: any, record: any) => {
|
render: (text: any, record: any) => {
|
||||||
|
let val = text;
|
||||||
|
if (!text) {
|
||||||
|
val = NACategories.includes(record.category?.[0]) ? 'N/A' : 0;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<AutoTooltip ghost>
|
<AutoTooltip ghost>
|
||||||
<span>{text || 'N/A'}</span>
|
<span>{val}</span>
|
||||||
</AutoTooltip>
|
</AutoTooltip>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ const METAKEYS = [
|
|||||||
'negative_prompt'
|
'negative_prompt'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const ODD_STRING = 'AAAABJRU5ErkJgg===';
|
||||||
|
|
||||||
const advancedFieldsDefaultValus = {
|
const advancedFieldsDefaultValus = {
|
||||||
seed: null,
|
seed: null,
|
||||||
sample_method: 'euler_a',
|
sample_method: 'euler_a',
|
||||||
@@ -135,6 +137,10 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const removeBase64Suffix = (str: string, suffix: string) => {
|
||||||
|
return str.endsWith(suffix) ? str.slice(0, -suffix.length) : str;
|
||||||
|
};
|
||||||
|
|
||||||
const getNewImageSizeOptions = useCallback((metaData: any) => {
|
const getNewImageSizeOptions = useCallback((metaData: any) => {
|
||||||
const { max_height, max_width } = metaData || {};
|
const { max_height, max_width } = metaData || {};
|
||||||
if (!max_height || !max_width) {
|
if (!max_height || !max_width) {
|
||||||
@@ -350,12 +356,12 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
chunk?.data?.forEach((item: any) => {
|
chunk?.data?.forEach((item: any) => {
|
||||||
const imgItem = newImageList[item.index];
|
const imgItem = newImageList[item.index];
|
||||||
if (item.b64_json && stream_options.chunk_results) {
|
if (item.b64_json && stream_options.chunk_results) {
|
||||||
imgItem.dataUrl += item.b64_json;
|
imgItem.dataUrl += removeBase64Suffix(item.b64_json, ODD_STRING);
|
||||||
} else if (item.b64_json) {
|
} else if (item.b64_json) {
|
||||||
console.log('item.b64_json:', item.b64_json, item.index);
|
imgItem.dataUrl = `data:image/png;base64,${removeBase64Suffix(item.b64_json, ODD_STRING)}`;
|
||||||
imgItem.dataUrl = `data:image/png;base64,${item.b64_json}`;
|
|
||||||
}
|
}
|
||||||
const progress = _.round(item.progress, 0);
|
const progress = item.progress;
|
||||||
|
|
||||||
newImageList[item.index] = {
|
newImageList[item.index] = {
|
||||||
dataUrl: imgItem.dataUrl,
|
dataUrl: imgItem.dataUrl,
|
||||||
height: imgSize[1],
|
height: imgSize[1],
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ const METAKEYS = [
|
|||||||
'strength'
|
'strength'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const ODD_STRING = 'AAAABJRU5ErkJgg===';
|
||||||
|
|
||||||
const advancedFieldsDefaultValus = {
|
const advancedFieldsDefaultValus = {
|
||||||
seed: null,
|
seed: null,
|
||||||
sample_method: 'euler_a',
|
sample_method: 'euler_a',
|
||||||
@@ -150,6 +152,10 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const removeBase64Suffix = (str: string, suffix: string) => {
|
||||||
|
return str.endsWith(suffix) ? str.slice(0, -suffix.length) : str;
|
||||||
|
};
|
||||||
|
|
||||||
const updateCacheFormData = (values: Record<string, any>) => {
|
const updateCacheFormData = (values: Record<string, any>) => {
|
||||||
cacheFormData.current = {
|
cacheFormData.current = {
|
||||||
...cacheFormData.current,
|
...cacheFormData.current,
|
||||||
@@ -383,11 +389,11 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
chunk?.data?.forEach((item: any) => {
|
chunk?.data?.forEach((item: any) => {
|
||||||
const imgItem = newImageList[item.index];
|
const imgItem = newImageList[item.index];
|
||||||
if (item.b64_json && params.stream_options_chunk_result) {
|
if (item.b64_json && params.stream_options_chunk_result) {
|
||||||
imgItem.dataUrl += item.b64_json;
|
imgItem.dataUrl += removeBase64Suffix(item.b64_json, ODD_STRING);
|
||||||
} else if (item.b64_json) {
|
} else if (item.b64_json) {
|
||||||
imgItem.dataUrl = `data:image/png;base64,${item.b64_json}`;
|
imgItem.dataUrl = `data:image/png;base64,${removeBase64Suffix(item.b64_json, ODD_STRING)}`;
|
||||||
}
|
}
|
||||||
const progress = _.round(item.progress, 0);
|
const progress = item.progress;
|
||||||
|
|
||||||
newImageList[item.index] = {
|
newImageList[item.index] = {
|
||||||
dataUrl: imgItem.dataUrl,
|
dataUrl: imgItem.dataUrl,
|
||||||
@@ -832,7 +838,8 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
style={{
|
style={{
|
||||||
height: 125,
|
height: 125,
|
||||||
maxWidth: 125,
|
maxWidth: 125,
|
||||||
maxHeight: 125
|
maxHeight: 125,
|
||||||
|
overflow: 'hidden'
|
||||||
}}
|
}}
|
||||||
key={item.uid}
|
key={item.uid}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -210,7 +210,6 @@ const processBuffer = async (buffer: string, callback: (data: any) => void) => {
|
|||||||
const jsonStr = trimmedLine.slice(6).trim();
|
const jsonStr = trimmedLine.slice(6).trim();
|
||||||
try {
|
try {
|
||||||
if (jsonStr !== '[DONE]') {
|
if (jsonStr !== '[DONE]') {
|
||||||
console.log('jsonStr>>>>>>>>>>>>>done:', jsonStr);
|
|
||||||
const jsonData = JSON.parse(jsonStr);
|
const jsonData = JSON.parse(jsonStr);
|
||||||
callback(jsonData);
|
callback(jsonData);
|
||||||
}
|
}
|
||||||
@@ -219,7 +218,6 @@ const processBuffer = async (buffer: string, callback: (data: any) => void) => {
|
|||||||
}
|
}
|
||||||
} else if (trimmedLine.startsWith('error:')) {
|
} else if (trimmedLine.startsWith('error:')) {
|
||||||
const errorStr = trimmedLine.slice(7).trim();
|
const errorStr = trimmedLine.slice(7).trim();
|
||||||
console.log('jsonStr>>>>>>>>>>>>>error:', errorStr);
|
|
||||||
try {
|
try {
|
||||||
const jsonData = JSON.parse(errorStr);
|
const jsonData = JSON.parse(errorStr);
|
||||||
callback({ error: jsonData });
|
callback({ error: jsonData });
|
||||||
@@ -308,6 +306,8 @@ export const readLargeStreamData = async (
|
|||||||
const lines = buffer.split('\n');
|
const lines = buffer.split('\n');
|
||||||
buffer = lines.pop() || ''; // Keep last line (may be incomplete)
|
buffer = lines.pop() || ''; // Keep last line (may be incomplete)
|
||||||
|
|
||||||
|
console.log('buffer>>>>>>>>>>>>>:', buffer);
|
||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
bufferManager.add(line);
|
bufferManager.add(line);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user