Skip to content

Commit b392324

Browse files
committed
fix(ai-gateway): show error when prompt test stream returns empty content
1 parent e50bc88 commit b392324

File tree

1 file changed

+12
-0
lines changed
  • Clients/src/presentation/pages/AIGateway

1 file changed

+12
-0
lines changed

Clients/src/presentation/pages/AIGateway/shared.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ export async function streamPromptTest(
274274
let content = "";
275275
let tokens = 0;
276276
let cost = 0;
277+
let streamError = "";
277278

278279
try {
279280
while (true) {
@@ -285,6 +286,9 @@ export async function streamPromptTest(
285286
if (line.startsWith("data: ") && line !== "data: [DONE]") {
286287
try {
287288
const chunk = JSON.parse(line.slice(6));
289+
if (chunk.error) {
290+
streamError = chunk.error;
291+
}
288292
const delta = chunk.choices?.[0]?.delta?.content;
289293
if (delta) {
290294
content += delta;
@@ -300,5 +304,13 @@ export async function streamPromptTest(
300304
reader.releaseLock();
301305
}
302306

307+
if (!content && streamError) {
308+
content = `Error: ${streamError}`;
309+
opts.onDelta(content);
310+
} else if (!content) {
311+
content = "No response received from the model. Check that the endpoint has a valid API key configured.";
312+
opts.onDelta(content);
313+
}
314+
303315
return { content, tokens, cost, latency: Date.now() - startTime };
304316
}

0 commit comments

Comments
 (0)