Added proxy support to ChatCompletionService
| @@ -43,10 +43,12 @@ import EventSourceStream from './sse-stream.js'; | ||
| 43 | 43 | * @property {boolean?} [stream=false] - Whether to stream the response |
| 44 | 44 | * @property {ChatCompletionMessage[]} messages - Array of chat messages |
| 45 | 45 | * @property {string} [model] - Optional model name to use for completion |
| 46 | 46 | * @property {string} chat_completion_source - Source provider for chat completion |
| 47 | 47 | * @property {number} max_tokens - Maximum number of tokens to generate |
| 48 | 48 | * @property {number} [temperature] - Optional temperature parameter for response randomness |
| 49 | 49 | * @property {string} [custom_url] - Optional custom URL for chat completion |
| 50 | + * @property {string} [reverse_proxy] - Optional reverse proxy URL | |
| 51 | + * @property {string} [proxy_password] - Optional proxy password | |
| 50 | 52 | */ |
| 51 | 53 | |
| 52 | 54 | /** @typedef {Record<string, any> & ChatCompletionPayloadBase} ChatCompletionPayload */ |
| @@ -387,7 +389,7 @@ export class ChatCompletionService { | ||
| 387 | 389 | * @param {ChatCompletionPayload} custom |
| 388 | 390 | * @returns {ChatCompletionPayload} |
| 389 | 391 | */ |
| 390 | 392 | static createRequestData({ stream = false, messages, model, chat_completion_source, max_tokens, temperature, custom_url, reverse_proxy, proxy_password, ...props }) { |
| 391 | 393 | const payload = { |
| 392 | 394 | ...props, |
| 393 | 395 | stream, |
| @@ -397,6 +399,8 @@ export class ChatCompletionService { | ||
| 397 | 399 | max_tokens, |
| 398 | 400 | temperature, |
| 399 | 401 | custom_url, |
| 402 | + reverse_proxy, | |
| 403 | + proxy_password, | |
| 400 | 404 | }; |
| 401 | 405 | |
| 402 | 406 | // Remove undefined values to avoid API errors |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | import { CONNECT_API_MAP, getRequestHeaders } from '../../script.js'; |
| 2 | 2 | import { extension_settings, openThirdPartyExtensionMenu } from '../extensions.js'; |
| 3 | 3 | import { t } from '../i18n.js'; |
| 4 | 4 | import { oai_settings, proxies } from '../openai.js'; |
| 5 | 5 | import { SECRET_KEYS, secret_state } from '../secrets.js'; |
| 6 | 6 | import { textgen_types, textgenerationwebui_settings } from '../textgen-settings.js'; |
| 7 | 7 | import { getTokenCountAsync } from '../tokenizers.js'; |
| @@ -326,6 +326,8 @@ export class ConnectionManagerRequestService { | ||
| 326 | 326 | throw new Error(`API type ${selectedApiMap.selected} does not support chat completions`); |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | + const proxyPreset = proxies.find((p) => p.name === profile.proxy); | |
| 330 | + | |
| 329 | 331 | const messages = Array.isArray(prompt) ? prompt : [{ role: 'user', content: prompt }]; |
| 330 | 332 | return await context.ChatCompletionService.processRequest({ |
| 331 | 333 | stream, |
| @@ -334,6 +336,8 @@ export class ConnectionManagerRequestService { | ||
| 334 | 336 | model: profile.model, |
| 335 | 337 | chat_completion_source: selectedApiMap.source, |
| 336 | 338 | custom_url: profile['api-url'], |
| 339 | + reverse_proxy: proxyPreset?.url, | |
| 340 | + proxy_password: proxyPreset?.password, | |
| 337 | 341 | }, { |
| 338 | 342 | presetName: includePreset ? profile.preset : undefined, |
| 339 | 343 | }, extractData, signal); |