Textgen setting refactors

This commit is contained in:
Cohee 2024-03-19 01:38:55 +02:00
parent 80d7f5a2cf
commit c8f84bd413
1 changed files with 42 additions and 58 deletions

View File

@ -239,28 +239,21 @@ export function validateTextGenUrl() {
}
export function getTextGenServer() {
if (settings.type === MANCER) {
switch (settings.type) {
case MANCER:
return MANCER_SERVER;
}
if (settings.type === TOGETHERAI) {
case TOGETHERAI:
return TOGETHERAI_SERVER;
}
if (settings.type === INFERMATICAI) {
case INFERMATICAI:
return INFERMATICAI_SERVER;
}
if (settings.type === DREAMGEN) {
case DREAMGEN:
return DREAMGEN_SERVER;
}
if (settings.type === OPENROUTER) {
case OPENROUTER:
return OPENROUTER_SERVER;
}
default:
return settings.server_urls[settings.type] ?? '';
}
}
async function selectPreset(name) {
const preset = textgenerationwebui_presets[textgenerationwebui_preset_names.indexOf(name)];
@ -282,8 +275,8 @@ async function selectPreset(name) {
function formatTextGenURL(value) {
try {
// Mancer/Together/InfermaticAI doesn't need any formatting (it's hardcoded)
if (settings.type === MANCER || settings.type === TOGETHERAI || settings.type === INFERMATICAI || settings.type === DREAMGEN || settings.type === OPENROUTER) {
const noFormatTypes = [MANCER, TOGETHERAI, INFERMATICAI, DREAMGEN, OPENROUTER];
if (noFormatTypes.includes(settings.type)) {
return value;
}
@ -934,41 +927,32 @@ function toIntArray(string) {
}
function getModel() {
if (settings.type === OOBA && settings.custom_model) {
switch (settings.type) {
case OOBA:
if (settings.custom_model) {
return settings.custom_model;
}
if (settings.type === MANCER) {
break;
case MANCER:
return settings.mancer_model;
}
if (settings.type === TOGETHERAI) {
case TOGETHERAI:
return settings.togetherai_model;
}
if (settings.type === INFERMATICAI) {
case INFERMATICAI:
return settings.infermaticai_model;
}
if (settings.type === DREAMGEN) {
case DREAMGEN:
return settings.dreamgen_model;
}
if (settings.type === OPENROUTER) {
case OPENROUTER:
return settings.openrouter_model;
}
if (settings.type === APHRODITE) {
case APHRODITE:
return settings.aphrodite_model;
}
if (settings.type === OLLAMA) {
case OLLAMA:
if (!settings.ollama_model) {
toastr.error('No Ollama model selected.', 'Text Completion API');
throw new Error('No Ollama model selected');
}
return settings.ollama_model;
default:
return undefined;
}
return undefined;