feat(ui): optional custom API Base toggle for local OpenAI-compatible servers

This commit is contained in:
EP
2025-08-25 13:16:13 -07:00
parent 1aec35d0a3
commit 7ca5ae9033
2 changed files with 26 additions and 2 deletions

View File

@@ -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;

View File

@@ -24,6 +24,16 @@
<input type="checkbox" id="rememberKey" /> Remember in this browser
</label>
</div>
<div class="grid-3">
<div class="field">
<label class="inline"><input type="checkbox" id="useCustomApiBase" /> Use custom API Base</label>
</div>
<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>
<div class="field"></div>
</div>
<div class="grid-3">
<div class="field">
<label for="model">Model</label>