Sfoglia il codice sorgente

fix: do not error out if OpenAI response has no delta

Jun Siang Cheah 1 anno fa
parent
commit
615e9e348f
1 ha cambiato i file con 1 aggiunte e 1 eliminazioni
  1. 1 1
      src/lib/apis/streaming/index.ts

+ 1 - 1
src/lib/apis/streaming/index.ts

@@ -36,7 +36,7 @@ async function* openAIStreamToIterator(
 						const data = JSON.parse(line.replace(/^data: /, ''));
 						console.log(data);
 
-						yield { done: false, value: data.choices[0].delta.content ?? '' };
+						yield { done: false, value: data.choices?.[0]?.delta?.content ?? '' };
 					} catch (e) {
 						console.error('Error extracting delta from SSE event:', e);
 					}