From 7971f89cd303401432bf6cd7d46ca52001bdb4ca Mon Sep 17 00:00:00 2001 From: Pavel Karasov Date: Thu, 14 Mar 2024 10:09:03 +0100 Subject: [PATCH] Added proxy support if the variable is defined. --- Open AI Code Review/src/main.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Open AI Code Review/src/main.ts b/Open AI Code Review/src/main.ts index 2d4318e..a5fe1f7 100644 --- a/Open AI Code Review/src/main.ts +++ b/Open AI Code Review/src/main.ts @@ -3,6 +3,7 @@ import { OpenAI } from 'openai'; import { ChatGPT } from './chatgpt'; import { Repository } from './repository'; import { PullRequest } from './pullrequest'; +import { HttpsProxyAgent } from 'https-proxy-agent'; export class Main { private static _chatGpt: ChatGPT; @@ -25,7 +26,14 @@ export class Main { const filesToExclude = tl.getInput('file_excludes', false); const additionalPrompts = tl.getInput('additional_prompts', false)?.split(',') - this._chatGpt = new ChatGPT(new OpenAI({ apiKey: apiKey }), tl.getBoolInput('bugs', true), tl.getBoolInput('performance', true), tl.getBoolInput('best_practices', true), additionalPrompts); + let proxyUrl = tl.getVariable('Agent.ProxyUrl'); + + if (!proxyUrl) { + this._chatGpt = new ChatGPT(new OpenAI({ apiKey: apiKey }), tl.getBoolInput('bugs', true), tl.getBoolInput('performance', true), tl.getBoolInput('best_practices', true), additionalPrompts); + } else { + this._chatGpt = new ChatGPT(new OpenAI({ apiKey: apiKey, httpAgent: new HttpsProxyAgent(proxyUrl)}), tl.getBoolInput('bugs', true), tl.getBoolInput('performance', true), tl.getBoolInput('best_practices', true), additionalPrompts); + } + this._repository = new Repository(); this._pullRequest = new PullRequest();