From 7ca5ae9033d19a292d589d536cce4e515a2df753 Mon Sep 17 00:00:00 2001 From: EP Date: Mon, 25 Aug 2025 13:16:13 -0700 Subject: [PATCH] feat(ui): optional custom API Base toggle for local OpenAI-compatible servers --- docs/app.js | 18 ++++++++++++++++-- docs/index.html | 10 ++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/app.js b/docs/app.js index 3a52bd6..a3a7e59 100644 --- a/docs/app.js +++ b/docs/app.js @@ -1,10 +1,12 @@ async function openAIChat(apiKey, model, messages, temperature = 0.7, top_p = 1.0, extra = {}) { - const url = 'https://api.openai.com/v1/chat/completions'; + const useCustom = document.getElementById('useCustomApiBase'); + const base = (useCustom && useCustom.checked ? (document.getElementById('apiBase')?.value?.trim()) : '') || 'https://api.openai.com/v1'; + const url = base.replace(/\/$/, '') + '/chat/completions'; const res = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', - 'Authorization': `Bearer ${apiKey}` + ...(apiKey ? { 'Authorization': `Bearer ${apiKey}` } : {}) }, body: JSON.stringify({ model, messages, temperature, top_p, ...extra }) }); @@ -196,6 +198,18 @@ document.addEventListener('DOMContentLoaded', () => { c.data.datasets[0].data.push({ x: temp, y: mean }); c.update('none'); } + // Custom API base toggle + const useCustom = getEl('useCustomApiBase'); + const apiBaseField = getEl('apiBaseField'); + if (useCustom && apiBaseField){ + const savedUse = localStorage.getItem('autotemp_use_custom_api') === '1'; + useCustom.checked = savedUse; + apiBaseField.style.display = savedUse ? '' : 'none'; + useCustom.addEventListener('change', ()=>{ + apiBaseField.style.display = useCustom.checked ? '' : 'none'; + localStorage.setItem('autotemp_use_custom_api', useCustom.checked ? '1' : '0'); + }); + } // Run state and controls let running = false; let cancelled = false; diff --git a/docs/index.html b/docs/index.html index a2be0d9..69dc0e6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -24,6 +24,16 @@ Remember in this browser +
+
+ +
+ +
+