Spaces:
Runtime error
Runtime error
+ icon; minor fixes
Browse files- graph.py +4 -2
- static/app.js +75 -26
graph.py
CHANGED
|
@@ -421,8 +421,10 @@ def chat_node(state: ChatState, config: RunnableConfig):
|
|
| 421 |
# model / provider resolves it without crashing the session.
|
| 422 |
is_rate = "429" in err_str or "TooManyRequests" in err_str or "rate" in err_str.lower()
|
| 423 |
is_auth_err = "401" in err_str or "User not found" in err_str or "Unauthorized" in err_str
|
| 424 |
-
|
| 425 |
-
|
|
|
|
|
|
|
| 426 |
print(f"[ROUTER] {reason} on {model_id}, rotating...")
|
| 427 |
skip_models.add(model_id)
|
| 428 |
continue
|
|
|
|
| 421 |
# model / provider resolves it without crashing the session.
|
| 422 |
is_rate = "429" in err_str or "TooManyRequests" in err_str or "rate" in err_str.lower()
|
| 423 |
is_auth_err = "401" in err_str or "User not found" in err_str or "Unauthorized" in err_str
|
| 424 |
+
is_ignored = "404" in err_str and "ignored" in err_str.lower()
|
| 425 |
+
|
| 426 |
+
if is_rate or is_auth_err or is_ignored:
|
| 427 |
+
reason = "429/rate-limit" if is_rate else ("401/provider-auth" if is_auth_err else "404/providers-ignored")
|
| 428 |
print(f"[ROUTER] {reason} on {model_id}, rotating...")
|
| 429 |
skip_models.add(model_id)
|
| 430 |
continue
|
static/app.js
CHANGED
|
@@ -749,14 +749,37 @@ function createWelcomeScreen() {
|
|
| 749 |
<div class="hero-input-wrap">
|
| 750 |
<div class="hero-image-preview" id="heroImagePreviewDynamic">
|
| 751 |
<div class="hero-image-preview-thumb" id="heroImagePreviewThumbDynamic"></div>
|
|
|
|
| 752 |
<button class="hero-image-preview-remove" id="heroImagePreviewRemoveDynamic">×</button>
|
| 753 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 754 |
<div class="hero-input-box" id="heroInputBoxDynamic">
|
| 755 |
-
<
|
| 756 |
-
<
|
| 757 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 758 |
<input type="file" id="heroImageInputDynamic" accept="image/*" style="display:none;">
|
| 759 |
-
<
|
|
|
|
| 760 |
<div class="style-selector-wrap" id="heroStyleSelectorWrapDynamic">
|
| 761 |
<button class="style-selector-btn" id="heroStyleSelectorBtnDynamic" title="Teaching style">
|
| 762 |
<span id="heroStyleSelectorLabelDynamic">${styleLabel}</span>
|
|
@@ -780,10 +803,17 @@ function createWelcomeScreen() {
|
|
| 780 |
|
| 781 |
const dynInput = div.querySelector('#heroInputDynamic');
|
| 782 |
const dynAdaptive = div.querySelector('#heroAdaptiveBtnDynamic');
|
| 783 |
-
const
|
| 784 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 785 |
const dynImgPreview = div.querySelector('#heroImagePreviewDynamic');
|
| 786 |
const dynImgThumb = div.querySelector('#heroImagePreviewThumbDynamic');
|
|
|
|
| 787 |
const dynImgRemove = div.querySelector('#heroImagePreviewRemoveDynamic');
|
| 788 |
const dynStyleBtn = div.querySelector('#heroStyleSelectorBtnDynamic');
|
| 789 |
const dynStyleDropdown = div.querySelector('#heroStyleDropdownDynamic');
|
|
@@ -802,16 +832,13 @@ function createWelcomeScreen() {
|
|
| 802 |
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); userInput.value = dynInput.value; sendMessage(); }
|
| 803 |
});
|
| 804 |
|
| 805 |
-
|
| 806 |
-
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
dynImgPreview.classList.remove('visible');
|
| 813 |
-
dynImgPreview.innerHTML = '';
|
| 814 |
-
}
|
| 815 |
});
|
| 816 |
|
| 817 |
// Style selector
|
|
@@ -1200,17 +1227,30 @@ async function handleDocFile(file) {
|
|
| 1200 |
if (file.size > 10 * 1024 * 1024) { showToast('File too large (Max 10MB)', 'error'); return; }
|
| 1201 |
|
| 1202 |
const filename = file.name;
|
| 1203 |
-
const
|
| 1204 |
-
const
|
| 1205 |
-
const
|
| 1206 |
-
const pName = isHero ? document.getElementById('heroImagePreviewName') : imagePreviewName;
|
| 1207 |
|
| 1208 |
if (pBar) {
|
| 1209 |
-
|
| 1210 |
-
|
| 1211 |
-
|
| 1212 |
-
|
| 1213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1214 |
}
|
| 1215 |
|
| 1216 |
const fd = new FormData();
|
|
@@ -1220,14 +1260,23 @@ async function handleDocFile(file) {
|
|
| 1220 |
const data = await res.json();
|
| 1221 |
if (res.ok) {
|
| 1222 |
pendingDocText = data.text;
|
| 1223 |
-
|
|
|
|
| 1224 |
showToast('Document attached!', 'success');
|
| 1225 |
} else {
|
| 1226 |
clearAttachments();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1227 |
showToast(data.error || 'Failed to extract text', 'error');
|
| 1228 |
}
|
| 1229 |
} catch(e) {
|
| 1230 |
clearAttachments();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1231 |
showToast('Upload failed', 'error');
|
| 1232 |
}
|
| 1233 |
}
|
|
|
|
| 749 |
<div class="hero-input-wrap">
|
| 750 |
<div class="hero-image-preview" id="heroImagePreviewDynamic">
|
| 751 |
<div class="hero-image-preview-thumb" id="heroImagePreviewThumbDynamic"></div>
|
| 752 |
+
<span class="image-preview-name" id="heroImagePreviewNameDynamic"></span>
|
| 753 |
<button class="hero-image-preview-remove" id="heroImagePreviewRemoveDynamic">×</button>
|
| 754 |
</div>
|
| 755 |
+
<!-- Tool progress bar (hero dynamic) -->
|
| 756 |
+
<div class="tool-progress-bar" id="heroToolProgressBarDynamic" style="display:none; padding: 0 16px;">
|
| 757 |
+
<div class="tool-progress-label" id="heroToolProgressLabelDynamic">Searching...</div>
|
| 758 |
+
<div class="tool-progress-track"><div class="tool-progress-fill" id="heroToolProgressFillDynamic"></div></div>
|
| 759 |
+
</div>
|
| 760 |
<div class="hero-input-box" id="heroInputBoxDynamic">
|
| 761 |
+
<div class="attach-wrap" id="heroAttachWrapDynamic">
|
| 762 |
+
<button class="attach-plus-btn" id="heroAttachPlusBtnDynamic" title="Attach or search">
|
| 763 |
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
|
| 764 |
+
</button>
|
| 765 |
+
<div class="attach-menu" id="heroAttachMenuDynamic">
|
| 766 |
+
<button class="attach-menu-item" id="heroWebSearchToggleDynamic" data-active="${isWebSearchEnabled}">
|
| 767 |
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
|
| 768 |
+
Web Search
|
| 769 |
+
</button>
|
| 770 |
+
<button class="attach-menu-item" id="heroYtSearchToggleDynamic" data-active="${isYtSearchEnabled}">
|
| 771 |
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="5 3 19 12 5 21 5 3"/></svg>
|
| 772 |
+
YouTube Video
|
| 773 |
+
</button>
|
| 774 |
+
<button class="attach-menu-item" id="heroAttachFileBtnDynamic">
|
| 775 |
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>
|
| 776 |
+
Add File / Image
|
| 777 |
+
</button>
|
| 778 |
+
</div>
|
| 779 |
+
</div>
|
| 780 |
<input type="file" id="heroImageInputDynamic" accept="image/*" style="display:none;">
|
| 781 |
+
<input type="file" id="heroDocInputDynamic" accept="image/*,.pdf,.doc,.docx,.txt,.md,.py,.js,.ts,.csv" style="display:none;">
|
| 782 |
+
<textarea id="heroInputDynamic" placeholder="${isWebSearchEnabled ? 'Search the web...' : (isYtSearchEnabled ? 'Paste a YouTube link...' : 'Ask STEM Copilot...')}" rows="1"></textarea>
|
| 783 |
<div class="style-selector-wrap" id="heroStyleSelectorWrapDynamic">
|
| 784 |
<button class="style-selector-btn" id="heroStyleSelectorBtnDynamic" title="Teaching style">
|
| 785 |
<span id="heroStyleSelectorLabelDynamic">${styleLabel}</span>
|
|
|
|
| 803 |
|
| 804 |
const dynInput = div.querySelector('#heroInputDynamic');
|
| 805 |
const dynAdaptive = div.querySelector('#heroAdaptiveBtnDynamic');
|
| 806 |
+
const dynPlusBtn = div.querySelector('#heroAttachPlusBtnDynamic');
|
| 807 |
+
const dynMenu = div.querySelector('#heroAttachMenuDynamic');
|
| 808 |
+
const dynWebToggle = div.querySelector('#heroWebSearchToggleDynamic');
|
| 809 |
+
const dynYtToggle = div.querySelector('#heroYtSearchToggleDynamic');
|
| 810 |
+
const dynFileBtn = div.querySelector('#heroAttachFileBtnDynamic');
|
| 811 |
+
const dynDocInput = div.querySelector('#heroDocInputDynamic');
|
| 812 |
+
const dynImgInput = div.querySelector('#heroImageInputDynamic');
|
| 813 |
+
|
| 814 |
const dynImgPreview = div.querySelector('#heroImagePreviewDynamic');
|
| 815 |
const dynImgThumb = div.querySelector('#heroImagePreviewThumbDynamic');
|
| 816 |
+
const dynImgName = div.querySelector('#heroImagePreviewNameDynamic');
|
| 817 |
const dynImgRemove = div.querySelector('#heroImagePreviewRemoveDynamic');
|
| 818 |
const dynStyleBtn = div.querySelector('#heroStyleSelectorBtnDynamic');
|
| 819 |
const dynStyleDropdown = div.querySelector('#heroStyleDropdownDynamic');
|
|
|
|
| 832 |
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); userInput.value = dynInput.value; sendMessage(); }
|
| 833 |
});
|
| 834 |
|
| 835 |
+
setupAttachMenu(dynPlusBtn, dynMenu, dynWebToggle, dynYtToggle, dynFileBtn, dynDocInput);
|
| 836 |
+
|
| 837 |
+
dynDocInput.addEventListener('change', () => _handleCombinedFile(dynDocInput.files[0], true));
|
| 838 |
+
|
| 839 |
+
dynImgRemove.addEventListener('click', () => {
|
| 840 |
+
clearAttachments();
|
| 841 |
+
dynImgPreview.classList.remove('visible');
|
|
|
|
|
|
|
|
|
|
| 842 |
});
|
| 843 |
|
| 844 |
// Style selector
|
|
|
|
| 1227 |
if (file.size > 10 * 1024 * 1024) { showToast('File too large (Max 10MB)', 'error'); return; }
|
| 1228 |
|
| 1229 |
const filename = file.name;
|
| 1230 |
+
const heroElem = document.getElementById('heroImagePreviewDynamic') || document.getElementById('heroImagePreview');
|
| 1231 |
+
const isHero = isHeroMode && heroElem;
|
| 1232 |
+
const pBar = isHero ? heroElem : imagePreviewBar;
|
|
|
|
| 1233 |
|
| 1234 |
if (pBar) {
|
| 1235 |
+
pBar.innerHTML = `
|
| 1236 |
+
<div class="${isHero ? 'hero-image-preview-thumb' : 'image-preview-thumb'}" style="background-color: var(--brand); display:flex; align-items:center; justify-content:center;">
|
| 1237 |
+
<svg style="width:16px;height:16px;color:#fff;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline></svg>
|
| 1238 |
+
</div>
|
| 1239 |
+
<span class="image-preview-name" id="docPreviewName">Extracting text...</span>
|
| 1240 |
+
<button class="${isHero ? 'hero-image-preview-remove' : 'image-preview-remove'}">×</button>
|
| 1241 |
+
`;
|
| 1242 |
+
|
| 1243 |
+
const removeBtn = pBar.querySelector(isHero ? '.hero-image-preview-remove' : '.image-preview-remove');
|
| 1244 |
+
if (removeBtn) {
|
| 1245 |
+
removeBtn.addEventListener('click', () => {
|
| 1246 |
+
clearAttachments();
|
| 1247 |
+
pBar.style.display = 'none';
|
| 1248 |
+
if (isHero) pBar.classList.remove('visible');
|
| 1249 |
+
});
|
| 1250 |
+
}
|
| 1251 |
+
|
| 1252 |
+
if (isHero) pBar.classList.add('visible');
|
| 1253 |
+
else pBar.style.display = 'flex';
|
| 1254 |
}
|
| 1255 |
|
| 1256 |
const fd = new FormData();
|
|
|
|
| 1260 |
const data = await res.json();
|
| 1261 |
if (res.ok) {
|
| 1262 |
pendingDocText = data.text;
|
| 1263 |
+
const pName = pBar ? pBar.querySelector('#docPreviewName') : null;
|
| 1264 |
+
if (pName) pName.textContent = data.filename || filename;
|
| 1265 |
showToast('Document attached!', 'success');
|
| 1266 |
} else {
|
| 1267 |
clearAttachments();
|
| 1268 |
+
if (pBar) {
|
| 1269 |
+
pBar.style.display = 'none';
|
| 1270 |
+
if (isHero) pBar.classList.remove('visible');
|
| 1271 |
+
}
|
| 1272 |
showToast(data.error || 'Failed to extract text', 'error');
|
| 1273 |
}
|
| 1274 |
} catch(e) {
|
| 1275 |
clearAttachments();
|
| 1276 |
+
if (pBar) {
|
| 1277 |
+
pBar.style.display = 'none';
|
| 1278 |
+
if (isHero) pBar.classList.remove('visible');
|
| 1279 |
+
}
|
| 1280 |
showToast('Upload failed', 'error');
|
| 1281 |
}
|
| 1282 |
}
|