thebird 1.2.14 → 1.2.15
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 +23 -12
- package/package.json +1 -1
package/docs/app.js
CHANGED
|
@@ -84,7 +84,14 @@ class BirdChat extends HTMLElement {
|
|
|
84
84
|
if (this.state.apiKey) this.loadModels(this.state.apiKey);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
setState(patch) {
|
|
87
|
+
setState(patch) {
|
|
88
|
+
Object.assign(this.state, patch);
|
|
89
|
+
this.render();
|
|
90
|
+
if (this.streamWrap && !this.querySelector('#msg-list')?.contains(this.streamWrap)) {
|
|
91
|
+
const list = this.querySelector('#msg-list');
|
|
92
|
+
if (list) list.appendChild(this.streamWrap);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
88
95
|
|
|
89
96
|
async loadModels(apiKey) {
|
|
90
97
|
this.setState({ modelsLoading: true, status: '' });
|
|
@@ -156,25 +163,29 @@ class BirdChat extends HTMLElement {
|
|
|
156
163
|
this.setState({ messages, streaming: true, status: '', streamingText: '' });
|
|
157
164
|
try {
|
|
158
165
|
let full = '';
|
|
159
|
-
|
|
160
|
-
streamEl.className = 'msg-bubble card bg-base-200 text-base-content px-4 py-3 text-sm leading-relaxed';
|
|
166
|
+
this.streamEl = document.createElement('div');
|
|
167
|
+
this.streamEl.className = 'msg-bubble card bg-base-200 text-base-content px-4 py-3 text-sm leading-relaxed';
|
|
161
168
|
const cursor = document.createElement('span');
|
|
162
169
|
cursor.className = 'animate-pulse ml-1';
|
|
163
170
|
cursor.textContent = '▋';
|
|
171
|
+
this.streamWrap = document.createElement('div');
|
|
172
|
+
this.streamWrap.className = 'flex justify-start';
|
|
173
|
+
this.streamWrap.appendChild(this.streamEl);
|
|
174
|
+
this.streamWrap.appendChild(cursor);
|
|
164
175
|
const list = this.querySelector('#msg-list');
|
|
165
|
-
|
|
166
|
-
wrap.className = 'flex justify-start';
|
|
167
|
-
wrap.appendChild(streamEl);
|
|
168
|
-
wrap.appendChild(cursor);
|
|
169
|
-
if (list) list.appendChild(wrap);
|
|
176
|
+
if (list) list.appendChild(this.streamWrap);
|
|
170
177
|
for await (const chunk of streamGenerate(apiKey, model, convertMessages(messages))) {
|
|
171
178
|
full += chunk;
|
|
172
|
-
streamEl.textContent = full;
|
|
173
|
-
|
|
179
|
+
this.streamEl.textContent = full;
|
|
180
|
+
const l = this.querySelector('#msg-list');
|
|
181
|
+
if (l) l.scrollTop = l.scrollHeight;
|
|
174
182
|
}
|
|
175
|
-
|
|
183
|
+
this.streamWrap.remove();
|
|
184
|
+
this.streamEl = null;
|
|
185
|
+
this.streamWrap = null;
|
|
176
186
|
this.setState({ messages: [...messages, { role: 'assistant', content: full || '(empty)' }], streaming: false, streamingText: '' });
|
|
177
|
-
|
|
187
|
+
const l2 = this.querySelector('#msg-list');
|
|
188
|
+
if (l2) l2.scrollTop = l2.scrollHeight;
|
|
178
189
|
} catch (err) {
|
|
179
190
|
this.setState({ streaming: false, streamingText: '', status: 'Error: ' + (err?.message || String(err)) });
|
|
180
191
|
}
|
package/package.json
CHANGED