thebird 1.2.12 → 1.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/app.js +9 -3
- package/package.json +1 -1
package/docs/app.js
CHANGED
|
@@ -160,13 +160,19 @@ class BirdChat extends HTMLElement {
|
|
|
160
160
|
this.setState({ messages, streaming: true, status: '', streamingText: '' });
|
|
161
161
|
try {
|
|
162
162
|
let full = '';
|
|
163
|
-
|
|
163
|
+
let rafPending = false;
|
|
164
|
+
const gen = streamGenerate(apiKey, model, convertMessages(messages));
|
|
165
|
+
for await (const chunk of gen) {
|
|
164
166
|
full += chunk;
|
|
165
|
-
|
|
167
|
+
if (!rafPending) {
|
|
168
|
+
rafPending = true;
|
|
169
|
+
const snap = full;
|
|
170
|
+
requestAnimationFrame(() => { this.setState({ streamingText: snap }); rafPending = false; });
|
|
171
|
+
}
|
|
166
172
|
}
|
|
173
|
+
this.setState({ messages: [...messages, { role: 'assistant', content: full || '(empty)' }], streaming: false, streamingText: '' });
|
|
167
174
|
const list = document.getElementById('msg-list');
|
|
168
175
|
if (list) list.scrollTop = list.scrollHeight;
|
|
169
|
-
this.setState({ messages: [...messages, { role: 'assistant', content: full || '(empty)' }], streaming: false, streamingText: '' });
|
|
170
176
|
} catch (err) {
|
|
171
177
|
this.setState({ streaming: false, streamingText: '', status: 'Error: ' + (err?.message || String(err)) });
|
|
172
178
|
}
|
package/package.json
CHANGED