Generic generate methods (#3566) * sendOpenAIRequest/getTextGenGenerationData methods are improved, now it can use custom API, instead of active ones * Added missing model param * Removed unnecessary variable * active_oai_settings -> settings * settings -> textgenerationwebui_settings * Better presetToSettings names, simpler settings name in getTextGenGenerationData, * Removed unused jailbreak_system * Reverted most core changes, new custom-request.js file * Forced stream to false, removed duplicate method, exported settingsToUpdate * Rewrite typedefs to define props one by one * Added extractData param for simplicity * Fixed typehints * Fixed typehints (again) --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
Signed| @@ -28,7 +28,6 @@ | ||
| 28 | 28 | "wrap_in_quotes": false, |
| 29 | 29 | "names_behavior": 0, |
| 30 | 30 | "send_if_empty": "", |
| 31 | - "jailbreak_system": false, | |
| 32 | 31 | "impersonation_prompt": "[Write your next reply from the point of view of {{user}}, using the chat history so far as a guideline for the writing style of {{user}}. Don't write as {{char}} or system. Don't describe actions of {{char}}.]", |
| 33 | 32 | "new_chat_prompt": "[Start a new Chat]", |
| 34 | 33 | "new_group_chat_prompt": "[Start a new group chat. Group members: {{group}}]", |
| @@ -626,7 +626,6 @@ | ||
| 626 | 626 | "ai21_model": "jamba-1.5-large", |
| 627 | 627 | "windowai_model": "", |
| 628 | 628 | "openrouter_model": "OR_Website", |
| 629 | - "jailbreak_system": true, | |
| 630 | 629 | "reverse_proxy": "", |
| 631 | 630 | "chat_completion_source": "openai", |
| 632 | 631 | "max_context_unlocked": false, |
| @@ -5647,7 +5647,7 @@ export async function sendStreamingRequest(type, data) { | ||
| 5647 | 5647 | * @returns {string} Generation URL |
| 5648 | 5648 | * @throws {Error} If the API is unknown |
| 5649 | 5649 | */ |
| 5650 | 5650 | export function getGenerateUrl(api) { |
| 5651 | 5651 | switch (api) { |
| 5652 | 5652 | case 'kobold': |
| 5653 | 5653 | return '/api/backends/kobold/generate'; |
| @@ -0,0 +1,189 @@ | ||
| 1 | +import { getPresetManager } from './preset-manager.js'; | |
| 2 | +import { extractMessageFromData, getGenerateUrl, getRequestHeaders } from '../script.js'; | |
| 3 | +import { getTextGenServer } from './textgen-settings.js'; | |
| 4 | + | |
| 5 | +// #region Type Definitions | |
| 6 | +/** | |
| 7 | + * @typedef {Object} TextCompletionRequestBase | |
| 8 | + * @property {string} prompt - The text prompt for completion | |
| 9 | + * @property {number} max_tokens - Maximum number of tokens to generate | |
| 10 | + * @property {string} [model] - Optional model name | |
| 11 | + * @property {string} api_type - Type of API to use | |
| 12 | + * @property {string} [api_server] - Optional API server URL | |
| 13 | + * @property {number} [temperature] - Optional temperature parameter | |
| 14 | + */ | |
| 15 | + | |
| 16 | +/** @typedef {Record<string, any> & TextCompletionRequestBase} TextCompletionRequest */ | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * @typedef {Object} TextCompletionPayloadBase | |
| 20 | + * @property {string} prompt - The text prompt for completion | |
| 21 | + * @property {number} max_tokens - Maximum number of tokens to generate | |
| 22 | + * @property {number} max_new_tokens - Alias for max_tokens | |
| 23 | + * @property {string} [model] - Optional model name | |
| 24 | + * @property {string} api_type - Type of API to use | |
| 25 | + * @property {string} api_server - API server URL | |
| 26 | + * @property {number} [temperature] - Optional temperature parameter | |
| 27 | + */ | |
| 28 | + | |
| 29 | +/** @typedef {Record<string, any> & TextCompletionPayloadBase} TextCompletionPayload */ | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * @typedef {Object} ChatCompletionMessage | |
| 33 | + * @property {string} role - The role of the message author (e.g., "user", "assistant", "system") | |
| 34 | + * @property {string} content - The content of the message | |
| 35 | + */ | |
| 36 | + | |
| 37 | +/** | |
| 38 | + * @typedef {Object} ChatCompletionPayloadBase | |
| 39 | + * @property {ChatCompletionMessage[]} messages - Array of chat messages | |
| 40 | + * @property {string} [model] - Optional model name to use for completion | |
| 41 | + * @property {string} chat_completion_source - Source provider for chat completion | |
| 42 | + * @property {number} max_tokens - Maximum number of tokens to generate | |
| 43 | + * @property {number} [temperature] - Optional temperature parameter for response randomness | |
| 44 | + */ | |
| 45 | + | |
| 46 | +/** @typedef {Record<string, any> & ChatCompletionPayloadBase} ChatCompletionPayload */ | |
| 47 | +// #endregion | |
| 48 | + | |
| 49 | +/** | |
| 50 | + * Creates & sends a text completion request. Streaming is not supported. | |
| 51 | + */ | |
| 52 | +export class TextCompletionService { | |
| 53 | + static TYPE = 'textgenerationwebui'; | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * @param {TextCompletionRequest} custom | |
| 57 | + * @returns {TextCompletionPayload} | |
| 58 | + */ | |
| 59 | + static createRequestData({ prompt, max_tokens, model, api_type, api_server, temperature, ...props }) { | |
| 60 | + return { | |
| 61 | + ...props, | |
| 62 | + prompt, | |
| 63 | + max_tokens, | |
| 64 | + max_new_tokens: max_tokens, | |
| 65 | + model, | |
| 66 | + api_type, | |
| 67 | + api_server: api_server ?? getTextGenServer(api_type), | |
| 68 | + temperature, | |
| 69 | + stream: false, | |
| 70 | + }; | |
| 71 | + } | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * Sends a text completion request to the specified server | |
| 75 | + * @param {TextCompletionPayload} data Request data | |
| 76 | + * @param {boolean?} extractData Extract message from the response. Default true | |
| 77 | + * @returns {Promise<string | any>} Extracted data or the raw response | |
| 78 | + * @throws {Error} | |
| 79 | + */ | |
| 80 | + static async sendRequest(data, extractData = true) { | |
| 81 | + const response = await fetch(getGenerateUrl(this.TYPE), { | |
| 82 | + method: 'POST', | |
| 83 | + headers: getRequestHeaders(), | |
| 84 | + cache: 'no-cache', | |
| 85 | + body: JSON.stringify(data), | |
| 86 | + signal: new AbortController().signal, | |
| 87 | + }); | |
| 88 | + | |
| 89 | + if (!response.ok) { | |
| 90 | + throw await response.json(); | |
| 91 | + } | |
| 92 | + | |
| 93 | + const json = await response.json(); | |
| 94 | + return extractData ? extractMessageFromData(json, this.TYPE) : json; | |
| 95 | + } | |
| 96 | + | |
| 97 | + /** | |
| 98 | + * @param {string} presetName | |
| 99 | + * @param {TextCompletionRequest} custom | |
| 100 | + * @param {boolean?} extractData Extract message from the response. Default true | |
| 101 | + * @returns {Promise<string | any>} Extracted data or the raw response | |
| 102 | + * @throws {Error} | |
| 103 | + */ | |
| 104 | + static async sendRequestWithPreset(presetName, custom, extractData = true) { | |
| 105 | + const presetManager = getPresetManager(this.TYPE); | |
| 106 | + if (!presetManager) { | |
| 107 | + throw new Error('Preset manager not found'); | |
| 108 | + } | |
| 109 | + | |
| 110 | + const preset = presetManager.getCompletionPresetByName(presetName); | |
| 111 | + if (!preset) { | |
| 112 | + throw new Error('Preset not found'); | |
| 113 | + } | |
| 114 | + | |
| 115 | + const data = this.createRequestData({ ...preset, ...custom }); | |
| 116 | + | |
| 117 | + return await this.sendRequest(data, extractData); | |
| 118 | + } | |
| 119 | +} | |
| 120 | + | |
| 121 | +/** | |
| 122 | + * Creates & sends a chat completion request. Streaming is not supported. | |
| 123 | + */ | |
| 124 | +export class ChatCompletionService { | |
| 125 | + static TYPE = 'openai'; | |
| 126 | + | |
| 127 | + /** | |
| 128 | + * @param {ChatCompletionPayload} custom | |
| 129 | + * @returns {ChatCompletionPayload} | |
| 130 | + */ | |
| 131 | + static createRequestData({ messages, model, chat_completion_source, max_tokens, temperature, ...props }) { | |
| 132 | + return { | |
| 133 | + ...props, | |
| 134 | + messages, | |
| 135 | + model, | |
| 136 | + chat_completion_source, | |
| 137 | + max_tokens, | |
| 138 | + temperature, | |
| 139 | + stream: false, | |
| 140 | + }; | |
| 141 | + } | |
| 142 | + | |
| 143 | + /** | |
| 144 | + * Sends a chat completion request | |
| 145 | + * @param {ChatCompletionPayload} data Request data | |
| 146 | + * @param {boolean?} extractData Extract message from the response. Default true | |
| 147 | + * @returns {Promise<string | any>} Extracted data or the raw response | |
| 148 | + * @throws {Error} | |
| 149 | + */ | |
| 150 | + static async sendRequest(data, extractData = true) { | |
| 151 | + const response = await fetch('/api/backends/chat-completions/generate', { | |
| 152 | + method: 'POST', | |
| 153 | + headers: getRequestHeaders(), | |
| 154 | + cache: 'no-cache', | |
| 155 | + body: JSON.stringify(data), | |
| 156 | + signal: new AbortController().signal, | |
| 157 | + }); | |
| 158 | + | |
| 159 | + if (!response.ok) { | |
| 160 | + throw await response.json(); | |
| 161 | + } | |
| 162 | + | |
| 163 | + const json = await response.json(); | |
| 164 | + return extractData ? extractMessageFromData(json, this.TYPE) : json; | |
| 165 | + } | |
| 166 | + | |
| 167 | + /** | |
| 168 | + * @param {string} presetName | |
| 169 | + * @param {ChatCompletionPayload} custom | |
| 170 | + * @param {boolean} extractData Extract message from the response. Default true | |
| 171 | + * @returns {Promise<string | any>} Extracted data or the raw response | |
| 172 | + * @throws {Error} | |
| 173 | + */ | |
| 174 | + static async sendRequestWithPreset(presetName, custom, extractData = true) { | |
| 175 | + const presetManager = getPresetManager(this.TYPE); | |
| 176 | + if (!presetManager) { | |
| 177 | + throw new Error('Preset manager not found'); | |
| 178 | + } | |
| 179 | + | |
| 180 | + const preset = presetManager.getCompletionPresetByName(presetName); | |
| 181 | + if (!preset) { | |
| 182 | + throw new Error('Preset not found'); | |
| 183 | + } | |
| 184 | + | |
| 185 | + const data = this.createRequestData({ ...preset, ...custom }); | |
| 186 | + | |
| 187 | + return await this.sendRequest(data, extractData); | |
| 188 | + } | |
| 189 | +} | |
| @@ -224,6 +224,87 @@ const sensitiveFields = [ | ||
| 224 | 224 | 'custom_include_headers', |
| 225 | 225 | ]; |
| 226 | 226 | |
| 227 | +/** | |
| 228 | + * preset_name -> [selector, setting_name, is_checkbox] | |
| 229 | + * @type {Record<string, [string, string, boolean]>} | |
| 230 | + */ | |
| 231 | +export const settingsToUpdate = { | |
| 232 | + chat_completion_source: ['#chat_completion_source', 'chat_completion_source', false], | |
| 233 | + temperature: ['#temp_openai', 'temp_openai', false], | |
| 234 | + frequency_penalty: ['#freq_pen_openai', 'freq_pen_openai', false], | |
| 235 | + presence_penalty: ['#pres_pen_openai', 'pres_pen_openai', false], | |
| 236 | + top_p: ['#top_p_openai', 'top_p_openai', false], | |
| 237 | + top_k: ['#top_k_openai', 'top_k_openai', false], | |
| 238 | + top_a: ['#top_a_openai', 'top_a_openai', false], | |
| 239 | + min_p: ['#min_p_openai', 'min_p_openai', false], | |
| 240 | + repetition_penalty: ['#repetition_penalty_openai', 'repetition_penalty_openai', false], | |
| 241 | + max_context_unlocked: ['#oai_max_context_unlocked', 'max_context_unlocked', true], | |
| 242 | + openai_model: ['#model_openai_select', 'openai_model', false], | |
| 243 | + claude_model: ['#model_claude_select', 'claude_model', false], | |
| 244 | + windowai_model: ['#model_windowai_select', 'windowai_model', false], | |
| 245 | + openrouter_model: ['#model_openrouter_select', 'openrouter_model', false], | |
| 246 | + openrouter_use_fallback: ['#openrouter_use_fallback', 'openrouter_use_fallback', true], | |
| 247 | + openrouter_group_models: ['#openrouter_group_models', 'openrouter_group_models', false], | |
| 248 | + openrouter_sort_models: ['#openrouter_sort_models', 'openrouter_sort_models', false], | |
| 249 | + openrouter_providers: ['#openrouter_providers_chat', 'openrouter_providers', false], | |
| 250 | + openrouter_allow_fallbacks: ['#openrouter_allow_fallbacks', 'openrouter_allow_fallbacks', true], | |
| 251 | + openrouter_middleout: ['#openrouter_middleout', 'openrouter_middleout', false], | |
| 252 | + ai21_model: ['#model_ai21_select', 'ai21_model', false], | |
| 253 | + mistralai_model: ['#model_mistralai_select', 'mistralai_model', false], | |
| 254 | + cohere_model: ['#model_cohere_select', 'cohere_model', false], | |
| 255 | + perplexity_model: ['#model_perplexity_select', 'perplexity_model', false], | |
| 256 | + groq_model: ['#model_groq_select', 'groq_model', false], | |
| 257 | + nanogpt_model: ['#model_nanogpt_select', 'nanogpt_model', false], | |
| 258 | + deepseek_model: ['#model_deepseek_select', 'deepseek_model', false], | |
| 259 | + zerooneai_model: ['#model_01ai_select', 'zerooneai_model', false], | |
| 260 | + blockentropy_model: ['#model_blockentropy_select', 'blockentropy_model', false], | |
| 261 | + custom_model: ['#custom_model_id', 'custom_model', false], | |
| 262 | + custom_url: ['#custom_api_url_text', 'custom_url', false], | |
| 263 | + custom_include_body: ['#custom_include_body', 'custom_include_body', false], | |
| 264 | + custom_exclude_body: ['#custom_exclude_body', 'custom_exclude_body', false], | |
| 265 | + custom_include_headers: ['#custom_include_headers', 'custom_include_headers', false], | |
| 266 | + custom_prompt_post_processing: ['#custom_prompt_post_processing', 'custom_prompt_post_processing', false], | |
| 267 | + google_model: ['#model_google_select', 'google_model', false], | |
| 268 | + openai_max_context: ['#openai_max_context', 'openai_max_context', false], | |
| 269 | + openai_max_tokens: ['#openai_max_tokens', 'openai_max_tokens', false], | |
| 270 | + wrap_in_quotes: ['#wrap_in_quotes', 'wrap_in_quotes', true], | |
| 271 | + names_behavior: ['#names_behavior', 'names_behavior', false], | |
| 272 | + send_if_empty: ['#send_if_empty_textarea', 'send_if_empty', false], | |
| 273 | + impersonation_prompt: ['#impersonation_prompt_textarea', 'impersonation_prompt', false], | |
| 274 | + new_chat_prompt: ['#newchat_prompt_textarea', 'new_chat_prompt', false], | |
| 275 | + new_group_chat_prompt: ['#newgroupchat_prompt_textarea', 'new_group_chat_prompt', false], | |
| 276 | + new_example_chat_prompt: ['#newexamplechat_prompt_textarea', 'new_example_chat_prompt', false], | |
| 277 | + continue_nudge_prompt: ['#continue_nudge_prompt_textarea', 'continue_nudge_prompt', false], | |
| 278 | + bias_preset_selected: ['#openai_logit_bias_preset', 'bias_preset_selected', false], | |
| 279 | + reverse_proxy: ['#openai_reverse_proxy', 'reverse_proxy', false], | |
| 280 | + wi_format: ['#wi_format_textarea', 'wi_format', false], | |
| 281 | + scenario_format: ['#scenario_format_textarea', 'scenario_format', false], | |
| 282 | + personality_format: ['#personality_format_textarea', 'personality_format', false], | |
| 283 | + group_nudge_prompt: ['#group_nudge_prompt_textarea', 'group_nudge_prompt', false], | |
| 284 | + stream_openai: ['#stream_toggle', 'stream_openai', true], | |
| 285 | + prompts: ['', 'prompts', false], | |
| 286 | + prompt_order: ['', 'prompt_order', false], | |
| 287 | + api_url_scale: ['#api_url_scale', 'api_url_scale', false], | |
| 288 | + show_external_models: ['#openai_show_external_models', 'show_external_models', true], | |
| 289 | + proxy_password: ['#openai_proxy_password', 'proxy_password', false], | |
| 290 | + assistant_prefill: ['#claude_assistant_prefill', 'assistant_prefill', false], | |
| 291 | + assistant_impersonation: ['#claude_assistant_impersonation', 'assistant_impersonation', false], | |
| 292 | + claude_use_sysprompt: ['#claude_use_sysprompt', 'claude_use_sysprompt', true], | |
| 293 | + use_makersuite_sysprompt: ['#use_makersuite_sysprompt', 'use_makersuite_sysprompt', true], | |
| 294 | + use_alt_scale: ['#use_alt_scale', 'use_alt_scale', true], | |
| 295 | + squash_system_messages: ['#squash_system_messages', 'squash_system_messages', true], | |
| 296 | + image_inlining: ['#openai_image_inlining', 'image_inlining', true], | |
| 297 | + inline_image_quality: ['#openai_inline_image_quality', 'inline_image_quality', false], | |
| 298 | + continue_prefill: ['#continue_prefill', 'continue_prefill', true], | |
| 299 | + continue_postfix: ['#continue_postfix', 'continue_postfix', false], | |
| 300 | + function_calling: ['#openai_function_calling', 'function_calling', true], | |
| 301 | + show_thoughts: ['#openai_show_thoughts', 'show_thoughts', true], | |
| 302 | + reasoning_effort: ['#openai_reasoning_effort', 'reasoning_effort', false], | |
| 303 | + seed: ['#seed_openai', 'seed', false], | |
| 304 | + n: ['#n_openai', 'n', false], | |
| 305 | + bypass_status_check: ['#openai_bypass_status_check', 'bypass_status_check', true], | |
| 306 | +}; | |
| 307 | + | |
| 227 | 308 | const default_settings = { |
| 228 | 309 | preset_settings_openai: 'Default', |
| 229 | 310 | temp_openai: 1.0, |
| @@ -277,7 +358,6 @@ const default_settings = { | ||
| 277 | 358 | openrouter_providers: [], |
| 278 | 359 | openrouter_allow_fallbacks: true, |
| 279 | 360 | openrouter_middleout: openrouter_middleout_types.ON, |
| 280 | - jailbreak_system: false, | |
| 281 | 361 | reverse_proxy: '', |
| 282 | 362 | chat_completion_source: chat_completion_sources.OPENAI, |
| 283 | 363 | max_context_unlocked: false, |
| @@ -357,7 +437,6 @@ const oai_settings = { | ||
| 357 | 437 | openrouter_providers: [], |
| 358 | 438 | openrouter_allow_fallbacks: true, |
| 359 | 439 | openrouter_middleout: openrouter_middleout_types.ON, |
| 360 | - jailbreak_system: false, | |
| 361 | 440 | reverse_proxy: '', |
| 362 | 441 | chat_completion_source: chat_completion_sources.OPENAI, |
| 363 | 442 | max_context_unlocked: false, |
| @@ -3219,7 +3298,6 @@ function loadOpenAISettings(data, settings) { | ||
| 3219 | 3298 | $('#openai_max_tokens').val(oai_settings.openai_max_tokens); |
| 3220 | 3299 | |
| 3221 | 3300 | $('#wrap_in_quotes').prop('checked', oai_settings.wrap_in_quotes); |
| 3222 | - $('#jailbreak_system').prop('checked', oai_settings.jailbreak_system); | |
| 3223 | 3301 | $('#openai_show_external_models').prop('checked', oai_settings.show_external_models); |
| 3224 | 3302 | $('#openai_external_category').toggle(oai_settings.show_external_models); |
| 3225 | 3303 | $('#claude_use_sysprompt').prop('checked', oai_settings.claude_use_sysprompt); |
| @@ -3503,7 +3581,6 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) { | ||
| 3503 | 3581 | names_behavior: settings.names_behavior, |
| 3504 | 3582 | send_if_empty: settings.send_if_empty, |
| 3505 | 3583 | jailbreak_prompt: settings.jailbreak_prompt, |
| 3506 | - jailbreak_system: settings.jailbreak_system, | |
| 3507 | 3584 | impersonation_prompt: settings.impersonation_prompt, |
| 3508 | 3585 | new_chat_prompt: settings.new_chat_prompt, |
| 3509 | 3586 | new_group_chat_prompt: settings.new_group_chat_prompt, |
| @@ -3923,82 +4000,6 @@ async function onLogitBiasPresetDeleteClick() { | ||
| 3923 | 4000 | |
| 3924 | 4001 | // Load OpenAI preset settings |
| 3925 | 4002 | function onSettingsPresetChange() { |
| 3926 | - const settingsToUpdate = { | |
| 3927 | - chat_completion_source: ['#chat_completion_source', 'chat_completion_source', false], | |
| 3928 | - temperature: ['#temp_openai', 'temp_openai', false], | |
| 3929 | - frequency_penalty: ['#freq_pen_openai', 'freq_pen_openai', false], | |
| 3930 | - presence_penalty: ['#pres_pen_openai', 'pres_pen_openai', false], | |
| 3931 | - top_p: ['#top_p_openai', 'top_p_openai', false], | |
| 3932 | - top_k: ['#top_k_openai', 'top_k_openai', false], | |
| 3933 | - top_a: ['#top_a_openai', 'top_a_openai', false], | |
| 3934 | - min_p: ['#min_p_openai', 'min_p_openai', false], | |
| 3935 | - repetition_penalty: ['#repetition_penalty_openai', 'repetition_penalty_openai', false], | |
| 3936 | - max_context_unlocked: ['#oai_max_context_unlocked', 'max_context_unlocked', true], | |
| 3937 | - openai_model: ['#model_openai_select', 'openai_model', false], | |
| 3938 | - claude_model: ['#model_claude_select', 'claude_model', false], | |
| 3939 | - windowai_model: ['#model_windowai_select', 'windowai_model', false], | |
| 3940 | - openrouter_model: ['#model_openrouter_select', 'openrouter_model', false], | |
| 3941 | - openrouter_use_fallback: ['#openrouter_use_fallback', 'openrouter_use_fallback', true], | |
| 3942 | - openrouter_group_models: ['#openrouter_group_models', 'openrouter_group_models', false], | |
| 3943 | - openrouter_sort_models: ['#openrouter_sort_models', 'openrouter_sort_models', false], | |
| 3944 | - openrouter_providers: ['#openrouter_providers_chat', 'openrouter_providers', false], | |
| 3945 | - openrouter_allow_fallbacks: ['#openrouter_allow_fallbacks', 'openrouter_allow_fallbacks', true], | |
| 3946 | - openrouter_middleout: ['#openrouter_middleout', 'openrouter_middleout', false], | |
| 3947 | - ai21_model: ['#model_ai21_select', 'ai21_model', false], | |
| 3948 | - mistralai_model: ['#model_mistralai_select', 'mistralai_model', false], | |
| 3949 | - cohere_model: ['#model_cohere_select', 'cohere_model', false], | |
| 3950 | - perplexity_model: ['#model_perplexity_select', 'perplexity_model', false], | |
| 3951 | - groq_model: ['#model_groq_select', 'groq_model', false], | |
| 3952 | - nanogpt_model: ['#model_nanogpt_select', 'nanogpt_model', false], | |
| 3953 | - deepseek_model: ['#model_deepseek_select', 'deepseek_model', false], | |
| 3954 | - zerooneai_model: ['#model_01ai_select', 'zerooneai_model', false], | |
| 3955 | - blockentropy_model: ['#model_blockentropy_select', 'blockentropy_model', false], | |
| 3956 | - custom_model: ['#custom_model_id', 'custom_model', false], | |
| 3957 | - custom_url: ['#custom_api_url_text', 'custom_url', false], | |
| 3958 | - custom_include_body: ['#custom_include_body', 'custom_include_body', false], | |
| 3959 | - custom_exclude_body: ['#custom_exclude_body', 'custom_exclude_body', false], | |
| 3960 | - custom_include_headers: ['#custom_include_headers', 'custom_include_headers', false], | |
| 3961 | - custom_prompt_post_processing: ['#custom_prompt_post_processing', 'custom_prompt_post_processing', false], | |
| 3962 | - google_model: ['#model_google_select', 'google_model', false], | |
| 3963 | - openai_max_context: ['#openai_max_context', 'openai_max_context', false], | |
| 3964 | - openai_max_tokens: ['#openai_max_tokens', 'openai_max_tokens', false], | |
| 3965 | - wrap_in_quotes: ['#wrap_in_quotes', 'wrap_in_quotes', true], | |
| 3966 | - names_behavior: ['#names_behavior', 'names_behavior', false], | |
| 3967 | - send_if_empty: ['#send_if_empty_textarea', 'send_if_empty', false], | |
| 3968 | - impersonation_prompt: ['#impersonation_prompt_textarea', 'impersonation_prompt', false], | |
| 3969 | - new_chat_prompt: ['#newchat_prompt_textarea', 'new_chat_prompt', false], | |
| 3970 | - new_group_chat_prompt: ['#newgroupchat_prompt_textarea', 'new_group_chat_prompt', false], | |
| 3971 | - new_example_chat_prompt: ['#newexamplechat_prompt_textarea', 'new_example_chat_prompt', false], | |
| 3972 | - continue_nudge_prompt: ['#continue_nudge_prompt_textarea', 'continue_nudge_prompt', false], | |
| 3973 | - bias_preset_selected: ['#openai_logit_bias_preset', 'bias_preset_selected', false], | |
| 3974 | - reverse_proxy: ['#openai_reverse_proxy', 'reverse_proxy', false], | |
| 3975 | - wi_format: ['#wi_format_textarea', 'wi_format', false], | |
| 3976 | - scenario_format: ['#scenario_format_textarea', 'scenario_format', false], | |
| 3977 | - personality_format: ['#personality_format_textarea', 'personality_format', false], | |
| 3978 | - group_nudge_prompt: ['#group_nudge_prompt_textarea', 'group_nudge_prompt', false], | |
| 3979 | - stream_openai: ['#stream_toggle', 'stream_openai', true], | |
| 3980 | - prompts: ['', 'prompts', false], | |
| 3981 | - prompt_order: ['', 'prompt_order', false], | |
| 3982 | - api_url_scale: ['#api_url_scale', 'api_url_scale', false], | |
| 3983 | - show_external_models: ['#openai_show_external_models', 'show_external_models', true], | |
| 3984 | - proxy_password: ['#openai_proxy_password', 'proxy_password', false], | |
| 3985 | - assistant_prefill: ['#claude_assistant_prefill', 'assistant_prefill', false], | |
| 3986 | - assistant_impersonation: ['#claude_assistant_impersonation', 'assistant_impersonation', false], | |
| 3987 | - claude_use_sysprompt: ['#claude_use_sysprompt', 'claude_use_sysprompt', true], | |
| 3988 | - use_makersuite_sysprompt: ['#use_makersuite_sysprompt', 'use_makersuite_sysprompt', true], | |
| 3989 | - use_alt_scale: ['#use_alt_scale', 'use_alt_scale', true], | |
| 3990 | - squash_system_messages: ['#squash_system_messages', 'squash_system_messages', true], | |
| 3991 | - image_inlining: ['#openai_image_inlining', 'image_inlining', true], | |
| 3992 | - inline_image_quality: ['#openai_inline_image_quality', 'inline_image_quality', false], | |
| 3993 | - continue_prefill: ['#continue_prefill', 'continue_prefill', true], | |
| 3994 | - continue_postfix: ['#continue_postfix', 'continue_postfix', false], | |
| 3995 | - function_calling: ['#openai_function_calling', 'function_calling', true], | |
| 3996 | - show_thoughts: ['#openai_show_thoughts', 'show_thoughts', true], | |
| 3997 | - reasoning_effort: ['#openai_reasoning_effort', 'reasoning_effort', false], | |
| 3998 | - seed: ['#seed_openai', 'seed', false], | |
| 3999 | - n: ['#n_openai', 'n', false], | |
| 4000 | - }; | |
| 4001 | - | |
| 4002 | 4003 | const presetNameBefore = oai_settings.preset_settings_openai; |
| 4003 | 4004 | |
| 4004 | 4005 | const presetName = $('#settings_preset_openai').find(':selected').text(); |
| @@ -77,6 +77,7 @@ import { accountStorage } from './util/AccountStorage.js'; | ||
| 77 | 77 | import { timestampToMoment, uuidv4 } from './utils.js'; |
| 78 | 78 | import { getGlobalVariable, getLocalVariable, setGlobalVariable, setLocalVariable } from './variables.js'; |
| 79 | 79 | import { convertCharacterBook, loadWorldInfo, saveWorldInfo, updateWorldInfoList } from './world-info.js'; |
| 80 | +import { ChatCompletionService, TextCompletionService } from './custom-request.js'; | |
| 80 | 81 | |
| 81 | 82 | export function getContext() { |
| 82 | 83 | return { |
| @@ -207,6 +208,8 @@ export function getContext() { | ||
| 207 | 208 | getChatCompletionModel, |
| 208 | 209 | printMessages, |
| 209 | 210 | clearChat, |
| 211 | + ChatCompletionService, | |
| 212 | + TextCompletionService, | |
| 210 | 213 | }; |
| 211 | 214 | } |
| 212 | 215 | |
| @@ -108,12 +108,12 @@ const BIAS_KEY = '#textgenerationwebui_api-settings'; | ||
| 108 | 108 | // (7 days later) The future has come. |
| 109 | 109 | const MANCER_SERVER_KEY = 'mancer_server'; |
| 110 | 110 | const MANCER_SERVER_DEFAULT = 'https://neuro.mancer.tech'; |
| 111 | 111 | export let MANCER_SERVER = localStorage.getItem(MANCER_SERVER_KEY) ?? MANCER_SERVER_DEFAULT; |
| 112 | 112 | export let TOGETHERAI_SERVER = 'https://api.together.xyz'; |
| 113 | 113 | export let INFERMATICAI_SERVER = 'https://api.totalgpt.ai'; |
| 114 | 114 | export let DREAMGEN_SERVER = 'https://dreamgen.com'; |
| 115 | 115 | export let OPENROUTER_SERVER = 'https://openrouter.ai/api'; |
| 116 | 116 | export let FEATHERLESS_SERVER = 'https://api.featherless.ai/v1'; |
| 117 | 117 | |
| 118 | 118 | export const SERVER_INPUTS = { |
| 119 | 119 | [textgen_types.OOBA]: '#textgenerationwebui_api_url_text', |