File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
Clients/src/presentation/pages/AIGateway Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments