Skip to content

Commit 5c1e44e

Browse files
authored
feat(OpenAIClient): Add HttpsProxyAgent to initializeLLM (danny-avila#1119)
* feat(OpenAIClient): Add HttpsProxyAgent to initializeLLM * chore: fix linting error in ModelService
1 parent 7b30ab3 commit 5c1e44e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

api/app/clients/OpenAIClient.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { encoding_for_model: encodingForModel, get_encoding: getEncoding } = require('tiktoken');
2+
const { HttpsProxyAgent } = require('https-proxy-agent');
23
const ChatGPTClient = require('./ChatGPTClient');
34
const BaseClient = require('./BaseClient');
45
const { getModelMaxTokens, genAzureChatCompletion } = require('../../utils');
@@ -461,6 +462,11 @@ If your reverse proxy is compatible to OpenAI specs in every other way, it may s
461462
};
462463
}
463464

465+
if (this.options.proxy) {
466+
configOptions.httpAgent = new HttpsProxyAgent(this.options.proxy);
467+
configOptions.httpsAgent = new HttpsProxyAgent(this.options.proxy);
468+
}
469+
464470
const { req, res, debug } = this.options;
465471
const runManager = new RunManager({ req, res, debug, abortController: this.abortController });
466472
this.runManager = runManager;

api/server/services/ModelService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const fetchOpenAIModels = async (opts = { azure: false, plugins: false }, _model
2929

3030
if (OPENROUTER_API_KEY) {
3131
reverseProxyUrl = 'https://openrouter.ai/api/v1';
32-
apiKey = OPENROUTER_API_KEY
32+
apiKey = OPENROUTER_API_KEY;
3333
}
3434

3535
if (reverseProxyUrl) {

0 commit comments

Comments
 (0)