Spaces:
Running
Running
Update js/iaConfigModule.js
Browse files- js/iaConfigModule.js +5 -22
js/iaConfigModule.js
CHANGED
|
@@ -11,9 +11,10 @@ const defaultConfig = {
|
|
| 11 |
models: { openai: "whisper-1", deepgram: "nova-2" }
|
| 12 |
}
|
| 13 |
};
|
| 14 |
-
|
|
|
|
| 15 |
export const llmProviders = [
|
| 16 |
-
{ name: "OpenAI", value: "openai", models: ["gpt-4o", "gpt-4o-mini"], url: "https://api.openai.com" },
|
| 17 |
{ name: "DeepSeek", value: "deepseek", models: ["deepseek-chat", "deepseek-reasoner"], url: "https://api.deepseek.com" }
|
| 18 |
];
|
| 19 |
export const transcriptionProviders = [
|
|
@@ -50,8 +51,6 @@ function loadConfig() {
|
|
| 50 |
|
| 51 |
let needsSave = false;
|
| 52 |
|
| 53 |
-
// CORRECCI脫N: La l贸gica de migraci贸n para 'transcription' era defectuosa.
|
| 54 |
-
// Pod铆a borrar la API key de Deepgram si era el proveedor antiguo.
|
| 55 |
if (config.transcription.apiKey !== undefined) {
|
| 56 |
console.log("[iaConfigModule] Migrando config antigua de transcripci贸n...");
|
| 57 |
const oldKey = config.transcription.apiKey;
|
|
@@ -92,7 +91,6 @@ export function getIaConfig() {
|
|
| 92 |
export function renderIaConfigForm(containerId) {
|
| 93 |
let config = loadConfig();
|
| 94 |
const container = document.getElementById(containerId);
|
| 95 |
-
// CORRECCI脫N: Errores de sintaxis en el manejo de errores.
|
| 96 |
if (!container) {
|
| 97 |
console.error(`[iaConfigModule] No se encontr贸 el contenedor '${containerId}'`);
|
| 98 |
document.body.insertAdjacentHTML('beforeend', `<div style='color:red; padding: 1rem;'>[Error] No se encontr贸 el contenedor '${containerId}' para la configuraci贸n IA.</div>`);
|
|
@@ -105,7 +103,6 @@ export function renderIaConfigForm(containerId) {
|
|
| 105 |
return `${key.substring(0, 3)}-****-${key.slice(-4)}`;
|
| 106 |
}
|
| 107 |
|
| 108 |
-
// CORRECCI脫N: Errores de sintaxis en la plantilla HTML (faltaban backticks ``).
|
| 109 |
container.innerHTML = `
|
| 110 |
<div class="flex justify-between items-center mb-6 border-b pb-2 border-blue-100">
|
| 111 |
<h2 class="text-xl font-bold text-blue-700 flex items-center"><i class='fas fa-cogs mr-2'></i>Configurar Proveedores IA</h2>
|
|
@@ -149,32 +146,23 @@ export function renderIaConfigForm(containerId) {
|
|
| 149 |
document.getElementById("toggleLlmApiKey").addEventListener("click", () => { llmApiKeyInput.type = llmApiKeyInput.type === "password" ? "text" : "password"; });
|
| 150 |
document.getElementById("toggleTransApiKey").addEventListener("click", () => { transApiKeyInput.type = transApiKeyInput.type === "password" ? "text" : "password"; });
|
| 151 |
|
| 152 |
-
// ===================== INICIO DE LA CORRECCI脫N =====================
|
| 153 |
-
// CORRECCI脫N: L贸gica de actualizaci贸n de UI refactorizada para ser m谩s clara y correcta.
|
| 154 |
function updateLlmUI() {
|
| 155 |
const selectedProvider = llmProviderSelect.value;
|
| 156 |
const providerObj = llmProviders.find(p => p.value === selectedProvider);
|
| 157 |
if (!providerObj) return;
|
| 158 |
|
| 159 |
-
// 1. Popular siempre la lista de modelos del proveedor seleccionado
|
| 160 |
llmModelSelect.innerHTML = providerObj.models.map(m => `<option value="${m}">${m}</option>`).join("");
|
| 161 |
|
| 162 |
-
|
| 163 |
-
let modelToSelect = providerObj.models[0]; // Por defecto, el primero de la lista
|
| 164 |
-
// Si el proveedor seleccionado es el que ya est谩 guardado en la config...
|
| 165 |
if (selectedProvider === config.llm.provider) {
|
| 166 |
-
// ...y si el modelo guardado es v谩lido para este proveedor...
|
| 167 |
if (providerObj.models.includes(config.llm.model)) {
|
| 168 |
-
// ...entonces usamos el modelo guardado.
|
| 169 |
modelToSelect = config.llm.model;
|
| 170 |
}
|
| 171 |
}
|
| 172 |
llmModelSelect.value = modelToSelect;
|
| 173 |
|
| 174 |
-
// 3. Actualizar la API Key
|
| 175 |
llmApiKeyInput.value = maskApiKey(config.llm.apiKeys[selectedProvider] || '');
|
| 176 |
}
|
| 177 |
-
// ===================== FIN DE LA CORRECCI脫N =======================
|
| 178 |
|
| 179 |
function updateTransUI() {
|
| 180 |
const selectedProvider = transProviderSelect.value;
|
|
@@ -182,7 +170,6 @@ export function renderIaConfigForm(containerId) {
|
|
| 182 |
if (!providerObj) return;
|
| 183 |
|
| 184 |
transModelSelect.innerHTML = providerObj.models.map(m => `<option value="${m}">${m}</option>`).join("");
|
| 185 |
-
// La estructura de 'models' en transcripci贸n permite una b煤squeda directa.
|
| 186 |
transModelSelect.value = config.transcription.models[selectedProvider] || providerObj.models[0];
|
| 187 |
transApiKeyInput.value = maskApiKey(config.transcription.apiKeys[selectedProvider] || '');
|
| 188 |
}
|
|
@@ -202,7 +189,6 @@ export function renderIaConfigForm(containerId) {
|
|
| 202 |
const prevConfig = config;
|
| 203 |
const newConfig = clone(prevConfig);
|
| 204 |
|
| 205 |
-
// Guardado de LLM
|
| 206 |
const llmProv = llmProviderSelect.value;
|
| 207 |
const rawLlmKey = llmApiKeyInput.value;
|
| 208 |
const oldLlmKey = prevConfig.llm.apiKeys[llmProv] || '';
|
|
@@ -214,7 +200,6 @@ export function renderIaConfigForm(containerId) {
|
|
| 214 |
apiKeys: { ...prevConfig.llm.apiKeys, [llmProv]: actualLlmKey }
|
| 215 |
};
|
| 216 |
|
| 217 |
-
// Guardado de Transcripci贸n
|
| 218 |
const transProv = transProviderSelect.value;
|
| 219 |
const rawTransKey = transApiKeyInput.value;
|
| 220 |
const oldTransKey = prevConfig.transcription.apiKeys[transProv] || '';
|
|
@@ -227,17 +212,15 @@ export function renderIaConfigForm(containerId) {
|
|
| 227 |
};
|
| 228 |
|
| 229 |
saveConfig(newConfig);
|
| 230 |
-
config = newConfig;
|
| 231 |
|
| 232 |
document.dispatchEvent(new CustomEvent('iaConfigChanged'));
|
| 233 |
|
| 234 |
-
// Resetear UI post-guardado
|
| 235 |
llmApiKeyInput.value = maskApiKey(newConfig.llm.apiKeys[newConfig.llm.provider] || '');
|
| 236 |
transApiKeyInput.value = maskApiKey(newConfig.transcription.apiKeys[newConfig.transcription.provider] || '');
|
| 237 |
llmApiKeyInput.type = "password";
|
| 238 |
transApiKeyInput.type = "password";
|
| 239 |
|
| 240 |
-
// Mensaje de 茅xito
|
| 241 |
let msg = document.getElementById('iaConfigSavedMsg');
|
| 242 |
if (!msg) {
|
| 243 |
msg = document.createElement('div');
|
|
|
|
| 11 |
models: { openai: "whisper-1", deepgram: "nova-2" }
|
| 12 |
}
|
| 13 |
};
|
| 14 |
+
|
| 15 |
+
// CORRECCI脫N: Nombres de modelos de OpenAI actualizados con tus nuevas solicitudes.
|
| 16 |
export const llmProviders = [
|
| 17 |
+
{ name: "OpenAI", value: "openai", models: ["gpt-4o", "gpt-4o-mini", "gpt-5-mini", "gpt-5", "gpt-5-nano"], url: "https://api.openai.com" },
|
| 18 |
{ name: "DeepSeek", value: "deepseek", models: ["deepseek-chat", "deepseek-reasoner"], url: "https://api.deepseek.com" }
|
| 19 |
];
|
| 20 |
export const transcriptionProviders = [
|
|
|
|
| 51 |
|
| 52 |
let needsSave = false;
|
| 53 |
|
|
|
|
|
|
|
| 54 |
if (config.transcription.apiKey !== undefined) {
|
| 55 |
console.log("[iaConfigModule] Migrando config antigua de transcripci贸n...");
|
| 56 |
const oldKey = config.transcription.apiKey;
|
|
|
|
| 91 |
export function renderIaConfigForm(containerId) {
|
| 92 |
let config = loadConfig();
|
| 93 |
const container = document.getElementById(containerId);
|
|
|
|
| 94 |
if (!container) {
|
| 95 |
console.error(`[iaConfigModule] No se encontr贸 el contenedor '${containerId}'`);
|
| 96 |
document.body.insertAdjacentHTML('beforeend', `<div style='color:red; padding: 1rem;'>[Error] No se encontr贸 el contenedor '${containerId}' para la configuraci贸n IA.</div>`);
|
|
|
|
| 103 |
return `${key.substring(0, 3)}-****-${key.slice(-4)}`;
|
| 104 |
}
|
| 105 |
|
|
|
|
| 106 |
container.innerHTML = `
|
| 107 |
<div class="flex justify-between items-center mb-6 border-b pb-2 border-blue-100">
|
| 108 |
<h2 class="text-xl font-bold text-blue-700 flex items-center"><i class='fas fa-cogs mr-2'></i>Configurar Proveedores IA</h2>
|
|
|
|
| 146 |
document.getElementById("toggleLlmApiKey").addEventListener("click", () => { llmApiKeyInput.type = llmApiKeyInput.type === "password" ? "text" : "password"; });
|
| 147 |
document.getElementById("toggleTransApiKey").addEventListener("click", () => { transApiKeyInput.type = transApiKeyInput.type === "password" ? "text" : "password"; });
|
| 148 |
|
|
|
|
|
|
|
| 149 |
function updateLlmUI() {
|
| 150 |
const selectedProvider = llmProviderSelect.value;
|
| 151 |
const providerObj = llmProviders.find(p => p.value === selectedProvider);
|
| 152 |
if (!providerObj) return;
|
| 153 |
|
|
|
|
| 154 |
llmModelSelect.innerHTML = providerObj.models.map(m => `<option value="${m}">${m}</option>`).join("");
|
| 155 |
|
| 156 |
+
let modelToSelect = providerObj.models[0];
|
|
|
|
|
|
|
| 157 |
if (selectedProvider === config.llm.provider) {
|
|
|
|
| 158 |
if (providerObj.models.includes(config.llm.model)) {
|
|
|
|
| 159 |
modelToSelect = config.llm.model;
|
| 160 |
}
|
| 161 |
}
|
| 162 |
llmModelSelect.value = modelToSelect;
|
| 163 |
|
|
|
|
| 164 |
llmApiKeyInput.value = maskApiKey(config.llm.apiKeys[selectedProvider] || '');
|
| 165 |
}
|
|
|
|
| 166 |
|
| 167 |
function updateTransUI() {
|
| 168 |
const selectedProvider = transProviderSelect.value;
|
|
|
|
| 170 |
if (!providerObj) return;
|
| 171 |
|
| 172 |
transModelSelect.innerHTML = providerObj.models.map(m => `<option value="${m}">${m}</option>`).join("");
|
|
|
|
| 173 |
transModelSelect.value = config.transcription.models[selectedProvider] || providerObj.models[0];
|
| 174 |
transApiKeyInput.value = maskApiKey(config.transcription.apiKeys[selectedProvider] || '');
|
| 175 |
}
|
|
|
|
| 189 |
const prevConfig = config;
|
| 190 |
const newConfig = clone(prevConfig);
|
| 191 |
|
|
|
|
| 192 |
const llmProv = llmProviderSelect.value;
|
| 193 |
const rawLlmKey = llmApiKeyInput.value;
|
| 194 |
const oldLlmKey = prevConfig.llm.apiKeys[llmProv] || '';
|
|
|
|
| 200 |
apiKeys: { ...prevConfig.llm.apiKeys, [llmProv]: actualLlmKey }
|
| 201 |
};
|
| 202 |
|
|
|
|
| 203 |
const transProv = transProviderSelect.value;
|
| 204 |
const rawTransKey = transApiKeyInput.value;
|
| 205 |
const oldTransKey = prevConfig.transcription.apiKeys[transProv] || '';
|
|
|
|
| 212 |
};
|
| 213 |
|
| 214 |
saveConfig(newConfig);
|
| 215 |
+
config = newConfig;
|
| 216 |
|
| 217 |
document.dispatchEvent(new CustomEvent('iaConfigChanged'));
|
| 218 |
|
|
|
|
| 219 |
llmApiKeyInput.value = maskApiKey(newConfig.llm.apiKeys[newConfig.llm.provider] || '');
|
| 220 |
transApiKeyInput.value = maskApiKey(newConfig.transcription.apiKeys[newConfig.transcription.provider] || '');
|
| 221 |
llmApiKeyInput.type = "password";
|
| 222 |
transApiKeyInput.type = "password";
|
| 223 |
|
|
|
|
| 224 |
let msg = document.getElementById('iaConfigSavedMsg');
|
| 225 |
if (!msg) {
|
| 226 |
msg = document.createElement('div');
|