thebird 1.2.12 → 1.2.14
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 +16 -8
- package/package.json +1 -1
package/docs/app.js
CHANGED
|
@@ -127,11 +127,7 @@ class BirdChat extends HTMLElement {
|
|
|
127
127
|
<div key=${i} class=${'flex ' + (m.role === 'user' ? 'justify-end' : 'justify-start')}>
|
|
128
128
|
<div class=${'msg-bubble card px-4 py-3 text-sm leading-relaxed ' + (m.role === 'user' ? 'bg-primary text-primary-content' : 'bg-base-200 text-base-content')}>${m.content}</div>
|
|
129
129
|
</div>`)}
|
|
130
|
-
${streamingText && html
|
|
131
|
-
<div class="flex justify-start">
|
|
132
|
-
<div class="msg-bubble card bg-base-200 text-base-content px-4 py-3 text-sm leading-relaxed">${streamingText}<span class="animate-pulse ml-1">▋</span></div>
|
|
133
|
-
</div>`}
|
|
134
|
-
${!streamingText && streaming && html`<div class="flex justify-start"><div class="card bg-base-200 px-4 py-3"><span class="loading loading-dots loading-sm"></span></div></div>`}
|
|
130
|
+
${streaming && !streamingText && html`<div class="flex justify-start"><div class="card bg-base-200 px-4 py-3"><span class="loading loading-dots loading-sm"></span></div></div>`}
|
|
135
131
|
</div>
|
|
136
132
|
|
|
137
133
|
${status && html`<div class="text-xs text-error px-4 pb-1">${status}</div>`}
|
|
@@ -160,13 +156,25 @@ class BirdChat extends HTMLElement {
|
|
|
160
156
|
this.setState({ messages, streaming: true, status: '', streamingText: '' });
|
|
161
157
|
try {
|
|
162
158
|
let full = '';
|
|
159
|
+
const streamEl = document.createElement('div');
|
|
160
|
+
streamEl.className = 'msg-bubble card bg-base-200 text-base-content px-4 py-3 text-sm leading-relaxed';
|
|
161
|
+
const cursor = document.createElement('span');
|
|
162
|
+
cursor.className = 'animate-pulse ml-1';
|
|
163
|
+
cursor.textContent = '▋';
|
|
164
|
+
const list = this.querySelector('#msg-list');
|
|
165
|
+
const wrap = document.createElement('div');
|
|
166
|
+
wrap.className = 'flex justify-start';
|
|
167
|
+
wrap.appendChild(streamEl);
|
|
168
|
+
wrap.appendChild(cursor);
|
|
169
|
+
if (list) list.appendChild(wrap);
|
|
163
170
|
for await (const chunk of streamGenerate(apiKey, model, convertMessages(messages))) {
|
|
164
171
|
full += chunk;
|
|
165
|
-
|
|
172
|
+
streamEl.textContent = full;
|
|
173
|
+
if (list) list.scrollTop = list.scrollHeight;
|
|
166
174
|
}
|
|
167
|
-
|
|
168
|
-
if (list) list.scrollTop = list.scrollHeight;
|
|
175
|
+
wrap.remove();
|
|
169
176
|
this.setState({ messages: [...messages, { role: 'assistant', content: full || '(empty)' }], streaming: false, streamingText: '' });
|
|
177
|
+
if (list) list.scrollTop = list.scrollHeight;
|
|
170
178
|
} catch (err) {
|
|
171
179
|
this.setState({ streaming: false, streamingText: '', status: 'Error: ' + (err?.message || String(err)) });
|
|
172
180
|
}
|
package/package.json
CHANGED