This commit is contained in:
HuangHai
2026-01-20 09:38:29 +08:00
parent 79954171c6
commit bf2680e346
4 changed files with 70 additions and 32 deletions

View File

@@ -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;
}