mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-10 00:50:11 +01:00
Add 01.AI as a chat completion source
This commit is contained in:
parent
537cfbc027
commit
cf56bfb6a9
59
public/img/01ai.svg
Normal file
59
public/img/01ai.svg
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
width="363.44339"
|
||||
height="375.68854"
|
||||
viewBox="0 0 363.44339 375.68854"
|
||||
version="1.1"
|
||||
id="svg2"
|
||||
sodipodi:docname="Yi_logo_icon_dark.svg"
|
||||
inkscape:version="1.3 (0e150ed, 2023-07-21)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<defs
|
||||
id="defs2" />
|
||||
<sodipodi:namedview
|
||||
id="namedview2"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:zoom="1.1073359"
|
||||
inkscape:cx="192.35355"
|
||||
inkscape:cy="196.86889"
|
||||
inkscape:window-width="1512"
|
||||
inkscape:window-height="857"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="38"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg2" />
|
||||
<rect
|
||||
x="287.14771"
|
||||
y="224.04056"
|
||||
width="42.3862"
|
||||
height="151.64799"
|
||||
rx="21.1931"
|
||||
id="rect1" />
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="m 299.41969,17.362538 c -8.916,-7.5830004 -22.291,-6.503 -29.874,2.414 l -118.432,139.253002 c -3.056,3.593 -4.705,7.911 -5.001,12.281 -0.166,1.069 -0.252,2.164 -0.252,3.279 v 178.022 c 0,11.705 9.488,21.193 21.193,21.193 11.705,0 21.193,-9.488 21.193,-21.193 v -171.819 l 113.587,-133.556002 c 7.583,-8.916 6.502,-22.291 -2.414,-29.874 z"
|
||||
id="path1" />
|
||||
<rect
|
||||
x="-18.236605"
|
||||
y="8.6596518"
|
||||
width="42.3862"
|
||||
height="174.745"
|
||||
rx="21.1931"
|
||||
transform="rotate(-39.3441)"
|
||||
id="rect2" />
|
||||
<circle
|
||||
cx="337.54071"
|
||||
cy="163.28656"
|
||||
r="25.9027"
|
||||
id="circle2" />
|
||||
</svg>
|
After Width: | Height: | Size: 1.8 KiB |
@ -423,7 +423,7 @@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="range-block" data-source="openai,claude,windowai,openrouter,ai21,scale,makersuite,mistralai,custom,cohere,perplexity,groq">
|
||||
<div class="range-block" data-source="openai,claude,windowai,openrouter,ai21,scale,makersuite,mistralai,custom,cohere,perplexity,groq,01ai">
|
||||
<div class="range-block-title" data-i18n="Temperature">
|
||||
Temperature
|
||||
</div>
|
||||
@ -488,7 +488,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div data-newbie-hidden class="range-block" data-source="openai,claude,openrouter,ai21,scale,makersuite,mistralai,custom,cohere,perplexity,groq">
|
||||
<div data-newbie-hidden class="range-block" data-source="openai,claude,openrouter,ai21,scale,makersuite,mistralai,custom,cohere,perplexity,groq,01ai">
|
||||
<div class="range-block-title" data-i18n="Top P">
|
||||
Top P
|
||||
</div>
|
||||
@ -2360,6 +2360,7 @@
|
||||
<option value="custom" data-i18n="Custom (OpenAI-compatible)">Custom (OpenAI-compatible)</option>
|
||||
</optgroup>
|
||||
<optgroup>
|
||||
<option value="01ai">01.AI (Yi)</option>
|
||||
<option value="ai21">AI21</option>
|
||||
<option value="claude">Claude</option>
|
||||
<option value="cohere">Cohere</option>
|
||||
@ -2890,6 +2891,23 @@
|
||||
<option value="claude">Claude</option>
|
||||
</select>
|
||||
</form>
|
||||
<div id="01ai_form" data-source="01ai">
|
||||
<h4>
|
||||
<a data-i18n="01.AI API Key" href="https://platform.01.ai/" target="_blank" rel="noopener noreferrer">
|
||||
01.AI API Key
|
||||
</a>
|
||||
</h4>
|
||||
<div class="flex-container">
|
||||
<input id="api_key_01ai" name="api_key_01ai" class="text_pole flex1" maxlength="500" value="" type="text" autocomplete="off">
|
||||
<div title="Clear your API key" data-i18n="[title]Clear your API key" class="menu_button fa-solid fa-circle-xmark clear-api-key" data-key="api_key_01ai"></div>
|
||||
</div>
|
||||
<div data-for="api_key_01ai" class="neutral_warning" data-i18n="For privacy reasons, your API key will be hidden after you reload the page.">
|
||||
For privacy reasons, your API key will be hidden after you reload the page.
|
||||
</div>
|
||||
<h4 data-i18n="01.AI Model">01.AI Model</h4>
|
||||
<select id="model_01ai_select">
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex-container flex">
|
||||
<div id="api_button_openai" class="api_button menu_button menu_button_icon" type="submit" data-i18n="Connect">Connect</div>
|
||||
<div class="api_loading menu_button" data-i18n="Cancel">Cancel</div>
|
||||
|
@ -8289,6 +8289,11 @@ const CONNECT_API_MAP = {
|
||||
button: '#api_button_openai',
|
||||
source: chat_completion_sources.GROQ,
|
||||
},
|
||||
'01ai': {
|
||||
selected: 'openai',
|
||||
button: '#api_button_openai',
|
||||
source: chat_completion_sources.ZEROONEAI,
|
||||
},
|
||||
'infermaticai': {
|
||||
selected: 'textgenerationwebui',
|
||||
button: '#api_button_textgenerationwebui',
|
||||
|
@ -379,6 +379,7 @@ function RA_autoconnect(PrevApi) {
|
||||
|| (secret_state[SECRET_KEYS.COHERE] && oai_settings.chat_completion_source == chat_completion_sources.COHERE)
|
||||
|| (secret_state[SECRET_KEYS.PERPLEXITY] && oai_settings.chat_completion_source == chat_completion_sources.PERPLEXITY)
|
||||
|| (secret_state[SECRET_KEYS.GROQ] && oai_settings.chat_completion_source == chat_completion_sources.GROQ)
|
||||
|| (secret_state[SECRET_KEYS.ZEROONEAI] && oai_settings.chat_completion_source == chat_completion_sources.ZEROONEAI)
|
||||
|| (isValidUrl(oai_settings.custom_url) && oai_settings.chat_completion_source == chat_completion_sources.CUSTOM)
|
||||
) {
|
||||
$('#api_button_openai').trigger('click');
|
||||
@ -476,8 +477,8 @@ export function dragElement(elmnt) {
|
||||
}
|
||||
|
||||
const style = getComputedStyle(target);
|
||||
height = parseInt(style.height)
|
||||
width = parseInt(style.width)
|
||||
height = parseInt(style.height);
|
||||
width = parseInt(style.width);
|
||||
top = parseInt(style.top);
|
||||
left = parseInt(style.left);
|
||||
right = parseInt(style.right);
|
||||
|
@ -181,6 +181,7 @@ export const chat_completion_sources = {
|
||||
COHERE: 'cohere',
|
||||
PERPLEXITY: 'perplexity',
|
||||
GROQ: 'groq',
|
||||
ZEROONEAI: '01ai',
|
||||
};
|
||||
|
||||
const character_names_behavior = {
|
||||
@ -251,6 +252,7 @@ const default_settings = {
|
||||
cohere_model: 'command-r',
|
||||
perplexity_model: 'llama-3-70b-instruct',
|
||||
groq_model: 'llama3-70b-8192',
|
||||
zerooneai_model: 'yi-large',
|
||||
custom_model: '',
|
||||
custom_url: '',
|
||||
custom_include_body: '',
|
||||
@ -329,6 +331,7 @@ const oai_settings = {
|
||||
cohere_model: 'command-r',
|
||||
perplexity_model: 'llama-3-70b-instruct',
|
||||
groq_model: 'llama3-70b-8192',
|
||||
zerooneai_model: 'yi-large',
|
||||
custom_model: '',
|
||||
custom_url: '',
|
||||
custom_include_body: '',
|
||||
@ -1470,6 +1473,8 @@ function getChatCompletionModel() {
|
||||
return oai_settings.perplexity_model;
|
||||
case chat_completion_sources.GROQ:
|
||||
return oai_settings.groq_model;
|
||||
case chat_completion_sources.ZEROONEAI:
|
||||
return oai_settings.zerooneai_model;
|
||||
default:
|
||||
throw new Error(`Unknown chat completion source: ${oai_settings.chat_completion_source}`);
|
||||
}
|
||||
@ -1566,6 +1571,23 @@ function saveModelList(data) {
|
||||
$('#model_custom_select').val(model_list[0].id).trigger('change');
|
||||
}
|
||||
}
|
||||
|
||||
if (oai_settings.chat_completion_source == chat_completion_sources.ZEROONEAI) {
|
||||
$('#model_01ai_select').empty();
|
||||
model_list.forEach((model) => {
|
||||
$('#model_01ai_select').append(
|
||||
$('<option>', {
|
||||
value: model.id,
|
||||
text: model.id,
|
||||
}));
|
||||
});
|
||||
|
||||
if (!oai_settings.zerooneai_model && model_list.length > 0) {
|
||||
oai_settings.zerooneai_model = model_list[0].id;
|
||||
}
|
||||
|
||||
$('#model_01ai_select').val(oai_settings.zerooneai_model).trigger('change');
|
||||
}
|
||||
}
|
||||
|
||||
function appendOpenRouterOptions(model_list, groupModels = false, sort = false) {
|
||||
@ -1697,6 +1719,7 @@ async function sendOpenAIRequest(type, messages, signal) {
|
||||
const isCohere = oai_settings.chat_completion_source == chat_completion_sources.COHERE;
|
||||
const isPerplexity = oai_settings.chat_completion_source == chat_completion_sources.PERPLEXITY;
|
||||
const isGroq = oai_settings.chat_completion_source == chat_completion_sources.GROQ;
|
||||
const is01AI = oai_settings.chat_completion_source == chat_completion_sources.ZEROONEAI;
|
||||
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';
|
||||
@ -1863,6 +1886,17 @@ async function sendOpenAIRequest(type, messages, signal) {
|
||||
delete generate_data.n;
|
||||
}
|
||||
|
||||
// https://platform.01.ai/docs#request-body
|
||||
if (is01AI) {
|
||||
delete generate_data.logprobs;
|
||||
delete generate_data.logit_bias;
|
||||
delete generate_data.top_logprobs;
|
||||
delete generate_data.n;
|
||||
delete generate_data.frequency_penalty;
|
||||
delete generate_data.presence_penalty;
|
||||
delete generate_data.stop;
|
||||
}
|
||||
|
||||
if ((isOAI || isOpenRouter || isMistral || isCustom || isCohere) && oai_settings.seed >= 0) {
|
||||
generate_data['seed'] = oai_settings.seed;
|
||||
}
|
||||
@ -2912,6 +2946,7 @@ function loadOpenAISettings(data, settings) {
|
||||
oai_settings.cohere_model = settings.cohere_model ?? default_settings.cohere_model;
|
||||
oai_settings.perplexity_model = settings.perplexity_model ?? default_settings.perplexity_model;
|
||||
oai_settings.groq_model = settings.groq_model ?? default_settings.groq_model;
|
||||
oai_settings.zerooneai_model = settings.zerooneai_model ?? default_settings.zerooneai_model;
|
||||
oai_settings.custom_model = settings.custom_model ?? default_settings.custom_model;
|
||||
oai_settings.custom_url = settings.custom_url ?? default_settings.custom_url;
|
||||
oai_settings.custom_include_body = settings.custom_include_body ?? default_settings.custom_include_body;
|
||||
@ -2988,6 +3023,7 @@ function loadOpenAISettings(data, settings) {
|
||||
$(`#model_perplexity_select option[value="${oai_settings.perplexity_model}"`).attr('selected', true);
|
||||
$('#model_groq_select').val(oai_settings.groq_model);
|
||||
$(`#model_groq_select option[value="${oai_settings.groq_model}"`).attr('selected', true);
|
||||
$('#model_01ai_select').val(oai_settings.zerooneai_model);
|
||||
$('#custom_model_id').val(oai_settings.custom_model);
|
||||
$('#custom_api_url_text').val(oai_settings.custom_url);
|
||||
$('#openai_max_context').val(oai_settings.openai_max_context);
|
||||
@ -3240,6 +3276,7 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) {
|
||||
cohere_model: settings.cohere_model,
|
||||
perplexity_model: settings.perplexity_model,
|
||||
groq_model: settings.groq_model,
|
||||
zerooneai_model: settings.zerooneai_model,
|
||||
custom_model: settings.custom_model,
|
||||
custom_url: settings.custom_url,
|
||||
custom_include_body: settings.custom_include_body,
|
||||
@ -3640,6 +3677,7 @@ function onSettingsPresetChange() {
|
||||
cohere_model: ['#model_cohere_select', 'cohere_model', false],
|
||||
perplexity_model: ['#model_perplexity_select', 'perplexity_model', false],
|
||||
groq_model: ['#model_groq_select', 'groq_model', false],
|
||||
zerooneai_model: ['#model_01ai_select', 'zerooneai_model', false],
|
||||
custom_model: ['#custom_model_id', 'custom_model', false],
|
||||
custom_url: ['#custom_api_url_text', 'custom_url', false],
|
||||
custom_include_body: ['#custom_include_body', 'custom_include_body', false],
|
||||
@ -3882,6 +3920,11 @@ async function onModelChange() {
|
||||
oai_settings.groq_model = value;
|
||||
}
|
||||
|
||||
if ($(this).is('#model_01ai_select')) {
|
||||
console.log('01.AI model changed to', value);
|
||||
oai_settings.zerooneai_model = value;
|
||||
}
|
||||
|
||||
if (value && $(this).is('#model_custom_select')) {
|
||||
console.log('Custom model changed to', value);
|
||||
oai_settings.custom_model = value;
|
||||
@ -3997,7 +4040,9 @@ async function onModelChange() {
|
||||
}
|
||||
|
||||
if (oai_settings.chat_completion_source === chat_completion_sources.MISTRALAI) {
|
||||
if (oai_settings.mistralai_model.includes('mixtral-8x22b')) {
|
||||
if (oai_settings.max_context_unlocked) {
|
||||
$('#openai_max_context').attr('max', unlocked_max);
|
||||
} else if (oai_settings.mistralai_model.includes('mixtral-8x22b')) {
|
||||
$('#openai_max_context').attr('max', max_64k);
|
||||
} else {
|
||||
$('#openai_max_context').attr('max', max_32k);
|
||||
@ -4120,6 +4165,20 @@ async function onModelChange() {
|
||||
$('#temp_openai').attr('max', oai_max_temp).val(oai_settings.temp_openai).trigger('input');
|
||||
}
|
||||
|
||||
if (oai_settings.chat_completion_source === chat_completion_sources.ZEROONEAI) {
|
||||
if (oai_settings.max_context_unlocked) {
|
||||
$('#openai_max_context').attr('max', unlocked_max);
|
||||
} else {
|
||||
$('#openai_max_context').attr('max', max_16k);
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
oai_settings.temp_openai = Math.min(oai_max_temp, oai_settings.temp_openai);
|
||||
$('#temp_openai').attr('max', oai_max_temp).val(oai_settings.temp_openai).trigger('input');
|
||||
}
|
||||
|
||||
$('#openai_max_context_counter').attr('max', Number($('#openai_max_context').attr('max')));
|
||||
|
||||
saveSettingsDebounced();
|
||||
@ -4314,6 +4373,19 @@ async function onConnectButtonClick(e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (oai_settings.chat_completion_source == chat_completion_sources.ZEROONEAI) {
|
||||
const api_key_01ai = String($('#api_key_01ai').val()).trim();
|
||||
|
||||
if (api_key_01ai.length) {
|
||||
await writeSecret(SECRET_KEYS.ZEROONEAI, api_key_01ai);
|
||||
}
|
||||
|
||||
if (!secret_state[SECRET_KEYS.ZEROONEAI]) {
|
||||
console.log('No secret key saved for 01.AI');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
startStatusLoading();
|
||||
saveSettingsDebounced();
|
||||
await getStatusOpen();
|
||||
@ -4358,6 +4430,9 @@ function toggleChatCompletionForms() {
|
||||
else if (oai_settings.chat_completion_source == chat_completion_sources.GROQ) {
|
||||
$('#model_groq_select').trigger('change');
|
||||
}
|
||||
else if (oai_settings.chat_completion_source == chat_completion_sources.ZEROONEAI) {
|
||||
$('#model_01ai_select').trigger('change');
|
||||
}
|
||||
else if (oai_settings.chat_completion_source == chat_completion_sources.CUSTOM) {
|
||||
$('#model_custom_select').trigger('change');
|
||||
}
|
||||
@ -5062,6 +5137,7 @@ $(document).ready(async function () {
|
||||
$('#model_cohere_select').on('change', onModelChange);
|
||||
$('#model_perplexity_select').on('change', onModelChange);
|
||||
$('#model_groq_select').on('change', onModelChange);
|
||||
$('#model_01ai_select').on('change', onModelChange);
|
||||
$('#model_custom_select').on('change', onModelChange);
|
||||
$('#settings_preset_openai').on('change', onSettingsPresetChange);
|
||||
$('#new_oai_preset').on('click', onNewPresetClick);
|
||||
|
@ -28,6 +28,7 @@ export const SECRET_KEYS = {
|
||||
PERPLEXITY: 'api_key_perplexity',
|
||||
GROQ: 'api_key_groq',
|
||||
AZURE_TTS: 'api_key_azure_tts',
|
||||
ZEROONEAI: 'api_key_01ai',
|
||||
};
|
||||
|
||||
const INPUT_MAP = {
|
||||
@ -56,6 +57,7 @@ const INPUT_MAP = {
|
||||
[SECRET_KEYS.COHERE]: '#api_key_cohere',
|
||||
[SECRET_KEYS.PERPLEXITY]: '#api_key_perplexity',
|
||||
[SECRET_KEYS.GROQ]: '#api_key_groq',
|
||||
[SECRET_KEYS.ZEROONEAI]: '#api_key_01ai',
|
||||
};
|
||||
|
||||
async function clearSecret() {
|
||||
|
@ -2994,6 +2994,7 @@ function getModelOptions() {
|
||||
{ id: 'model_cohere_select', api: 'openai', type: chat_completion_sources.COHERE },
|
||||
{ id: 'model_perplexity_select', api: 'openai', type: chat_completion_sources.PERPLEXITY },
|
||||
{ id: 'model_groq_select', api: 'openai', type: chat_completion_sources.GROQ },
|
||||
{ id: 'model_01ai_select', api: 'openai', type: chat_completion_sources.ZEROONEAI },
|
||||
{ id: 'model_novel_select', api: 'novel', type: null },
|
||||
{ id: 'horde_model', api: 'koboldhorde', type: null },
|
||||
];
|
||||
|
@ -545,6 +545,10 @@ export function getTokenizerModel() {
|
||||
}
|
||||
}
|
||||
|
||||
if (oai_settings.chat_completion_source === chat_completion_sources.ZEROONEAI) {
|
||||
return yiTokenizer;
|
||||
}
|
||||
|
||||
// Default to Turbo 3.5
|
||||
return turboTokenizer;
|
||||
}
|
||||
|
@ -194,6 +194,7 @@ const CHAT_COMPLETION_SOURCES = {
|
||||
COHERE: 'cohere',
|
||||
PERPLEXITY: 'perplexity',
|
||||
GROQ: 'groq',
|
||||
ZEROONEAI: '01ai',
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -17,6 +17,7 @@ const API_COHERE = 'https://api.cohere.ai/v1';
|
||||
const API_PERPLEXITY = 'https://api.perplexity.ai';
|
||||
const API_GROQ = 'https://api.groq.com/openai/v1';
|
||||
const API_MAKERSUITE = 'https://generativelanguage.googleapis.com';
|
||||
const API_01AI = 'https://api.01.ai/v1';
|
||||
|
||||
/**
|
||||
* Applies a post-processing step to the generated messages.
|
||||
@ -670,6 +671,10 @@ router.post('/status', jsonParser, async function (request, response_getstatus_o
|
||||
api_url = API_COHERE;
|
||||
api_key_openai = readSecret(request.user.directories, SECRET_KEYS.COHERE);
|
||||
headers = {};
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.ZEROONEAI) {
|
||||
api_url = API_01AI;
|
||||
api_key_openai = readSecret(request.user.directories, SECRET_KEYS.ZEROONEAI);
|
||||
headers = {};
|
||||
} else {
|
||||
console.log('This chat completion source is not supported yet.');
|
||||
return response_getstatus_openai.status(400).send({ error: true });
|
||||
@ -931,6 +936,11 @@ router.post('/generate', jsonParser, function (request, response) {
|
||||
request.body.tool_choice = 'none';
|
||||
}
|
||||
}
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.ZEROONEAI) {
|
||||
apiUrl = API_01AI;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.ZEROONEAI);
|
||||
headers = {};
|
||||
bodyParams = {};
|
||||
} else {
|
||||
console.log('This chat completion source is not supported yet.');
|
||||
return response.status(400).send({ error: true });
|
||||
|
@ -40,6 +40,7 @@ const SECRET_KEYS = {
|
||||
PERPLEXITY: 'api_key_perplexity',
|
||||
GROQ: 'api_key_groq',
|
||||
AZURE_TTS: 'api_key_azure_tts',
|
||||
ZEROONEAI: 'api_key_01ai',
|
||||
};
|
||||
|
||||
// These are the keys that are safe to expose, even if allowKeysExposure is false
|
||||
|
Loading…
x
Reference in New Issue
Block a user