Upload app.js with huggingface_hub
Browse files
app.js
CHANGED
|
@@ -360,9 +360,9 @@ function updateProviderUI() {
|
|
| 360 |
|
| 361 |
// CHATSAM 免 key:隐藏账号池+模型选择区域
|
| 362 |
const noKeyNeeded = p.noKeyRequired;
|
| 363 |
-
const keyListField = keyListEl.closest('.field');
|
| 364 |
const dashField = dashBody.closest('.field');
|
| 365 |
-
const newKeyRow =
|
| 366 |
if (noKeyNeeded) {
|
| 367 |
if (keyListField) keyListField.style.display = 'none';
|
| 368 |
if (dashField) dashField.style.display = 'none';
|
|
@@ -371,6 +371,23 @@ function updateProviderUI() {
|
|
| 371 |
if (keyListField) keyListField.style.display = '';
|
| 372 |
if (dashField) dashField.style.display = '';
|
| 373 |
if (newKeyRow) newKeyRow.style.display = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
}
|
| 375 |
|
| 376 |
// 模型下拉框根据 provider 切换
|
|
@@ -476,8 +493,13 @@ function renderKeyList() {
|
|
| 476 |
// 每个 token 可用模型列表(探测后存在 k.probedModels)
|
| 477 |
// 未探测时显示全模型
|
| 478 |
const modelOptions = (p && p.models) ? p.models : (p && p.defaultModel ? [p.defaultModel] : []);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 479 |
keyListEl.innerHTML = (ks.length === 0)
|
| 480 |
-
?
|
| 481 |
: ks.map((k, i) => {
|
| 482 |
const status = k.status || 'ok';
|
| 483 |
const statusLabel = status === 'ok' ? '<span class="tag tag-ok">正常</span>'
|
|
@@ -488,7 +510,8 @@ function renderKeyList() {
|
|
| 488 |
const avail = Array.isArray(k.probedModels) && k.probedModels.length ? k.probedModels : modelOptions;
|
| 489 |
const useModel = (avail.includes(k.model)) ? k.model
|
| 490 |
: (k.model || (p && p.defaultModel) || 'gpt-4o');
|
| 491 |
-
|
|
|
|
| 492 |
? `<select class="key-model-sel" data-idx="${i}" title="选择该账号使用的模型">
|
| 493 |
${avail.map((m) => `<option value="${m}"${m === useModel ? ' selected' : ''}>${m}</option>`).join('')}
|
| 494 |
</select>`
|
|
@@ -496,6 +519,7 @@ function renderKeyList() {
|
|
| 496 |
const plan = k.sessionInfo && k.sessionInfo.planType ? `<span class="tag tag-plan">${k.sessionInfo.planType}</span>` : '';
|
| 497 |
const tabBadge = '';
|
| 498 |
const tabBtn = '';
|
|
|
|
| 499 |
const probeBtn = isPool ? `<button class="key-probe" data-idx="${i}" title="探测此 token 能跑哪些模型">🔍</button>` : '';
|
| 500 |
const sessionBtn = isPool ? `<button class="key-session" data-idx="${i}" title="查看账号配额和 plan">📊</button>` : '';
|
| 501 |
return `
|
|
@@ -504,7 +528,7 @@ function renderKeyList() {
|
|
| 504 |
<span class="key-val">${escapeHtml(maskKey(k.key))}</span>
|
| 505 |
${modelSelect}
|
| 506 |
${plan}
|
| 507 |
-
${
|
| 508 |
${probeBtn}
|
| 509 |
${sessionBtn}
|
| 510 |
${status === 'limited' ? `<button class="key-reset" data-idx="${i}" title="强制重置为正常">↻</button>` : ''}
|
|
@@ -803,15 +827,21 @@ addKeyBtn.addEventListener('click', async () => {
|
|
| 803 |
const p = PROVIDERS[settings.provider];
|
| 804 |
const modelSel = $('newKeyModel');
|
| 805 |
const model = (modelSel && modelSel.value) || (p && p.defaultModel) || 'gpt-4o';
|
| 806 |
-
const newKey = { name, key, provider: settings.provider, model, addedAt: Date.now() };
|
| 807 |
settings.keys.push(newKey);
|
| 808 |
saveSettings();
|
| 809 |
newKeyNameInput.value = '';
|
| 810 |
newKeyValInput.value = '';
|
| 811 |
renderKeyList();
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 815 |
});
|
| 816 |
|
| 817 |
// 批量刷新所有账号:先 session 后 probe
|
|
|
|
| 360 |
|
| 361 |
// CHATSAM 免 key:隐藏账号池+模型选择区域
|
| 362 |
const noKeyNeeded = p.noKeyRequired;
|
| 363 |
+
const keyListField = $('keyField') || keyListEl.closest('.field');
|
| 364 |
const dashField = dashBody.closest('.field');
|
| 365 |
+
const newKeyRow = $('keyAddRow');
|
| 366 |
if (noKeyNeeded) {
|
| 367 |
if (keyListField) keyListField.style.display = 'none';
|
| 368 |
if (dashField) dashField.style.display = 'none';
|
|
|
|
| 371 |
if (keyListField) keyListField.style.display = '';
|
| 372 |
if (dashField) dashField.style.display = '';
|
| 373 |
if (newKeyRow) newKeyRow.style.display = '';
|
| 374 |
+
// 根据 provider 切换 label / placeholder / hint
|
| 375 |
+
const labelEl = $('keyFieldLabel');
|
| 376 |
+
const valInput = newKeyValInput;
|
| 377 |
+
const hintTip = $('keyHintTip');
|
| 378 |
+
if (provider === 'zhipu') {
|
| 379 |
+
if (labelEl) labelEl.textContent = '智谱 API Key(支持多 Key 轮询)';
|
| 380 |
+
if (valInput) valInput.placeholder = '粘贴智谱 API Key(apikey.xxx 格式)';
|
| 381 |
+
if (hintTip) hintTip.textContent = '在 open.bigmodel.cn 创建 API Key。支持多 Key 轮询,自动跟踪模型余额。Key 存本机 localStorage,不上传服务器。';
|
| 382 |
+
} else if (provider === 'chatgpt') {
|
| 383 |
+
if (labelEl) labelEl.textContent = 'ChatGPT 账号池(多 access_token 自动轮询)';
|
| 384 |
+
if (valInput) valInput.placeholder = 'eyJ... 开头的 access_token';
|
| 385 |
+
if (hintTip) hintTip.textContent = '多账号 token 都加进来,自动轮询;单账号限流/失效不影响其他。Token 存本机 localStorage,不上传服务器。';
|
| 386 |
+
} else {
|
| 387 |
+
if (labelEl) labelEl.textContent = 'API Key';
|
| 388 |
+
if (valInput) valInput.placeholder = '粘贴 API Key / access_token';
|
| 389 |
+
if (hintTip) hintTip.textContent = '多账号轮询,单账号限流自动切换。';
|
| 390 |
+
}
|
| 391 |
}
|
| 392 |
|
| 393 |
// 模型下拉框根据 provider 切换
|
|
|
|
| 493 |
// 每个 token 可用模型列表(探测后存在 k.probedModels)
|
| 494 |
// 未探测时显示全模型
|
| 495 |
const modelOptions = (p && p.models) ? p.models : (p && p.defaultModel ? [p.defaultModel] : []);
|
| 496 |
+
const emptyTip = settings.provider === 'zhipu'
|
| 497 |
+
? '还没添加智谱 API Key,去 open.bigmodel.cn 创建后粘贴到下方'
|
| 498 |
+
: settings.provider === 'chatgpt'
|
| 499 |
+
? '还没添加账号,去 chatgpt.com 抓 access_token 加进来'
|
| 500 |
+
: '还没添加 API Key';
|
| 501 |
keyListEl.innerHTML = (ks.length === 0)
|
| 502 |
+
? `<div class="empty-tip">${emptyTip}</div>`
|
| 503 |
: ks.map((k, i) => {
|
| 504 |
const status = k.status || 'ok';
|
| 505 |
const statusLabel = status === 'ok' ? '<span class="tag tag-ok">正常</span>'
|
|
|
|
| 510 |
const avail = Array.isArray(k.probedModels) && k.probedModels.length ? k.probedModels : modelOptions;
|
| 511 |
const useModel = (avail.includes(k.model)) ? k.model
|
| 512 |
: (k.model || (p && p.defaultModel) || 'gpt-4o');
|
| 513 |
+
// 智谱/ChatGPT 都显示模型选择
|
| 514 |
+
const modelSelect = avail.length
|
| 515 |
? `<select class="key-model-sel" data-idx="${i}" title="选择该账号使用的模型">
|
| 516 |
${avail.map((m) => `<option value="${m}"${m === useModel ? ' selected' : ''}>${m}</option>`).join('')}
|
| 517 |
</select>`
|
|
|
|
| 519 |
const plan = k.sessionInfo && k.sessionInfo.planType ? `<span class="tag tag-plan">${k.sessionInfo.planType}</span>` : '';
|
| 520 |
const tabBadge = '';
|
| 521 |
const tabBtn = '';
|
| 522 |
+
// 探测/session 按钮仅 ChatGPT 显示
|
| 523 |
const probeBtn = isPool ? `<button class="key-probe" data-idx="${i}" title="探测此 token 能跑哪些模型">🔍</button>` : '';
|
| 524 |
const sessionBtn = isPool ? `<button class="key-session" data-idx="${i}" title="查看账号配额和 plan">📊</button>` : '';
|
| 525 |
return `
|
|
|
|
| 528 |
<span class="key-val">${escapeHtml(maskKey(k.key))}</span>
|
| 529 |
${modelSelect}
|
| 530 |
${plan}
|
| 531 |
+
${statusLabel}
|
| 532 |
${probeBtn}
|
| 533 |
${sessionBtn}
|
| 534 |
${status === 'limited' ? `<button class="key-reset" data-idx="${i}" title="强制重置为正常">↻</button>` : ''}
|
|
|
|
| 827 |
const p = PROVIDERS[settings.provider];
|
| 828 |
const modelSel = $('newKeyModel');
|
| 829 |
const model = (modelSel && modelSel.value) || (p && p.defaultModel) || 'gpt-4o';
|
| 830 |
+
const newKey = { name, key, provider: settings.provider, model, addedAt: Date.now(), status: 'ok' };
|
| 831 |
settings.keys.push(newKey);
|
| 832 |
saveSettings();
|
| 833 |
newKeyNameInput.value = '';
|
| 834 |
newKeyValInput.value = '';
|
| 835 |
renderKeyList();
|
| 836 |
+
// ChatGPT 走探测;智谱直接可用
|
| 837 |
+
if (settings.provider === 'chatgpt') {
|
| 838 |
+
toast(`已添加「${name}」,自动探测可用模型...`);
|
| 839 |
+
probeOneToken(newKey);
|
| 840 |
+
} else if (settings.provider === 'zhipu') {
|
| 841 |
+
toast(`✅ 已添加「${name}」,可直接发送`);
|
| 842 |
+
} else {
|
| 843 |
+
toast(`已添加「${name}」`);
|
| 844 |
+
}
|
| 845 |
});
|
| 846 |
|
| 847 |
// 批量刷新所有账号:先 session 后 probe
|