'commit'
This commit is contained in:
@@ -32,18 +32,42 @@ const app = createApp({
|
||||
}
|
||||
|
||||
refining.value = true;
|
||||
const originalPrompt = prompt.value;
|
||||
let isFirstChunk = true;
|
||||
|
||||
try {
|
||||
const res = await axios.post('/haibao/refine', {
|
||||
prompt: prompt.value
|
||||
const response = await fetch('/haibao/refine', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ prompt: originalPrompt })
|
||||
});
|
||||
|
||||
if (res.data.refined_prompt) {
|
||||
prompt.value = res.data.refined_prompt;
|
||||
ElementPlus.ElMessage.success('创意扩写完成');
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
while (true) {
|
||||
const { value, done } = await reader.read();
|
||||
if (done) break;
|
||||
|
||||
const text = decoder.decode(value, { stream: true });
|
||||
|
||||
if (isFirstChunk) {
|
||||
prompt.value = '';
|
||||
isFirstChunk = false;
|
||||
}
|
||||
prompt.value += text;
|
||||
}
|
||||
|
||||
ElementPlus.ElMessage.success('创意扩写完成');
|
||||
} catch (e) {
|
||||
console.error('Refine failed', e);
|
||||
ElementPlus.ElMessage.error('扩写失败: ' + (e.response?.data?.detail || e.message));
|
||||
ElementPlus.ElMessage.error('扩写失败: ' + e.message);
|
||||
} finally {
|
||||
refining.value = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user