Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix proxy setting #8

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ai-commit",
"displayName": "AI Commit",
"description": "Use Azure/OpenAI API to review Git changes, generate conventional commit messages that meet the conventions, simplify the commit process, and keep the commit conventions consistent.",
"version": "0.0.6",
"version": "0.0.7",
"engines": {
"node": ">=16",
"vscode": "^1.77.0"
Expand Down Expand Up @@ -158,6 +158,7 @@
"webpack-cli": "^5.0.1"
},
"dependencies": {
"https-proxy-agent": "^7.0.5",
"openai": "^4.14.2",
"simple-git": "^3.17.0",
"fs-extra": "^11.0.4"
Expand Down
11 changes: 11 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as vscode from 'vscode';
import { Agent } from 'https';
import { HttpsProxyAgent } from 'https-proxy-agent';

/**
* Configuration keys used in the AI commit extension.
Expand Down Expand Up @@ -50,6 +52,15 @@ export class ConfigurationManager {
return this.configCache.get(key);
}

getProxyAgent(): Agent | undefined {
const proxy = vscode.workspace.getConfiguration().get<string>('http.proxy');
console.warn('Debug: ', proxy);
if (proxy) {
return new HttpsProxyAgent(proxy);
}
return undefined;
}

dispose() {
this.disposable.dispose();
}
Expand Down
7 changes: 7 additions & 0 deletions src/openai-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import OpenAI from 'openai';
import { ChatCompletionMessageParam } from 'openai/resources';
import { ConfigKeys, ConfigurationManager } from './config';
import { type Agent } from 'http';

/**
* Creates and returns an OpenAI configuration object.
Expand All @@ -12,6 +13,7 @@ function getOpenAIConfig() {
const apiKey = configManager.getConfig<string>(ConfigKeys.OPENAI_API_KEY);
const baseURL = configManager.getConfig<string>(ConfigKeys.OPENAI_BASE_URL);
const apiVersion = configManager.getConfig<string>(ConfigKeys.AZURE_API_VERSION);
const httpAgent = configManager.getProxyAgent();

if (!apiKey) {
throw new Error('The OPENAI_API_KEY environment variable is missing or empty.');
Expand All @@ -20,12 +22,17 @@ function getOpenAIConfig() {
const config: {
apiKey: string;
baseURL?: string;
httpAgent?: Agent;
defaultQuery?: { 'api-version': string };
defaultHeaders?: { 'api-key': string };
} = {
apiKey
};

if (httpAgent) {
config.httpAgent = httpAgent;
}

if (baseURL) {
config.baseURL = baseURL;
if (apiVersion) {
Expand Down