use base URL as endpoint ID and remove model name input field - models now selected from dropdown
This commit is contained in:
parent
81a4062b19
commit
461194ee83
6 changed files with 16 additions and 29 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}`;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue