mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-07-24 07:45:57 +02:00
Added:
- v1 completions (OpenAI compatible) and testing connection
- Add API key handling for Ollama and v1 completions if required
Co-authored-by: midhun kumar <midh0001@student.monash.edu>
Reviewed-on: https://codeberg.org/ArkHost/HelixNotes/pulls/74
This commit is contained in:
+192
-2
@@ -21,6 +21,8 @@ pub fn ai_request(
|
||||
std::thread::spawn(move || {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
// Handle all API keys as optional; ollama and v1 completions doesnt always require it.
|
||||
let key_opt = if api_key.is_empty() { None } else { Some(api_key.as_str()) };
|
||||
let result = match provider.as_str() {
|
||||
"openai" => {
|
||||
stream_openai(
|
||||
@@ -40,7 +42,7 @@ pub fn ai_request(
|
||||
stream_openai(
|
||||
&app,
|
||||
&url,
|
||||
None,
|
||||
key_opt,
|
||||
&model,
|
||||
&system_prompt,
|
||||
&user_message,
|
||||
@@ -48,6 +50,24 @@ pub fn ai_request(
|
||||
)
|
||||
.await
|
||||
}
|
||||
"openai_compatible" => {
|
||||
let url = base_url.as_deref().unwrap_or("");
|
||||
if url.is_empty() {
|
||||
Err("No base URL configured for OpenAI Compatible provider".to_string())
|
||||
} else {
|
||||
let url = format!("{}/v1/completions", url.trim_end_matches('/'));
|
||||
stream_completions(
|
||||
&app,
|
||||
&url,
|
||||
key_opt,
|
||||
&model,
|
||||
&system_prompt,
|
||||
&user_message,
|
||||
&request_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
stream_anthropic(
|
||||
&app,
|
||||
@@ -353,12 +373,21 @@ pub async fn test_connection(
|
||||
model: &str,
|
||||
base_url: Option<&str>,
|
||||
) -> Result<String, String> {
|
||||
let key_opt = if api_key.is_empty() { None } else { Some(api_key) };
|
||||
match provider {
|
||||
"openai" => test_openai(OPENAI_API_URL, Some(api_key), model).await,
|
||||
"ollama" => {
|
||||
let url = base_url.unwrap_or(OLLAMA_DEFAULT_URL);
|
||||
let url = format!("{}/v1/chat/completions", url.trim_end_matches('/'));
|
||||
test_openai(&url, None, model).await
|
||||
test_openai(&url, key_opt, model).await
|
||||
}
|
||||
"openai_compatible" => {
|
||||
let url = base_url.unwrap_or("");
|
||||
if url.is_empty() {
|
||||
return Err("No base URL configured for OpenAI Compatible provider".to_string());
|
||||
}
|
||||
let url = format!("{}/v1/completions", url.trim_end_matches('/'));
|
||||
test_completions(&url, key_opt, model).await
|
||||
}
|
||||
_ => test_anthropic(api_key, model).await,
|
||||
}
|
||||
@@ -397,6 +426,167 @@ async fn test_anthropic(api_key: &str, model: &str) -> Result<String, String> {
|
||||
}
|
||||
}
|
||||
|
||||
async fn stream_completions(
|
||||
app: &AppHandle,
|
||||
url: &str,
|
||||
api_key: Option<&str>,
|
||||
model: &str,
|
||||
system_prompt: &str,
|
||||
user_message: &str,
|
||||
_request_id: &str,
|
||||
) -> Result<(), String> {
|
||||
let client = Client::new();
|
||||
|
||||
let prompt = format!("{}\n\nUser: {}\nAssistant:", system_prompt, user_message);
|
||||
|
||||
let body = json!({
|
||||
"model": model,
|
||||
"prompt": prompt,
|
||||
"max_tokens": 4096,
|
||||
"stream": true,
|
||||
"temperature": 0.7
|
||||
});
|
||||
|
||||
let mut req = client
|
||||
.post(url)
|
||||
.header("content-type", "application/json");
|
||||
|
||||
if let Some(key) = api_key {
|
||||
req = req.header("Authorization", format!("Bearer {}", key));
|
||||
}
|
||||
|
||||
let response = req
|
||||
.json(&body)
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("Request failed: {}", e))?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
let status = response.status();
|
||||
let body_text = response.text().await.unwrap_or_default();
|
||||
return Err(format!("API error {}: {}", status, body_text));
|
||||
}
|
||||
|
||||
// Parse SSE stream
|
||||
use futures::StreamExt;
|
||||
let mut stream = response.bytes_stream();
|
||||
let mut buffer = String::new();
|
||||
|
||||
while let Some(chunk) = stream.next().await {
|
||||
let chunk = chunk.map_err(|e| format!("Stream error: {}", e))?;
|
||||
buffer.push_str(&String::from_utf8_lossy(&chunk));
|
||||
|
||||
// Process complete SSE events from buffer
|
||||
while let Some(event_end) = buffer.find("\n\n") {
|
||||
let event_str = buffer[..event_end].to_string();
|
||||
buffer = buffer[event_end + 2..].to_string();
|
||||
|
||||
for line in event_str.lines() {
|
||||
if let Some(data) = line.strip_prefix("data: ") {
|
||||
if data == "[DONE]" {
|
||||
let _ = app.emit(
|
||||
"ai-stream",
|
||||
AiStreamEvent {
|
||||
event_type: "done".to_string(),
|
||||
text: None,
|
||||
error: None,
|
||||
},
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Ok(parsed) = serde_json::from_str::<serde_json::Value>(data) {
|
||||
// Completions streaming: choices[0].text
|
||||
if let Some(text) = parsed["choices"][0]["text"].as_str() {
|
||||
if !text.is_empty() {
|
||||
let _ = app.emit(
|
||||
"ai-stream",
|
||||
AiStreamEvent {
|
||||
event_type: "text".to_string(),
|
||||
text: Some(text.to_string()),
|
||||
error: None,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Check finish_reason
|
||||
if let Some(reason) = parsed["choices"][0]["finish_reason"].as_str() {
|
||||
if reason == "stop" || reason == "length" {
|
||||
let _ = app.emit(
|
||||
"ai-stream",
|
||||
AiStreamEvent {
|
||||
event_type: "done".to_string(),
|
||||
text: None,
|
||||
error: None,
|
||||
},
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
// Check for error in stream
|
||||
if let Some(err) = parsed["error"]["message"].as_str() {
|
||||
let _ = app.emit(
|
||||
"ai-stream",
|
||||
AiStreamEvent {
|
||||
event_type: "error".to_string(),
|
||||
text: None,
|
||||
error: Some(err.to_string()),
|
||||
},
|
||||
);
|
||||
return Err(err.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let _ = app.emit(
|
||||
"ai-stream",
|
||||
AiStreamEvent {
|
||||
event_type: "done".to_string(),
|
||||
text: None,
|
||||
error: None,
|
||||
},
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn test_completions(url: &str, api_key: Option<&str>, model: &str) -> Result<String, String> {
|
||||
let client = Client::new();
|
||||
|
||||
let body = json!({
|
||||
"model": model,
|
||||
"prompt": "Hi",
|
||||
"max_tokens": 10,
|
||||
});
|
||||
|
||||
let mut req = client
|
||||
.post(url)
|
||||
.header("content-type", "application/json");
|
||||
|
||||
if let Some(key) = api_key {
|
||||
req = req.header("Authorization", format!("Bearer {}", key));
|
||||
}
|
||||
|
||||
let response = req
|
||||
.json(&body)
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("Connection failed: {}", e))?;
|
||||
|
||||
if response.status().is_success() {
|
||||
Ok("Connection successful".to_string())
|
||||
} else {
|
||||
let status = response.status();
|
||||
let body_text = response.text().await.unwrap_or_default();
|
||||
Err(format!("API error {}: {}", status, body_text))
|
||||
}
|
||||
}
|
||||
|
||||
async fn test_openai(url: &str, api_key: Option<&str>, model: &str) -> Result<String, String> {
|
||||
let client = Client::new();
|
||||
|
||||
|
||||
+29
-16
@@ -1654,12 +1654,22 @@ pub fn set_ai_settings(
|
||||
model: String,
|
||||
writing_style: Option<String>,
|
||||
base_url: Option<String>,
|
||||
ollama_api_key: Option<String>,
|
||||
openai_compatible_base_url: Option<String>,
|
||||
openai_compatible_api_key: Option<String>,
|
||||
) -> Result<(), String> {
|
||||
let mut config = state.config.lock().map_err(|e| e.to_string())?;
|
||||
let key = api_key.filter(|k| !k.is_empty());
|
||||
match provider.as_deref() {
|
||||
Some("openai") => config.openai_api_key = key,
|
||||
Some("ollama") => config.ollama_base_url = base_url.filter(|u| !u.trim().is_empty()),
|
||||
Some("ollama") => {
|
||||
config.ollama_base_url = base_url.filter(|u| !u.trim().is_empty());
|
||||
config.ollama_api_key = ollama_api_key.filter(|k| !k.is_empty());
|
||||
}
|
||||
Some("openai_compatible") => {
|
||||
config.openai_compatible_base_url = openai_compatible_base_url.filter(|u| !u.trim().is_empty());
|
||||
config.openai_compatible_api_key = openai_compatible_api_key.filter(|k| !k.is_empty());
|
||||
}
|
||||
_ => config.ai_api_key = key,
|
||||
}
|
||||
config.ai_provider = provider;
|
||||
@@ -1678,17 +1688,18 @@ pub fn test_ai_connection(app: AppHandle) -> Result<(), String> {
|
||||
.ai_provider
|
||||
.clone()
|
||||
.unwrap_or_else(|| "anthropic".to_string());
|
||||
let key = if provider == "ollama" {
|
||||
// Ollama doesn't require an API key
|
||||
Some(String::new())
|
||||
} else if provider == "openai" {
|
||||
config.openai_api_key.clone()
|
||||
} else {
|
||||
config.ai_api_key.clone()
|
||||
let key = match provider.as_str() {
|
||||
"ollama" => Some(config.ollama_api_key.clone().unwrap_or_default()),
|
||||
"openai_compatible" => Some(config.openai_compatible_api_key.clone().unwrap_or_default()),
|
||||
"openai" => config.openai_api_key.clone(),
|
||||
_ => config.ai_api_key.clone(),
|
||||
}
|
||||
.ok_or("No API key configured")?;
|
||||
let model = config.ai_model.clone();
|
||||
let base_url = config.ollama_base_url.clone();
|
||||
let base_url = match provider.as_str() {
|
||||
"openai_compatible" => config.openai_compatible_base_url.clone(),
|
||||
_ => config.ollama_base_url.clone(),
|
||||
};
|
||||
(provider, key, model, base_url)
|
||||
};
|
||||
|
||||
@@ -1734,17 +1745,19 @@ pub fn ai_ask(
|
||||
.ai_provider
|
||||
.clone()
|
||||
.unwrap_or_else(|| "anthropic".to_string());
|
||||
let key = if provider == "ollama" {
|
||||
Some(String::new())
|
||||
} else if provider == "openai" {
|
||||
config.openai_api_key.clone()
|
||||
} else {
|
||||
config.ai_api_key.clone()
|
||||
let key = match provider.as_str() {
|
||||
"ollama" => Some(config.ollama_api_key.clone().unwrap_or_default()),
|
||||
"openai_compatible" => Some(config.openai_compatible_api_key.clone().unwrap_or_default()),
|
||||
"openai" => config.openai_api_key.clone(),
|
||||
_ => config.ai_api_key.clone(),
|
||||
}
|
||||
.ok_or("No API key configured. Go to Settings > AI to set up your API key.")?;
|
||||
let model = config.ai_model.clone();
|
||||
let style = config.ai_writing_style.clone();
|
||||
let base_url = config.ollama_base_url.clone();
|
||||
let base_url = match provider.as_str() {
|
||||
"openai_compatible" => config.openai_compatible_base_url.clone(),
|
||||
_ => config.ollama_base_url.clone(),
|
||||
};
|
||||
(provider, key, model, style, base_url)
|
||||
};
|
||||
|
||||
|
||||
@@ -109,6 +109,12 @@ pub struct AppConfig {
|
||||
pub openai_api_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ollama_base_url: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ollama_api_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub openai_compatible_base_url: Option<String>,
|
||||
#[serde(default)]
|
||||
pub openai_compatible_api_key: Option<String>,
|
||||
#[serde(default = "default_ai_model")]
|
||||
pub ai_model: String,
|
||||
#[serde(default)]
|
||||
@@ -181,6 +187,9 @@ impl Default for AppConfig {
|
||||
ai_api_key: None,
|
||||
openai_api_key: None,
|
||||
ollama_base_url: None,
|
||||
ollama_api_key: None,
|
||||
openai_compatible_base_url: None,
|
||||
openai_compatible_api_key: None,
|
||||
ai_model: "claude-sonnet-4-6".to_string(),
|
||||
ai_writing_style: None,
|
||||
default_view_mode: false,
|
||||
|
||||
+7
-1
@@ -351,8 +351,14 @@ export async function setAiSettings(
|
||||
model: string,
|
||||
writingStyle: string | null,
|
||||
baseUrl: string | null = null,
|
||||
ollamaApiKey: string | null = null,
|
||||
openaiCompatibleBaseUrl: string | null = null,
|
||||
openaiCompatibleApiKey: string | null = null,
|
||||
): Promise<void> {
|
||||
return invoke("set_ai_settings", { provider, apiKey, model, writingStyle, baseUrl });
|
||||
return invoke("set_ai_settings", {
|
||||
provider, apiKey, model, writingStyle, baseUrl,
|
||||
ollamaApiKey, openaiCompatibleBaseUrl, openaiCompatibleApiKey,
|
||||
});
|
||||
}
|
||||
|
||||
export async function testAiConnection(): Promise<void> {
|
||||
|
||||
@@ -219,14 +219,20 @@
|
||||
let aiApiKey = $derived.by(() => {
|
||||
if (aiProvider === 'openai') return _openaiKey;
|
||||
if (aiProvider === 'ollama') return '';
|
||||
if (aiProvider === 'openai_compatible') return _openaiCompatibleKey;
|
||||
return _anthropicKey;
|
||||
});
|
||||
let _anthropicKey = $state($appConfig?.ai_api_key ?? '');
|
||||
let _openaiKey = $state($appConfig?.openai_api_key ?? '');
|
||||
let _ollamaBaseUrl = $state($appConfig?.ollama_base_url ?? 'http://localhost:11434');
|
||||
let _ollamaApiKey = $state($appConfig?.ollama_api_key ?? '');
|
||||
let _openaiCompatibleBaseUrl = $state($appConfig?.openai_compatible_base_url ?? '');
|
||||
let _openaiCompatibleKey = $state($appConfig?.openai_compatible_api_key ?? '');
|
||||
let aiModel = $state($appConfig?.ai_model ?? 'claude-sonnet-4-6');
|
||||
let aiWritingStyle = $state($appConfig?.ai_writing_style ?? '');
|
||||
let aiShowKey = $state(false);
|
||||
let aiShowCompatibleKey = $state(false);
|
||||
let aiShowOllamaKey = $state(false);
|
||||
let aiTestLoading = $state(false);
|
||||
let aiTestMessage = $state<{ type: 'success' | 'error'; text: string } | null>(null);
|
||||
|
||||
@@ -245,7 +251,16 @@
|
||||
|
||||
async function saveAiSettings() {
|
||||
const baseUrl = aiProvider === 'ollama' ? (_ollamaBaseUrl || null) : null;
|
||||
await setAiSettings(aiProvider, aiApiKey || null, aiModel, aiWritingStyle || null, baseUrl);
|
||||
await setAiSettings(
|
||||
aiProvider,
|
||||
aiApiKey || null,
|
||||
aiModel,
|
||||
aiWritingStyle || null,
|
||||
baseUrl,
|
||||
_ollamaApiKey || null,
|
||||
_openaiCompatibleBaseUrl || null,
|
||||
_openaiCompatibleKey || null,
|
||||
);
|
||||
if ($appConfig) {
|
||||
$appConfig = {
|
||||
...$appConfig,
|
||||
@@ -253,6 +268,9 @@
|
||||
ai_api_key: _anthropicKey || null,
|
||||
openai_api_key: _openaiKey || null,
|
||||
ollama_base_url: _ollamaBaseUrl || null,
|
||||
ollama_api_key: _ollamaApiKey || null,
|
||||
openai_compatible_base_url: _openaiCompatibleBaseUrl || null,
|
||||
openai_compatible_api_key: _openaiCompatibleKey || null,
|
||||
ai_model: aiModel,
|
||||
ai_writing_style: aiWritingStyle || null,
|
||||
};
|
||||
@@ -1037,16 +1055,17 @@
|
||||
<div class="tab-content">
|
||||
<div class="settings-section">
|
||||
<h3>Provider</h3>
|
||||
<div class="setting-options">
|
||||
<div class="setting-options" style="flex-wrap: wrap;">
|
||||
<button class="option-btn" class:active={!aiProvider} onclick={() => { if (!aiProvider) return; aiProvider = null; aiTestMessage = null; saveAiSettings(); }}>Disabled</button>
|
||||
<button class="option-btn" class:active={aiProvider === 'ollama'} onclick={() => { if (aiProvider === 'ollama') return; aiProvider = 'ollama'; aiModel = 'gemma3:4b'; aiTestMessage = null; saveAiSettings(); }}>Ollama</button>
|
||||
<button class="option-btn" class:active={aiProvider === 'anthropic'} onclick={() => { if (aiProvider === 'anthropic') return; aiProvider = 'anthropic'; aiModel = 'claude-sonnet-4-6'; aiTestMessage = null; saveAiSettings(); }}>Anthropic</button>
|
||||
<button class="option-btn" class:active={aiProvider === 'openai'} onclick={() => { if (aiProvider === 'openai') return; aiProvider = 'openai'; aiModel = 'gpt-5.2'; aiTestMessage = null; saveAiSettings(); }}>OpenAI</button>
|
||||
<button class="option-btn" class:active={aiProvider === 'openai_compatible'} onclick={() => { if (aiProvider === 'openai_compatible') return; aiProvider = 'openai_compatible'; aiModel = ''; aiTestMessage = null; saveAiSettings(); }}>Compatible</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if aiProvider}
|
||||
{#if aiProvider === 'ollama'}
|
||||
{#if aiProvider === 'ollama' || aiProvider === 'openai_compatible'}
|
||||
<p class="setting-hint" style="color: var(--text-success, #4ade80); margin-top: -4px; margin-bottom: 12px;">Your data stays on your device. No text is sent to any external server.</p>
|
||||
{:else}
|
||||
<p class="setting-hint" style="color: var(--text-warning, #f59e0b); margin-top: -4px; margin-bottom: 12px;">Your selected text and note content will be sent to {aiProvider === 'openai' ? 'OpenAI' : 'Anthropic'} servers for processing.</p>
|
||||
@@ -1065,6 +1084,59 @@
|
||||
/>
|
||||
<p class="setting-hint">Ollama server address. Install from <a href="https://ollama.com" target="_blank" class="ai-link">ollama.com</a></p>
|
||||
</div>
|
||||
<div class="settings-section">
|
||||
<h3>API Key <span style="font-weight: 400; text-transform: none; font-size: 11px;">(optional)</span></h3>
|
||||
<div class="ai-key-row">
|
||||
<input
|
||||
type={aiShowOllamaKey ? 'text' : 'password'}
|
||||
class="ai-key-input"
|
||||
placeholder="Only required if your server requires auth"
|
||||
value={_ollamaApiKey}
|
||||
oninput={(e) => { _ollamaApiKey = (e.target as HTMLInputElement).value; }}
|
||||
onblur={saveAiSettings}
|
||||
/>
|
||||
<button class="ai-key-toggle" onclick={() => aiShowOllamaKey = !aiShowOllamaKey} title={aiShowOllamaKey ? 'Hide' : 'Show'}>
|
||||
{#if aiShowOllamaKey}
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17.94 17.94A10.07 10.07 0 0112 20c-7 0-11-8-11-8a18.45 18.45 0 015.06-5.94M9.9 4.24A9.12 9.12 0 0112 4c7 0 11 8 11 8a18.5 18.5 0 01-2.16 3.19m-6.72-1.07a3 3 0 11-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/></svg>
|
||||
{:else}
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{:else if aiProvider === 'openai_compatible'}
|
||||
<div class="settings-section">
|
||||
<h3>Server URL</h3>
|
||||
<input
|
||||
type="text"
|
||||
class="ai-key-input"
|
||||
placeholder="http://localhost:1234"
|
||||
value={_openaiCompatibleBaseUrl}
|
||||
oninput={(e) => { _openaiCompatibleBaseUrl = (e.target as HTMLInputElement).value; }}
|
||||
onblur={saveAiSettings}
|
||||
/>
|
||||
<p class="setting-hint">Base URL for any OpenAI-compatible server (LM Studio, LocalAI, vLLM, etc.). Uses the <code>v1/completions</code> endpoint.</p>
|
||||
</div>
|
||||
<div class="settings-section">
|
||||
<h3>API Key <span style="font-weight: 400; text-transform: none; font-size: 11px;">(optional)</span></h3>
|
||||
<div class="ai-key-row">
|
||||
<input
|
||||
type={aiShowCompatibleKey ? 'text' : 'password'}
|
||||
class="ai-key-input"
|
||||
placeholder="Leave empty if no auth required"
|
||||
value={_openaiCompatibleKey}
|
||||
oninput={(e) => { _openaiCompatibleKey = (e.target as HTMLInputElement).value; }}
|
||||
onblur={saveAiSettings}
|
||||
/>
|
||||
<button class="ai-key-toggle" onclick={() => aiShowCompatibleKey = !aiShowCompatibleKey} title={aiShowCompatibleKey ? 'Hide' : 'Show'}>
|
||||
{#if aiShowCompatibleKey}
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17.94 17.94A10.07 10.07 0 0112 20c-7 0-11-8-11-8a18.45 18.45 0 015.06-5.94M9.9 4.24A9.12 9.12 0 0112 4c7 0 11 8 11 8a18.5 18.5 0 01-2.16 3.19m-6.72-1.07a3 3 0 11-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/></svg>
|
||||
{:else}
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="settings-section">
|
||||
<h3>API Key</h3>
|
||||
@@ -1095,16 +1167,16 @@
|
||||
|
||||
<div class="settings-section">
|
||||
<h3>Model</h3>
|
||||
{#if aiProvider === 'ollama'}
|
||||
{#if aiProvider === 'ollama' || aiProvider === 'openai_compatible'}
|
||||
<input
|
||||
type="text"
|
||||
class="ai-key-input"
|
||||
placeholder="gemma3:4b"
|
||||
placeholder={aiProvider === 'ollama' ? 'gemma3:4b' : 'Enter model name'}
|
||||
value={aiModel}
|
||||
oninput={(e) => { aiModel = (e.target as HTMLInputElement).value; }}
|
||||
onblur={saveAiSettings}
|
||||
/>
|
||||
<p class="setting-hint">Enter the model name as shown by <code>ollama list</code></p>
|
||||
<p class="setting-hint">{aiProvider === 'ollama' ? 'Enter the model name as shown by <code>ollama list</code>' : 'Enter the model name as required by your server'}</p>
|
||||
{:else}
|
||||
<div class="ai-model-options">
|
||||
{#each aiModels as m}
|
||||
@@ -1136,7 +1208,7 @@
|
||||
|
||||
<div class="settings-section">
|
||||
<h3>Connection</h3>
|
||||
<button class="import-btn" onclick={handleTestAi} disabled={aiTestLoading || (aiProvider !== 'ollama' && !aiApiKey)}>
|
||||
<button class="import-btn" onclick={handleTestAi} disabled={aiTestLoading || (aiProvider === 'openai_compatible' && !_openaiCompatibleBaseUrl) || (aiProvider !== 'ollama' && aiProvider !== 'openai_compatible' && !aiApiKey)}>
|
||||
{#if aiTestLoading}
|
||||
<svg class="spinner-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10" opacity="0.25" /><path d="M12 2a10 10 0 019.95 9" /></svg>
|
||||
Testing...
|
||||
|
||||
@@ -73,6 +73,9 @@ export interface AppConfig {
|
||||
ai_api_key: string | null;
|
||||
openai_api_key: string | null;
|
||||
ollama_base_url: string | null;
|
||||
ollama_api_key: string | null;
|
||||
openai_compatible_base_url: string | null;
|
||||
openai_compatible_api_key: string | null;
|
||||
ai_model: string;
|
||||
ai_writing_style: string | null;
|
||||
default_view_mode: boolean;
|
||||
|
||||
Reference in New Issue
Block a user