Merge pull request #21 from mohitagw15856/add-skill-playground-web-ui
fix(web): propagate mid-stream API errors and raise max_tokens
This commit is contained in:
+12
-9
@@ -170,7 +170,7 @@ async function run() {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: el('model').value,
|
model: el('model').value,
|
||||||
max_tokens: 4096,
|
max_tokens: 8192,
|
||||||
stream: true,
|
stream: true,
|
||||||
system,
|
system,
|
||||||
messages: [{ role: 'user', content: userMessage }],
|
messages: [{ role: 'user', content: userMessage }],
|
||||||
@@ -193,15 +193,18 @@ async function run() {
|
|||||||
if (!line.startsWith('data:')) continue;
|
if (!line.startsWith('data:')) continue;
|
||||||
const payload = line.slice(5).trim();
|
const payload = line.slice(5).trim();
|
||||||
if (!payload || payload === '[DONE]') continue;
|
if (!payload || payload === '[DONE]') continue;
|
||||||
|
let evt;
|
||||||
try {
|
try {
|
||||||
const evt = JSON.parse(payload);
|
evt = JSON.parse(payload);
|
||||||
if (evt.type === 'content_block_delta' && evt.delta && evt.delta.text) {
|
} catch (_) {
|
||||||
acc += evt.delta.text;
|
continue; // skip an unparseable / partial SSE line
|
||||||
renderMarkdown(out, acc, true);
|
}
|
||||||
} else if (evt.type === 'error') {
|
if (evt.type === 'content_block_delta' && evt.delta && evt.delta.text) {
|
||||||
throw new Error(evt.error ? evt.error.message : 'stream error');
|
acc += evt.delta.text;
|
||||||
}
|
renderMarkdown(out, acc, true);
|
||||||
} catch (_) { /* ignore partial */ }
|
} else if (evt.type === 'error') {
|
||||||
|
throw new Error(evt.error ? evt.error.message : 'Stream error from the API.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
renderMarkdown(out, acc, false);
|
renderMarkdown(out, acc, false);
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user