-
-
-
-
-
-
+
+
-
+
@@ -697,25 +693,18 @@
LLM Keys
}
function handleLlmKeyInput(element) {
- const openai = document.getElementById('llm-key-openai');
const anthropic = document.getElementById('llm-key-anthropic');
- const gemini = document.getElementById('llm-key-gemini');
+ const groq = document.getElementById('llm-key-groq');
const select = document.getElementById('llm-routing-model');
const hasValue = element.value.trim() !== '';
- if (element.id === 'llm-key-openai') {
- anthropic.disabled = hasValue;
- gemini.disabled = hasValue;
- if (hasValue) select.value = 'gpt-4o';
- } else if (element.id === 'llm-key-anthropic') {
- openai.disabled = hasValue;
- gemini.disabled = hasValue;
- if (hasValue) select.value = 'claude-3-5-sonnet';
- } else if (element.id === 'llm-key-gemini') {
- openai.disabled = hasValue;
- anthropic.disabled = hasValue;
- if (hasValue) select.value = 'gemini-1-5-pro';
+ if (element.id === 'llm-key-anthropic') {
+ if (groq) groq.disabled = hasValue;
+ if (select && hasValue) select.value = 'claude-3-5-sonnet';
+ } else if (element.id === 'llm-key-groq') {
+ if (anthropic) anthropic.disabled = hasValue;
+ if (select && hasValue) select.value = 'groq';
}
}
@@ -726,45 +715,47 @@ LLM Keys
btn.disabled = true;
btn.classList.add('opacity-70', 'cursor-not-allowed');
- const select = document.getElementById('llm-routing-model');
- const keyName = select.value;
-
- let keyValue = '';
- if (keyName === 'gpt-4o') {
- keyValue = document.getElementById('llm-key-openai').value;
- } else if (keyName === 'claude-3-5-sonnet') {
- keyValue = document.getElementById('llm-key-anthropic').value;
- } else if (keyName === 'gemini-1-5-pro') {
- keyValue = document.getElementById('llm-key-gemini').value;
- }
+ const anthropicKey = document.getElementById('llm-key-anthropic')?.value;
+ const groqKey = document.getElementById('llm-key-groq')?.value;
try {
let metricsHostname = 'docs-embeddings-qdrant.zapconnecthub.com';
if (window.location.hostname && window.location.hostname !== 'localhost' && window.location.hostname !== '127.0.0.1') {
metricsHostname = window.location.hostname.replace('wikijs', 'docs-embeddings-qdrant');
}
- const response = await fetch(`https://${metricsHostname}/keys`, {
- method: 'POST',
- headers: {
- 'accept': 'application/json',
- 'Authorization': `Bearer ${sessionStorage.getItem('wiki_dashboard_jwt') || ''}`,
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- key_name: keyName,
- key_value: keyValue
- })
- });
- if (!response.ok) {
- console.error('Failed to save LLM Key', response.statusText);
- showToast('Failed to save LLM key', true);
+ const saveKey = async (name, value) => {
+ if (!value) return true; // Nothing to save
+ const response = await fetch(`https://${metricsHostname}/keys`, {
+ method: 'POST',
+ headers: {
+ 'accept': 'application/json',
+ 'Authorization': `Bearer ${sessionStorage.getItem('wiki_dashboard_jwt') || ''}`,
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({
+ key_name: name,
+ key_value: value
+ })
+ });
+ if (!response.ok) {
+ console.error(`Failed to save ${name}`, response.statusText);
+ return false;
+ }
+ return true;
+ };
+
+ const savedAnthropic = await saveKey('ANTHROPIC_API_KEY', anthropicKey);
+ const savedGroq = await saveKey('GROQ_API_KEY', groqKey);
+
+ if (!savedAnthropic || !savedGroq) {
+ showToast('Failed to save one or more LLM keys', true);
} else {
- showToast('LLM key saved successfully');
+ showToast('LLM keys saved successfully');
}
} catch (err) {
console.error('Request failed', err);
- showToast('Network error, failed to save LLM key', true);
+ showToast('Network error, failed to save LLM keys', true);
} finally {
closeDrawers();
setTimeout(() => {
@@ -820,7 +811,7 @@ LLM Keys
}, 500);
}
- document.addEventListener('DOMContentLoaded', () => {
+ // document.addEventListener('DOMContentLoaded', () => {
const loginModal = document.getElementById('login-modal');
const loginForm = document.getElementById('login-form');
const loginError = document.getElementById('login-error');
@@ -1113,7 +1104,7 @@ ${s.name}
loginSubmit.innerHTML = originalText;
}
});
- });
+