mirror of
https://github.com/elder-plinius/AutoTemp.git
synced 2026-07-31 08:27:26 +02:00
feat(ui): optional custom API Base toggle for local OpenAI-compatible servers
This commit is contained in:
+16
-2
@@ -1,10 +1,12 @@
|
|||||||
async function openAIChat(apiKey, model, messages, temperature = 0.7, top_p = 1.0, extra = {}) {
|
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, {
|
const res = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': `Bearer ${apiKey}`
|
...(apiKey ? { 'Authorization': `Bearer ${apiKey}` } : {})
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ model, messages, temperature, top_p, ...extra })
|
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.data.datasets[0].data.push({ x: temp, y: mean });
|
||||||
c.update('none');
|
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
|
// Run state and controls
|
||||||
let running = false;
|
let running = false;
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
|||||||
@@ -24,6 +24,16 @@
|
|||||||
<input type="checkbox" id="rememberKey" /> Remember in this browser
|
<input type="checkbox" id="rememberKey" /> Remember in this browser
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</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="grid-3">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="model">Model</label>
|
<label for="model">Model</label>
|
||||||
|
|||||||
Reference in New Issue
Block a user