Add app settings management and update API URL handling
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
|
||||
const API_URL_KEY = 'ollamaApiUrl';
|
||||
const BACKEND_API_URL_KEY = 'backendApiUrl';
|
||||
const OLLAMA_API_URL_KEY = 'ollamaApiUrl';
|
||||
const MODEL_KEY = 'chatModel';
|
||||
const STREAM_KEY = 'streamOutput';
|
||||
const DEFAULT_BACKEND_API_URL = 'http://127.0.0.1:8000';
|
||||
const DEFAULT_OLLAMA_API_URL = 'http://127.0.0.1:11434';
|
||||
|
||||
function resolveBackendApiUrl(settings) {
|
||||
return settings.backendApiUrl || settings.ollamaApiUrl || DEFAULT_BACKEND_API_URL;
|
||||
}
|
||||
|
||||
export default function GeneralSettings({ onModelChange, onStreamOutputChange }) {
|
||||
const [backendApiUrl, setBackendApiUrl] = useState('');
|
||||
const [ollamaApiUrl, setOllamaApiUrl] = useState('');
|
||||
const [models, setModels] = useState([]);
|
||||
const [selectedModel, setSelectedModel] = useState('');
|
||||
@@ -12,6 +20,7 @@ export default function GeneralSettings({ onModelChange, onStreamOutputChange })
|
||||
|
||||
useEffect(() => {
|
||||
window.electronAPI.getSettings().then(settings => {
|
||||
setBackendApiUrl(resolveBackendApiUrl(settings));
|
||||
setOllamaApiUrl(settings.ollamaApiUrl);
|
||||
setSelectedModel(settings.chatModel || '');
|
||||
setStreamOutput(settings.streamOutput || false);
|
||||
@@ -19,8 +28,8 @@ export default function GeneralSettings({ onModelChange, onStreamOutputChange })
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (ollamaApiUrl) {
|
||||
fetch(ollamaApiUrl + '/models')
|
||||
if (backendApiUrl) {
|
||||
fetch(backendApiUrl + '/models')
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
const names = data.models?.map(m => m.name) || [];
|
||||
@@ -34,12 +43,18 @@ export default function GeneralSettings({ onModelChange, onStreamOutputChange })
|
||||
})
|
||||
.catch(err => console.error('Failed to load models', err));
|
||||
}
|
||||
}, [ollamaApiUrl, selectedModel]); // Depend on selectedModel to re-evaluate default selection
|
||||
}, [backendApiUrl, selectedModel]); // Depend on selectedModel to re-evaluate default selection
|
||||
|
||||
const handleUrlChange = (e) => {
|
||||
const handleBackendUrlChange = (e) => {
|
||||
const newUrl = e.target.value;
|
||||
setBackendApiUrl(newUrl);
|
||||
window.electronAPI.setSetting(BACKEND_API_URL_KEY, newUrl);
|
||||
};
|
||||
|
||||
const handleOllamaUrlChange = (e) => {
|
||||
const newUrl = e.target.value;
|
||||
setOllamaApiUrl(newUrl);
|
||||
window.electronAPI.setSetting(API_URL_KEY, newUrl);
|
||||
window.electronAPI.setSetting(OLLAMA_API_URL_KEY, newUrl);
|
||||
};
|
||||
|
||||
const handleModelChange = (e) => {
|
||||
@@ -63,14 +78,26 @@ export default function GeneralSettings({ onModelChange, onStreamOutputChange })
|
||||
return (
|
||||
<div className="settings-content-panel">
|
||||
<div className="setting-section">
|
||||
<h3>Ollama API URL</h3>
|
||||
<h3>Heimgeist Backend URL</h3>
|
||||
<input
|
||||
type="text"
|
||||
className="input"
|
||||
value={backendApiUrl}
|
||||
onChange={handleBackendUrlChange}
|
||||
placeholder={`e.g., ${DEFAULT_BACKEND_API_URL}`}
|
||||
/>
|
||||
<p className="setting-description">Internal UI requests like chats, sessions, and databases go to this URL.</p>
|
||||
</div>
|
||||
<div className="setting-section">
|
||||
<h3>Ollama URL</h3>
|
||||
<input
|
||||
type="text"
|
||||
className="input"
|
||||
value={ollamaApiUrl}
|
||||
onChange={handleUrlChange}
|
||||
placeholder="e.g., http://localhost:11434"
|
||||
onChange={handleOllamaUrlChange}
|
||||
placeholder={`e.g., ${DEFAULT_OLLAMA_API_URL}`}
|
||||
/>
|
||||
<p className="setting-description">Heimgeist uses this URL to talk to Ollama for models and chat generation.</p>
|
||||
</div>
|
||||
<div className="setting-section">
|
||||
<h3>Chat Model</h3>
|
||||
|
||||
Reference in New Issue
Block a user