fix: image request error message

This commit is contained in:
jialin
2024-11-29 10:58:16 +08:00
parent 0cc2a40f26
commit 890287ce72
14 changed files with 145 additions and 69 deletions
+1
View File
@@ -95,6 +95,7 @@ export default {
'playground.multiple.on': 'Enable',
'playground.multiple.off': 'Disable',
'playground.image.params.sampler': 'Sampler',
'playground.image.params.schedule': 'Schedule',
'playground.image.params.samplerSteps': 'Sampler Steps',
'playground.image.params.seed': 'Seed',
'playground.image.params.negativePrompt': 'Negative Prompt',
+1
View File
@@ -92,6 +92,7 @@ export default {
'playground.multiple.on': '开启',
'playground.multiple.off': '关闭',
'playground.image.params.sampler': '采样方法',
'playground.image.params.schedule': '调度',
'playground.image.params.samplerSteps': '迭代步数',
'playground.image.params.seed': '随机种子',
'playground.image.params.negativePrompt': '负向提示',
+2 -7
View File
@@ -236,14 +236,9 @@ const Models: React.FC<ModelsProps> = ({
const setActionList = useCallback((record: ListItem) => {
return _.filter(ActionList, (action: any) => {
if (action.key === 'chat') {
return record.ready_replicas > 0 && !record.embedding_only;
}
if (action.key === 'embedding') {
return (
(record.embedding_only || record.reranker) &&
record.ready_replicas > 0
);
return record.ready_replicas > 0;
}
return true;
});
}, []);
@@ -14,6 +14,7 @@ import {
import { useIntl, useSearchParams } from '@umijs/max';
import { Button, Checkbox, Segmented, Tabs, Tooltip } from 'antd';
import classNames from 'classnames';
import _ from 'lodash';
import { PCA } from 'ml-pca';
import 'overlayscrollbars/overlayscrollbars.css';
import { Resizable } from 're-resizable';
@@ -147,7 +148,8 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
};
});
setScatterData(list);
const embeddingJson = embeddings.map((item, index) => {
const embeddingJson = embeddings.map((o, index) => {
const item = _.cloneDeep(o);
item.embedding = item.embedding.slice(0, 5);
item.embedding.push(null);
return item;
@@ -286,7 +288,7 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
const dataLlist = text.split('\n').map((item: string) => {
return {
text: item?.trim(),
uid: setMessageId(),
uid: inputListRef.current?.setMessageId(),
name: ''
};
});
@@ -300,7 +302,7 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
.map((item, index) => {
return {
...item,
uid: setMessageId()
uid: inputListRef.current?.setMessageId()
};
});
setTextList(result);
@@ -449,20 +451,22 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
style={{ width: 60 }}
></Button>
) : (
<Button
style={{ width: 80 }}
size="middle"
type="primary"
onClick={handleStopConversation}
icon={
<IconFont
type="icon-stop1"
className="font-size-12"
></IconFont>
}
<Tooltip
title={intl.formatMessage({ id: 'common.button.stop' })}
>
{intl.formatMessage({ id: 'common.button.stop' })}
</Button>
<Button
style={{ width: 60 }}
size="middle"
type="primary"
onClick={handleStopConversation}
icon={
<IconFont
type="icon-stop1"
className="font-size-12"
></IconFont>
}
></Button>
</Tooltip>
)}
</div>
</div>
@@ -52,7 +52,8 @@ const initialValues = {
sampler: 'euler_a',
cfg_scale: 4.5,
sample_steps: 10,
negative_prompt: null
negative_prompt: null,
schedule: 'discrete'
};
const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
@@ -241,9 +242,7 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
const params = {
stream: true,
stream_options: {
// chunk_result: false
},
stream_options: {},
prompt: current?.content || currentPrompt || '',
..._.omitBy(finalParameters, (value: string) => !value)
};
@@ -253,6 +252,15 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
url: `${CREAT_IMAGE_API}?t=${Date.now()}`,
signal: requestToken.current.signal
});
if (result.error) {
setTokenResult({
error: true,
errorMessage:
result?.data?.error?.message || result?.data?.error || ''
});
setImageList([]);
return;
}
const { reader, decoder } = result;
const imgSize = _.split(finalParameters.size, 'x');
@@ -265,7 +273,6 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
});
return;
}
console.log('imgItem.dataUrl:', chunk.data);
chunk?.data?.forEach((item: any) => {
const imgItem = newImageList[item.index];
if (item.b64_json) {
@@ -285,7 +292,6 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
};
});
setImageList([...newImageList]);
console.log('newImageList:', newImageList);
});
} catch (error) {
console.log('error:', error);
@@ -320,7 +326,8 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
sampler: 'euler_a',
cfg_scale: 4.5,
sample_steps: 10,
negative_prompt: null
negative_prompt: null,
schedule: 'discrete'
});
setParams((pre: object) => {
return {
@@ -329,7 +336,8 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
sampler: 'euler_a',
cfg_scale: 4.5,
sample_steps: 10,
negative_prompt: null
negative_prompt: null,
schedule: 'discrete'
};
});
} else {
@@ -342,7 +350,8 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
'sampler',
'cfg_scale',
'sample_steps',
'negative_prompt'
'negative_prompt',
'schedule'
])
};
});
@@ -519,8 +528,8 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
})}
actions={['clear']}
defaultSize={{
minRows: 6,
maxRows: 6
minRows: 5,
maxRows: 5
}}
loading={loading}
disabled={!parameters.model}
@@ -294,6 +294,10 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
)}
<div className="ground-left-footer">
<MessageInput
defaultSize={{
minRows: 5,
maxRows: 5
}}
loading={loading}
disabled={!parameters.model}
isEmpty={!messageList.length}
@@ -365,6 +365,9 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
]
.filter((item) => item.text)
.map((item, index) => {
item.percent = undefined;
item.score = undefined;
item.rank = undefined;
return {
...item,
uid: setMessageId()
+35 -20
View File
@@ -1,3 +1,4 @@
import AlertInfo from '@/components/alert-info';
import AudioAnimation from '@/components/audio-animation';
import AudioPlayer from '@/components/audio-player';
import IconFont from '@/components/icon-font';
@@ -54,7 +55,6 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
const controllerRef = useRef<any>(null);
const scroller = useRef<any>(null);
const paramsRef = useRef<any>(null);
const messageListLengthCache = useRef<number>(0);
const [audioPermissionOn, setAudioPermissionOn] = useState(true);
const [audioData, setAudioData] = useState<any>(null);
const [audioChunks, setAudioChunks] = useState<any>({
@@ -113,7 +113,10 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
setTokenResult({
error: true,
errorMessage:
result?.data?.error?.message || result?.data?.message || ''
result?.data?.error?.message ||
result?.data?.message ||
result.error.detail ||
''
});
return;
}
@@ -172,6 +175,7 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
async (data: { file: any; fileList: any }) => {
const res = await readAudioFile(data.file);
setAudioData(res);
setTokenResult(null);
},
[]
);
@@ -187,6 +191,7 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
const handleOnRecord = useCallback((val: boolean) => {
setIsRecording(val);
setAudioData(null);
setTokenResult(null);
console.log('data===', val);
}, []);
@@ -326,24 +331,34 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
>
<div className="content" style={{ height: '100%' }}>
<>
<div
style={{
padding: '8px 14px',
lineHeight: '20px',
display: 'flex',
justifyContent: 'center'
}}
>
{messageList.length ? (
messageList[0]?.content
) : (
<span className="text-tertiary">
{intl.formatMessage({
id: 'playground.audio.generating.tips'
})}
</span>
)}
</div>
{!tokenResult && (
<div
style={{
padding: '8px 14px',
lineHeight: '20px',
display: 'flex',
justifyContent: 'center'
}}
>
{messageList.length ? (
messageList[0]?.content
) : (
<span className="text-tertiary">
{intl.formatMessage({
id: 'playground.audio.generating.tips'
})}
</span>
)}
</div>
)}
{tokenResult && (
<div style={{ height: 40 }}>
<AlertInfo
type="danger"
message={tokenResult?.errorMessage}
></AlertInfo>
</div>
)}
{loading && (
<Spin size="small">
<div style={{ height: '46px' }}></div>
+24 -4
View File
@@ -1,3 +1,4 @@
import AlertInfo from '@/components/alert-info';
import IconFont from '@/components/icon-font';
import SealSelect from '@/components/seal-form/seal-select';
import SpeechContent from '@/components/speech-content';
@@ -25,7 +26,6 @@ import '../style/ground-left.less';
import '../style/system-message-wrap.less';
import DynamicParams from './dynamic-params';
import MessageInput from './message-input';
import ReferenceParams from './reference-params';
import ViewCodeModal from './view-code-modal';
interface MessageProps {
@@ -96,7 +96,7 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
};
const submitMessage = async (current?: { role: string; content: string }) => {
await formRef.current?.form.validateFields();
// await formRef.current?.form.validateFields();
if (!parameters.model) return;
try {
setLoading(true);
@@ -120,6 +120,19 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
console.log('result:', res);
if (res.error) {
setTokenResult({
error: true,
errorMessage:
res?.data?.error?.message ||
res?.data?.error ||
res.error?.detail ||
''
});
setMessageList([]);
return;
}
setMessageList([
{
input: current?.content || currentPrompt,
@@ -132,7 +145,7 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
}
]);
} catch (error) {
// console.log('error:', error);
console.log('error:', error);
} finally {
setLoading(false);
}
@@ -280,7 +293,10 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
</div>
{tokenResult && (
<div style={{ height: 40 }}>
<ReferenceParams usage={tokenResult}></ReferenceParams>
<AlertInfo
type="danger"
message={tokenResult?.errorMessage}
></AlertInfo>
</div>
)}
<div className="ground-left-footer">
@@ -289,6 +305,10 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
checkLabel={intl.formatMessage({
id: 'playground.toolbar.autoplay'
})}
defaultSize={{
minRows: 5,
maxRows: 5
}}
onCheck={handleOnCheckChange}
loading={loading}
disabled={!parameters.model}
@@ -473,7 +473,10 @@ const MessageInput: React.FC<MessageInputProps> = forwardRef(
{actions.includes('paste') ? (
<TextArea
ref={inputRef}
autoSize={{ minRows: 3, maxRows: 8 }}
autoSize={{
minRows: defaultSize.minRows,
maxRows: defaultSize.maxRows
}}
onChange={handleInputChange}
value={message.content}
size="large"
@@ -293,7 +293,6 @@ const MultiCompare: React.FC<MultiCompareProps> = ({ modelList, loaded }) => {
</div>
<div>
<MessageInput
scope="compare"
loading={isLoading}
disabled={isLoading || !modelSelections.length || !modelList.length}
handleSubmit={handleSubmit}
@@ -303,8 +302,10 @@ const MultiCompare: React.FC<MultiCompareProps> = ({ modelList, loaded }) => {
updateLayout={updateLayout}
setModelSelections={handleUpdateModelSelections}
presetPrompt={handlePresetPrompt}
modelList={modelFullList}
showModelSelection={false}
defaultSize={{
minRows: 5,
maxRows: 5
}}
/>
</div>
</div>
@@ -34,7 +34,7 @@ const ThumbImg: React.FC<{
[onDelete]
);
if (_.isEmpty(dataList)) {
if (!dataList?.length) {
return null;
}
@@ -254,6 +254,26 @@ export const ImageAdvancedParamsConfig: ParamsSchema[] = [
}
]
},
{
type: 'Select',
name: 'schedule',
options: [
{ label: 'discrete', value: 'discrete' },
{ label: 'karras', value: 'karras' },
{ label: 'exponential', value: 'exponential' },
{ label: 'ays', value: 'ays' },
{ label: 'gits', value: 'gits' }
],
label: {
text: 'playground.image.params.schedule',
isLocalized: true
},
rules: [
{
required: false
}
]
},
{
type: 'InputNumber',
name: 'sample_steps',
+6 -6
View File
@@ -114,7 +114,7 @@ export const readLargeStreamData = async (
let buffer = ''; // cache incomplete line
while (true) {
const { done, value } = await reader.read();
const { done, value } = await reader?.read?.();
if (done) {
// Process remaining buffered data
if (buffer.trim()) {
@@ -131,14 +131,14 @@ export const readLargeStreamData = async (
buffer = lines.pop() || ''; // Keep last line (may be incomplete)
for (const line of lines) {
if (line === '[DONE]') {
continue;
}
if (line.startsWith('data: ')) {
const jsonStr = line.slice(6).trim();
try {
const jsonData = JSON.parse(jsonStr);
callback(jsonData);
if (jsonStr !== '[DONE]') {
const jsonData = JSON.parse(jsonStr);
callback(jsonData);
}
} catch (e) {
console.error('Failed to parse JSON:', jsonStr, e);
}