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,27 +239,20 @@ export function validateTextGenUrl() {
} }
export function getTextGenServer() { export function getTextGenServer() {
if (settings.type === MANCER) { switch (settings.type) {
return MANCER_SERVER; case MANCER:
return MANCER_SERVER;
case TOGETHERAI:
return TOGETHERAI_SERVER;
case INFERMATICAI:
return INFERMATICAI_SERVER;
case DREAMGEN:
return DREAMGEN_SERVER;
case OPENROUTER:
return OPENROUTER_SERVER;
default:
return settings.server_urls[settings.type] ?? '';
} }
if (settings.type === TOGETHERAI) {
return TOGETHERAI_SERVER;
}
if (settings.type === INFERMATICAI) {
return INFERMATICAI_SERVER;
}
if (settings.type === DREAMGEN) {
return DREAMGEN_SERVER;
}
if (settings.type === OPENROUTER) {
return OPENROUTER_SERVER;
}
return settings.server_urls[settings.type] ?? '';
} }
async function selectPreset(name) { async function selectPreset(name) {
@ -282,8 +275,8 @@ async function selectPreset(name) {
function formatTextGenURL(value) { function formatTextGenURL(value) {
try { try {
// Mancer/Together/InfermaticAI doesn't need any formatting (it's hardcoded) const noFormatTypes = [MANCER, TOGETHERAI, INFERMATICAI, DREAMGEN, OPENROUTER];
if (settings.type === MANCER || settings.type === TOGETHERAI || settings.type === INFERMATICAI || settings.type === DREAMGEN || settings.type === OPENROUTER) { if (noFormatTypes.includes(settings.type)) {
return value; return value;
} }
@ -871,7 +864,7 @@ export function parseTextgenLogprobs(token, logprobs) {
if (!logprobs?.length) { if (!logprobs?.length) {
return null; return null;
} }
const candidates = logprobs[0].probs.map(x => [ x.tok_str, x.prob ]); const candidates = logprobs[0].probs.map(x => [x.tok_str, x.prob]);
return { token, topLogprobs: candidates }; return { token, topLogprobs: candidates };
} }
default: default:
@ -934,41 +927,32 @@ function toIntArray(string) {
} }
function getModel() { function getModel() {
if (settings.type === OOBA && settings.custom_model) { switch (settings.type) {
return settings.custom_model; case OOBA:
} if (settings.custom_model) {
return settings.custom_model;
if (settings.type === MANCER) { }
return settings.mancer_model; break;
} case MANCER:
return settings.mancer_model;
if (settings.type === TOGETHERAI) { case TOGETHERAI:
return settings.togetherai_model; return settings.togetherai_model;
} case INFERMATICAI:
return settings.infermaticai_model;
if (settings.type === INFERMATICAI) { case DREAMGEN:
return settings.infermaticai_model; return settings.dreamgen_model;
} case OPENROUTER:
return settings.openrouter_model;
if (settings.type === DREAMGEN) { case APHRODITE:
return settings.dreamgen_model; return settings.aphrodite_model;
} case OLLAMA:
if (!settings.ollama_model) {
if (settings.type === OPENROUTER) { toastr.error('No Ollama model selected.', 'Text Completion API');
return settings.openrouter_model; throw new Error('No Ollama model selected');
} }
return settings.ollama_model;
if (settings.type === APHRODITE) { default:
return settings.aphrodite_model; return undefined;
}
if (settings.type === 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;
} }
return undefined; return undefined;