diff --git a/src/chat.js b/src/chat.js index 49bdfe2..cd3b065 100644 --- a/src/chat.js +++ b/src/chat.js @@ -52,7 +52,7 @@ export async function* sendMessage(message) { chatHistory.push({ role: "user", content: message }); // Get API configuration (custom or default) - const apiConfig = getAPIConfig(); + const apiConfig = await getAPIConfig(); let apiUrl, headers, model; @@ -212,7 +212,7 @@ export function getChatHistory() { // Generator function to send a message with custom history (doesn't modify global chatHistory) export async function* sendMessageWithCustomHistory(customHistory) { // Get API configuration (custom or default) - const apiConfig = getAPIConfig(); + const apiConfig = await getAPIConfig(); let apiUrl, headers, model; diff --git a/src/config.js b/src/config.js index 96c96fe..ea5c4ca 100644 --- a/src/config.js +++ b/src/config.js @@ -70,26 +70,29 @@ export const VLLM_ENDPOINTS = [ ]; // Function to get API configuration (custom or default) -export function getAPIConfig() { +export async function getAPIConfig() { try { const useCustomAPI = localStorage.getItem("useCustomAPI") === "true"; if (useCustomAPI) { const customBaseURL = localStorage.getItem("customBaseURL"); const customAPIKey = localStorage.getItem("customAPIKey"); - const customModelName = localStorage.getItem("customModelName"); - if (customBaseURL && customAPIKey && customModelName) { + if (customBaseURL && customAPIKey) { + // Import model functions to get the currently selected model + const { getSelectedModel } = await import("./models.js"); + const selectedModel = getSelectedModel(); + console.log("🔧 Using CUSTOM API:", { endpoint: customBaseURL, - model: customModelName, + model: selectedModel, apiKey: customAPIKey.substring(0, 8) + "..." }); return { isCustom: true, endpoint: customBaseURL, apiKey: customAPIKey, - model: customModelName, + model: selectedModel, headers: { "Authorization": `Bearer ${customAPIKey}`, "Content-Type": "application/json" @@ -98,8 +101,7 @@ export function getAPIConfig() { } else { console.log("⚠️ Custom API enabled but missing configuration:", { baseURL: !!customBaseURL, - apiKey: !!customAPIKey, - modelName: !!customModelName + apiKey: !!customAPIKey }); } } diff --git a/src/models.js b/src/models.js index f6d71be..5252247 100644 --- a/src/models.js +++ b/src/models.js @@ -32,10 +32,10 @@ export async function fetchModelsFromEndpoints() { const endpointsToFetch = [...VLLM_ENDPOINTS]; // Add custom API endpoint if configured - const apiConfig = getAPIConfig(); + const apiConfig = await getAPIConfig(); if (apiConfig.isCustom) { endpointsToFetch.push({ - id: "custom-api", + id: apiConfig.endpoint, url: apiConfig.endpoint }); } @@ -48,7 +48,7 @@ export async function fetchModelsFromEndpoints() { }; // Add authorization for custom API - if (endpoint.id === "custom-api" && apiConfig.isCustom) { + if (endpoint.id === apiConfig.endpoint && apiConfig.isCustom) { headers["Authorization"] = `Bearer ${apiConfig.apiKey}`; } diff --git a/src/translation.js b/src/translation.js index 9579704..47e3ecd 100644 --- a/src/translation.js +++ b/src/translation.js @@ -51,7 +51,7 @@ export const NATIVE_LANGUAGE_NAMES = { // Send message with custom history (for translation with minimal system prompt) async function* sendMessageWithHistory(messageHistory) { // Get API configuration (custom or default) - const apiConfig = getAPIConfig(); + const apiConfig = await getAPIConfig(); let apiUrl, headers, model; diff --git a/src/ui.js b/src/ui.js index becf7a3..f375304 100644 --- a/src/ui.js +++ b/src/ui.js @@ -115,7 +115,7 @@ function addCodeBlockCopyButtons(element) { // Send message with custom history (for intro generation) async function* sendMessageWithCustomHistory(messageHistory) { // Get API configuration (custom or default) - const apiConfig = getAPIConfig(); + const apiConfig = await getAPIConfig(); let apiUrl, headers, model; diff --git a/src/uncloseai-embed-modal.js b/src/uncloseai-embed-modal.js index 8f9ce9f..5081f5d 100644 --- a/src/uncloseai-embed-modal.js +++ b/src/uncloseai-embed-modal.js @@ -465,17 +465,6 @@ async function openUncloseaiEmbeddedModalNew() { apiKeyContainer.appendChild(apiKeyInput); - // Model Name input - const modelNameContainer = document.createElement("div"); - modelNameContainer.className = "uncloseai-input-container"; - - const modelNameInput = document.createElement("input"); - modelNameInput.type = "text"; - modelNameInput.placeholder = "Model Name"; - modelNameInput.value = localStorage.getItem("customModelName") || ""; - modelNameInput.className = "uncloseai-input"; - - modelNameContainer.appendChild(modelNameInput); // API Config container for inputs const apiConfigInputs = document.createElement("div"); @@ -483,7 +472,6 @@ async function openUncloseaiEmbeddedModalNew() { apiConfigInputs.style.display = customAPICheckbox.checked ? "block" : "none"; apiConfigInputs.appendChild(baseURLContainer); apiConfigInputs.appendChild(apiKeyContainer); - apiConfigInputs.appendChild(modelNameContainer); // Event handlers customAPICheckbox.onchange = () => { @@ -500,9 +488,6 @@ async function openUncloseaiEmbeddedModalNew() { localStorage.setItem("customAPIKey", apiKeyInput.value); }; - modelNameInput.onchange = () => { - localStorage.setItem("customModelName", modelNameInput.value); - }; apiConfigSection.appendChild(customAPIToggle); apiConfigSection.appendChild(apiConfigInputs);