+ For privacy reasons, your API key will be hidden after you reload the page.
+
+
From 2e1660e895531ffebd013f1915b6253307b71144 Mon Sep 17 00:00:00 2001
From: Fayiron <59962292+Fayiron@users.noreply.github.com>
Date: Sat, 16 Dec 2023 15:08:03 +0100
Subject: [PATCH 3/9] Add TogetherAI model and settings
---
public/scripts/openai.js | 43 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)
diff --git a/public/scripts/openai.js b/public/scripts/openai.js
index 30f4c6e29..e6aa3c43d 100644
--- a/public/scripts/openai.js
+++ b/public/scripts/openai.js
@@ -164,6 +164,7 @@ export const chat_completion_sources = {
OPENROUTER: 'openrouter',
AI21: 'ai21',
PALM: 'palm',
+ TOGETHERAI: 'togetherai',
};
const prefixMap = selected_group ? {
@@ -207,6 +208,7 @@ const default_settings = {
openai_model: 'gpt-3.5-turbo',
claude_model: 'claude-instant-v1',
ai21_model: 'j2-ultra',
+ togetherai_model: 'togethercomputer/GPT-NeoXT-Chat-Base-20B', // unsure here
windowai_model: '',
openrouter_model: openrouter_website_model,
openrouter_use_fallback: false,
@@ -261,6 +263,7 @@ const oai_settings = {
openai_model: 'gpt-3.5-turbo',
claude_model: 'claude-instant-v1',
ai21_model: 'j2-ultra',
+ togetherai_model: 'togethercomputer/GPT-NeoXT-Chat-Base-20B', // unsure here
windowai_model: '',
openrouter_model: openrouter_website_model,
openrouter_use_fallback: false,
@@ -1258,6 +1261,8 @@ function getChatCompletionModel() {
return oai_settings.openrouter_model !== openrouter_website_model ? oai_settings.openrouter_model : null;
case chat_completion_sources.AI21:
return oai_settings.ai21_model;
+ case chat_completion_sources.TOGETHERAI:
+ return oai_settings.togetherai_model;
default:
throw new Error(`Unknown chat completion source: ${oai_settings.chat_completion_source}`);
}
@@ -1445,6 +1450,7 @@ async function sendOpenAIRequest(type, messages, signal) {
const isAI21 = oai_settings.chat_completion_source == chat_completion_sources.AI21;
const isPalm = oai_settings.chat_completion_source == chat_completion_sources.PALM;
const isOAI = oai_settings.chat_completion_source == chat_completion_sources.OPENAI;
+ const isTogetherAI = oai_settings.chat_completion_source == chat_completion_sources.TOGETHERAI;
const isTextCompletion = (isOAI && textCompletionModels.includes(oai_settings.openai_model)) || (isOpenRouter && oai_settings.openrouter_force_instruct && power_user.instruct.enabled);
const isQuiet = type === 'quiet';
const isImpersonate = type === 'impersonate';
@@ -1552,7 +1558,7 @@ async function sendOpenAIRequest(type, messages, signal) {
generate_data['stop_tokens'] = [name1 + ':', oai_settings.new_chat_prompt, oai_settings.new_group_chat_prompt];
}
- if ((isOAI || isOpenRouter) && oai_settings.seed >= 0) {
+ if ((isOAI || isOpenRouter || isTogetherAI) && oai_settings.seed >= 0) {
generate_data['seed'] = oai_settings.seed;
}
@@ -2329,6 +2335,7 @@ function loadOpenAISettings(data, settings) {
oai_settings.assistant_prefill = settings.assistant_prefill ?? default_settings.assistant_prefill;
oai_settings.image_inlining = settings.image_inlining ?? default_settings.image_inlining;
oai_settings.bypass_status_check = settings.bypass_status_check ?? default_settings.bypass_status_check;
+ oai_settings.togetherai_model = settings.togetherai_model ?? default_settings.togetherai_model;
oai_settings.prompts = settings.prompts ?? default_settings.prompts;
oai_settings.prompt_order = settings.prompt_order ?? default_settings.prompt_order;
@@ -2360,6 +2367,8 @@ function loadOpenAISettings(data, settings) {
$(`#model_windowai_select option[value="${oai_settings.windowai_model}"`).attr('selected', true);
$('#model_ai21_select').val(oai_settings.ai21_model);
$(`#model_ai21_select option[value="${oai_settings.ai21_model}"`).attr('selected', true);
+ $('#model_togetherai_select').val(oai_settings.togetherai_model);
+ $(`#model_togetherai_select option[value="${oai_settings.togetherai_model}"`).attr('selected', true);
$('#openai_max_context').val(oai_settings.openai_max_context);
$('#openai_max_context_counter').val(`${oai_settings.openai_max_context}`);
$('#model_openrouter_select').val(oai_settings.openrouter_model);
@@ -2554,6 +2563,7 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) {
openrouter_group_models: settings.openrouter_group_models,
openrouter_sort_models: settings.openrouter_sort_models,
ai21_model: settings.ai21_model,
+ togetherai_model: settings.togetherai_model,
temperature: settings.temp_openai,
frequency_penalty: settings.freq_pen_openai,
presence_penalty: settings.pres_pen_openai,
@@ -2924,6 +2934,7 @@ function onSettingsPresetChange() {
openrouter_group_models: ['#openrouter_group_models', 'openrouter_group_models', false],
openrouter_sort_models: ['#openrouter_sort_models', 'openrouter_sort_models', false],
ai21_model: ['#model_ai21_select', 'ai21_model', false],
+ togetherai_model: ['#model_togetherai_select', 'togetherai_model', false],
openai_max_context: ['#openai_max_context', 'openai_max_context', false],
openai_max_tokens: ['#openai_max_tokens', 'openai_max_tokens', false],
wrap_in_quotes: ['#wrap_in_quotes', 'wrap_in_quotes', true],
@@ -3102,6 +3113,11 @@ async function onModelChange() {
oai_settings.ai21_model = value;
}
+ if ($(this).is('#model_togetherai_select')) {
+ console.log('TogetherAI model changed to', value);
+ oai_settings.togetherai_model = value;
+ }
+
if (oai_settings.chat_completion_source == chat_completion_sources.SCALE) {
if (oai_settings.max_context_unlocked) {
$('#openai_max_context').attr('max', unlocked_max);
@@ -3191,6 +3207,14 @@ async function onModelChange() {
}
}
+ // not sure if this is enough
+ if (oai_settings.chat_completion_source == chat_completion_sources.TOGETHERAI) {
+ $('#openai_max_context').attr('max', max_2k); // assuming togethercomputer/GPT-NeoXT-Chat-Base-20B
+ oai_settings.openai_max_context = Math.min(oai_settings.openai_max_context, Number($('#openai_max_context').attr('max')));
+ $('#openai_max_context').val(oai_settings.openai_max_context).trigger('input');
+
+ }
+
if (oai_settings.chat_completion_source == chat_completion_sources.OPENAI) {
$('#openai_max_context').attr('max', getMaxContextOpenAI(value));
oai_settings.openai_max_context = Math.min(oai_settings.openai_max_context, Number($('#openai_max_context').attr('max')));
@@ -3363,6 +3387,19 @@ async function onConnectButtonClick(e) {
}
}
+ if (oai_settings.chat_completion_source == chat_completion_sources.TOGETHERAI) {
+ const api_key_togetherai = String($('#api_key_togetherai').val()).trim();
+
+ if (api_key_togetherai.length) {
+ await writeSecret(SECRET_KEYS.TOGETHERAI, api_key_togetherai);
+ }
+
+ if (!secret_state[SECRET_KEYS.TOGETHERAI]) {
+ console.log('No secret key saved for TogetherAI');
+ return;
+ }
+ }
+
startStatusLoading();
saveSettingsDebounced();
await getStatusOpen();
@@ -3395,6 +3432,9 @@ function toggleChatCompletionForms() {
else if (oai_settings.chat_completion_source == chat_completion_sources.AI21) {
$('#model_ai21_select').trigger('change');
}
+ else if (oai_settings.chat_completion_source == chat_completion_sources.TOGETHERAI) {
+ $('#model_togetherai_select').trigger('change');
+ }
$('[data-source]').each(function () {
const validSources = $(this).data('source').split(',');
$(this).toggle(validSources.includes(oai_settings.chat_completion_source));
@@ -3792,6 +3832,7 @@ $(document).ready(async function () {
$('#openrouter_group_models').on('change', onOpenrouterModelSortChange);
$('#openrouter_sort_models').on('change', onOpenrouterModelSortChange);
$('#model_ai21_select').on('change', onModelChange);
+ $('#model_togetherai_select').on('change', onModelChange);
$('#settings_preset_openai').on('change', onSettingsPresetChange);
$('#new_oai_preset').on('click', onNewPresetClick);
$('#delete_oai_preset').on('click', onDeletePresetClick);
From eb2a85cfe00c5de2a02ad8afff970902d1046ff3 Mon Sep 17 00:00:00 2001
From: Fayiron <59962292+Fayiron@users.noreply.github.com>
Date: Sat, 16 Dec 2023 15:11:04 +0100
Subject: [PATCH 4/9] Add TogetherAI API key to secrets.js
---
public/scripts/secrets.js | 2 ++
1 file changed, 2 insertions(+)
diff --git a/public/scripts/secrets.js b/public/scripts/secrets.js
index 84279641d..798baa7b2 100644
--- a/public/scripts/secrets.js
+++ b/public/scripts/secrets.js
@@ -14,6 +14,7 @@ export const SECRET_KEYS = {
SCALE_COOKIE: 'scale_cookie',
PALM: 'api_key_palm',
SERPAPI: 'api_key_serpapi',
+ TOGETHERAI: 'api_key_togetherai',
};
const INPUT_MAP = {
@@ -29,6 +30,7 @@ const INPUT_MAP = {
[SECRET_KEYS.PALM]: '#api_key_palm',
[SECRET_KEYS.APHRODITE]: '#api_key_aphrodite',
[SECRET_KEYS.TABBY]: '#api_key_tabby',
+ [SECRET_KEYS.TOGETHERAI]: '#api_key_togetherai',
};
async function clearSecret() {
From 7b0ecd3e61880447c8aec41e7d34e9a5e0b52bec Mon Sep 17 00:00:00 2001
From: Fayiron <59962292+Fayiron@users.noreply.github.com>
Date: Sat, 16 Dec 2023 15:17:03 +0100
Subject: [PATCH 5/9] more stuff
---
src/constants.js | 1 +
src/endpoints/secrets.js | 1 +
2 files changed, 2 insertions(+)
diff --git a/src/constants.js b/src/constants.js
index 32ea6fad5..aa1e2a68d 100644
--- a/src/constants.js
+++ b/src/constants.js
@@ -140,6 +140,7 @@ const CHAT_COMPLETION_SOURCES = {
OPENROUTER: 'openrouter',
AI21: 'ai21',
PALM: 'palm',
+ TOGETHERAI: 'togetherai',
};
const UPLOADS_PATH = './uploads';
diff --git a/src/endpoints/secrets.js b/src/endpoints/secrets.js
index 54687cbeb..11b1bd340 100644
--- a/src/endpoints/secrets.js
+++ b/src/endpoints/secrets.js
@@ -25,6 +25,7 @@ const SECRET_KEYS = {
DEEPLX_URL: 'deeplx_url',
PALM: 'api_key_palm',
SERPAPI: 'api_key_serpapi',
+ TOGETHERAI: 'api_key_togetherai',
};
/**
From 80e82171c1e635ad035fab097c3d515afd267322 Mon Sep 17 00:00:00 2001
From: Fayiron <59962292+Fayiron@users.noreply.github.com>
Date: Sat, 16 Dec 2023 17:06:52 +0100
Subject: [PATCH 6/9] Add support for multiple OpenAI compatible endpoints
---
src/endpoints/togetherai.js | 4 ++++
src/endpoints/vectors.js | 3 ++-
src/openai-vectors.js | 43 +++++++++++++++++++++++++++----------
3 files changed, 38 insertions(+), 12 deletions(-)
create mode 100644 src/endpoints/togetherai.js
diff --git a/src/endpoints/togetherai.js b/src/endpoints/togetherai.js
new file mode 100644
index 000000000..309eff1f3
--- /dev/null
+++ b/src/endpoints/togetherai.js
@@ -0,0 +1,4 @@
+/**
+ * sends a request to the together AI api
+ *
+ */
\ No newline at end of file
diff --git a/src/endpoints/vectors.js b/src/endpoints/vectors.js
index 387803ccb..eb3efc88b 100644
--- a/src/endpoints/vectors.js
+++ b/src/endpoints/vectors.js
@@ -12,8 +12,9 @@ const { jsonParser } = require('../express-common');
*/
async function getVector(source, text) {
switch (source) {
+ case 'togetherai':
case 'openai':
- return require('../openai-vectors').getOpenAIVector(text);
+ return require('../openai-vectors').getOpenAIVector(text, source);
case 'transformers':
return require('../embedding').getTransformersVector(text);
case 'palm':
diff --git a/src/openai-vectors.js b/src/openai-vectors.js
index ecb245065..08bd15bf0 100644
--- a/src/openai-vectors.js
+++ b/src/openai-vectors.js
@@ -2,19 +2,40 @@ const fetch = require('node-fetch').default;
const { SECRET_KEYS, readSecret } = require('./endpoints/secrets');
/**
- * Gets the vector for the given text from OpenAI ada model
+ * Gets the vector for the given text from an OpenAI compatible endpoint.
* @param {string} text - The text to get the vector for
+ * @param {string} source - The source of the vector
* @returns {Promise
} - The vector for the text
*/
-async function getOpenAIVector(text) {
- const key = readSecret(SECRET_KEYS.OPENAI);
+async function getOpenAIVector(text, source) {
+
+ // dictionary of sources to endpoints with source as key and endpoint, model and secret key as value
+ const endpoints = {
+ 'togetherai': {
+ endpoint: 'https://api.togetherai.xyz/v1/embeddings', // is this correct?
+ model: 'togethercomputer/GPT-NeoXT-Chat-Base-20B',
+ secret: SECRET_KEYS.TOGETHERAI,
+ },
+ 'openai': {
+ endpoint: 'https://api.openai.com/v1/embeddings',
+ model: 'text-embedding-ada-002',
+ secret: SECRET_KEYS.OPENAI,
+ },
+ 'mistral': {
+ endpoint: 'https://api.mistral.ai/v1/embeddings',
+ model: 'mistral-embed',
+ secret: SECRET_KEYS.MISTRAL,
+ },
+ };
+
+ const key = readSecret(endpoints[source].secret);
if (!key) {
- console.log('No OpenAI key found');
- throw new Error('No OpenAI key found');
+ console.log('No %s key found.', source);
+ throw new Error('No ${source} key found.');
}
- const response = await fetch('https://api.openai.com/v1/embeddings', {
+ const response = await fetch(endpoints[source].endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -22,22 +43,22 @@ async function getOpenAIVector(text) {
},
body: JSON.stringify({
input: text,
- model: 'text-embedding-ada-002',
+ model: endpoints[source].model,
}),
});
if (!response.ok) {
const text = await response.text();
- console.log('OpenAI request failed', response.statusText, text);
- throw new Error('OpenAI request failed');
+ console.log('${source} request failed', response.statusText, text);
+ throw new Error('${source} request failed');
}
const data = await response.json();
const vector = data?.data[0]?.embedding;
if (!Array.isArray(vector)) {
- console.log('OpenAI response was not an array');
- throw new Error('OpenAI response was not an array');
+ console.log('${source} response was not an array');
+ throw new Error('${source} response was not an array');
}
return vector;
From 0a9f6783998e2eb0fbb5d5944f4d30f0b9e63dcf Mon Sep 17 00:00:00 2001
From: Fayiron <59962292+Fayiron@users.noreply.github.com>
Date: Sat, 16 Dec 2023 17:09:09 +0100
Subject: [PATCH 7/9] Remove togetherai.js
---
src/endpoints/togetherai.js | 4 ----
1 file changed, 4 deletions(-)
delete mode 100644 src/endpoints/togetherai.js
diff --git a/src/endpoints/togetherai.js b/src/endpoints/togetherai.js
deleted file mode 100644
index 309eff1f3..000000000
--- a/src/endpoints/togetherai.js
+++ /dev/null
@@ -1,4 +0,0 @@
-/**
- * sends a request to the together AI api
- *
- */
\ No newline at end of file
From b0d9f14534be0e6f9f70980c166206b77b69448a Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Sun, 17 Dec 2023 23:38:03 +0200
Subject: [PATCH 8/9] Re-add Together as a text completion source
---
default/settings.json | 1 -
public/img/togetherai.svg | 55 ++++++++
public/index.html | 47 +++----
public/script.js | 35 +++--
public/scripts/RossAscends-mods.js | 5 +-
public/scripts/extensions/vectors/index.js | 3 +-
.../scripts/extensions/vectors/settings.html | 1 -
public/scripts/mancer-settings.js | 64 ----------
public/scripts/openai.js | 44 +------
public/scripts/textgen-models.js | 120 ++++++++++++++++++
public/scripts/textgen-settings.js | 33 +++--
public/scripts/tokenizers.js | 5 +-
src/additional-headers.js | 11 ++
src/constants.js | 15 ++-
src/endpoints/backends/text-completions.js | 23 +++-
src/endpoints/vectors.js | 1 -
src/openai-vectors.js | 6 -
17 files changed, 300 insertions(+), 169 deletions(-)
create mode 100644 public/img/togetherai.svg
delete mode 100644 public/scripts/mancer-settings.js
create mode 100644 public/scripts/textgen-models.js
diff --git a/default/settings.json b/default/settings.json
index 1f3a3260d..3dd13670f 100644
--- a/default/settings.json
+++ b/default/settings.json
@@ -3,7 +3,6 @@
"username": "User",
"api_server": "http://127.0.0.1:5000/api",
"api_server_textgenerationwebui": "http://127.0.0.1:5000/api",
- "api_use_mancer_webui": false,
"preset_settings": "RecoveredRuins",
"user_avatar": "user-default.png",
"amount_gen": 250,
diff --git a/public/img/togetherai.svg b/public/img/togetherai.svg
new file mode 100644
index 000000000..e1e4c0407
--- /dev/null
+++ b/public/img/togetherai.svg
@@ -0,0 +1,55 @@
+
+
diff --git a/public/index.html b/public/index.html
index ea673f7c0..0bfa60876 100644
--- a/public/index.html
+++ b/public/index.html
@@ -69,7 +69,7 @@
-
+
@@ -509,7 +509,7 @@