Merge pull request #1800 from EX3-0/patch-1

Update openai.js added /proxy command.
This commit is contained in:
Cohee 2024-02-08 00:05:53 +02:00 committed by GitHub
commit d7f86a7f6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 0 deletions

View File

@ -31,6 +31,7 @@ import {
this_chid,
} from '../script.js';
import { groups, selected_group } from './group-chats.js';
import { registerSlashCommand } from './slash-commands.js';
import {
chatCompletionDefaultPrompts,
@ -3934,6 +3935,28 @@ $('#delete_proxy').on('click', async function () {
}
});
function runProxyCallback(_, value) {
if (!value) {
toastr.warning('Proxy preset name is required');
return '';
}
const proxyNames = proxies.map(preset => preset.name);
const fuse = new Fuse(proxyNames);
const result = fuse.search(value);
if (result.length === 0) {
toastr.warning(`Proxy preset "${value}" not found`);
return '';
}
const foundName = result[0].item;
$('#openai_proxy_preset').val(foundName).trigger('change');
return foundName;
}
registerSlashCommand('proxy', runProxyCallback, [], '<span class="monospace">(name)</span> sets a proxy preset by name');
$(document).ready(async function () {
$('#test_api_button').on('click', testApiConnection);