victor HF staff commited on
Commit
191f5be
1 Parent(s): 842026e

Improved handling of streaming response from OpenAI API in Playground component.

Browse files
src/lib/components/Playground/Playground.svelte CHANGED
@@ -75,9 +75,11 @@
75
  max_tokens: 500,
76
  seed: 0,
77
  })) {
78
- if (streamingMessage && chunk.choices[0]?.delta?.content) {
79
- streamingMessage.content += chunk.choices[0].delta.content;
80
- messages = [...messages];
 
 
81
  }
82
  }
83
  } catch (error) {
 
75
  max_tokens: 500,
76
  seed: 0,
77
  })) {
78
+ if (chunk.choices && chunk.choices.length > 0) {
79
+ if (streamingMessage && chunk.choices[0]?.delta?.content) {
80
+ streamingMessage.content += chunk.choices[0].delta.content;
81
+ messages = [...messages];
82
+ }
83
  }
84
  }
85
  } catch (error) {