Skip to content

Commit b432e1e

Browse files
committed
✨ Add OpenAi Proxy config
1 parent 65c9c3d commit b432e1e

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

config.yaml.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ chatGPTAccountPool:
22
- email: email
33
password: password
44
session_token: session_token
5-
chatPrivateTiggerKeyword: ""
5+
chatPrivateTiggerKeyword: ""
6+
openAIProxy: ""

src/chatgpt.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ export class ChatGPTPoole {
5858
const platform = process.platform;
5959
const { stdout, stderr, exitCode } = await execa(
6060
platform === "win32" ? "powershell" : "sh",
61-
[platform === "win32" ? "/c" : "-c", cmd]
61+
[platform === "win32" ? "/c" : "-c", cmd],
62+
{
63+
env: {
64+
https_proxy: config.openAIProxy || process.env.https_proxy,
65+
},
66+
}
6267
);
6368
if (exitCode !== 0) {
6469
console.error(`${email} login failed: ${stderr}`);

src/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ if (fs.existsSync("./config.yaml")) {
1919
],
2020
chatGptRetryTimes: Number(process.env.CHAT_GPT_RETRY_TIMES),
2121
chatPrivateTiggerKeyword: process.env.CHAT_PRIVATE_TRIGGER_KEYWORD,
22+
openAIProxy: process.env.OPENAI_PROXY,
2223
};
2324
}
2425
dotenv.config();
@@ -35,4 +36,6 @@ export const config: IConfig = {
3536
""
3637
) ||
3738
"",
39+
// Support openai-js use this proxy
40+
openAIProxy: configFile.openAIProxy,
3841
};

src/generate_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def login(email: str, password: str) -> str:
2020
config={
2121
"email": email,
2222
"password": password,
23-
"proxy": os.environ.get("http_proxy", None),
23+
"proxy": os.environ.get("http_proxy",None) or os.environ.get("openAIProxy", None) ,
2424
},
2525
conversation_id=None,
2626
)

src/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ export interface IConfig {
3636
chatGPTAccountPool: IAccount[];
3737
chatGptRetryTimes: number;
3838
chatPrivateTiggerKeyword: string;
39+
openAIProxy?: string;
3940
}

0 commit comments

Comments
 (0)