fix(ui): normalize custom API base to include /v1 and display effective endpoint

This commit is contained in:
EP
2025-08-25 14:03:34 -07:00
parent 96e7f662ba
commit 36dfe1a35f
3 changed files with 17 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
async function openAIChat(apiKey, model, messages, temperature = 0.7, top_p = 1.0, extra = {}) {
const useCustom = document.getElementById('useCustomApiBase');
const base = (useCustom && useCustom.checked ? (document.getElementById('apiBase')?.value?.trim()) : '') || 'https://api.openai.com/v1';
let base = (useCustom && useCustom.checked ? (document.getElementById('apiBase')?.value?.trim()) : '') || 'https://api.openai.com/v1';
if (!/\/v1\/?$/.test(base)) base = base.replace(/\/$/, '') + '/v1';
const url = base.replace(/\/$/, '') + '/chat/completions';
const res = await fetch(url, {
method: 'POST',
@@ -210,6 +211,19 @@ document.addEventListener('DOMContentLoaded', () => {
localStorage.setItem('autotemp_use_custom_api', useCustom.checked ? '1' : '0');
});
}
// Show effective base URL
function updateEffective(){
const eff = document.getElementById('apiBaseEffective');
if (!eff) return;
const useCustom = document.getElementById('useCustomApiBase');
let base = (useCustom && useCustom.checked ? (document.getElementById('apiBase')?.value?.trim()) : '') || 'https://api.openai.com/v1';
if (!/\/v1\/?$/.test(base)) base = base.replace(/\/$/, '') + '/v1';
eff.textContent = base.replace(/\/$/, '') + '/chat/completions';
}
const apiBaseInput = getEl('apiBase');
if (apiBaseInput){ apiBaseInput.addEventListener('input', updateEffective); }
if (useCustom){ useCustom.addEventListener('change', updateEffective); }
updateEffective();
// Run state and controls
let running = false;
let cancelled = false;

View File

@@ -31,6 +31,7 @@
<div class="field" id="apiBaseField" style="display:none">
<label for="apiBase">API Base URL</label>
<input id="apiBase" value="http://127.0.0.1:1234/v1" placeholder="http://127.0.0.1:1234/v1" />
<div class="hint">Effective: <code id="apiBaseEffective"></code></div>
</div>
<div class="field"></div>
</div>

View File

@@ -56,6 +56,7 @@ pre{ white-space:pre-wrap; background:#010a06; padding:14px; border-radius:10px;
.footer{ display:flex; align-items:center; gap:10px; opacity:.85 }
.blink{ width:8px; height:18px; background:var(--accent); animation: blink 1s infinite }
.glow{ text-shadow:0 0 8px rgba(0,255,156,.35) }
.hint{ font-size:12px; color:#a5ffd6; margin-top:6px }
@keyframes blink{ 50%{ opacity:.2 } }
@media(max-width:720px){ .grid-2,.grid-3{ grid-template-columns:1fr } }