Skip to content

Commit

Permalink
✨ Add cf_clearance token support
Browse files Browse the repository at this point in the history
  • Loading branch information
fuergaosi233 committed Dec 12, 2022
1 parent 12042ec commit 11d25eb
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
4 changes: 3 additions & 1 deletion config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ chatGPTAccountPool:
password: password
session_token: session_token
chatPrivateTiggerKeyword: ""
openAIProxy: ""
openAIProxy: ""
clearanceToken: ""
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"chatgpt": "^2.0.1",
"chatgpt": "^2.1.1",
"dotenv": "^16.0.3",
"execa": "^6.1.0",
"qrcode": "^1.5.1",
Expand Down
8 changes: 7 additions & 1 deletion src/chatgpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export class ChatGPTPoole {
);
chatGPTItem.chatGpt = new ChatGPTAPI({
sessionToken: session_token,
clearanceToken: config.clearanceToken,
userAgent: config.userAgent,
});
} catch (err) {
//remove this object
Expand Down Expand Up @@ -160,6 +162,8 @@ export class ChatGPTPoole {
return {
chatGpt: new ChatGPTAPI({
sessionToken: account.session_token,
clearanceToken: config.clearanceToken,
userAgent: config.userAgent,
}),
account,
};
Expand Down Expand Up @@ -220,7 +224,9 @@ export class ChatGPTPoole {
return response;
} catch (err: any) {
if (err.message.includes("ChatGPT failed to refresh auth token")) {
// If refresh token failed, we will remove the conversation from pool
await this.resetAccount(account);
console.log(`Refresh token failed, account ${JSON.stringify(account)}`);
return this.sendMessage(message, talkid);
}
console.error(
Expand Down Expand Up @@ -274,7 +280,7 @@ export class ChatGPTBot {
""
);
// remove more text via - - - - - - - - - - - - - - -
return text.trim();
return text;
}
async getGPTMessage(text: string, talkerId: string): Promise<string> {
return await this.chatGPTPool.sendMessage(text, talkerId);
Expand Down
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ if (fs.existsSync("./config.yaml")) {
chatGptRetryTimes: Number(process.env.CHAT_GPT_RETRY_TIMES),
chatPrivateTiggerKeyword: process.env.CHAT_PRIVATE_TRIGGER_KEYWORD,
openAIProxy: process.env.OPENAI_PROXY,
clearanceToken: process.env.CF_CLEARANCE,
userAgent: process.env.USER_AGENT,
};
}
dotenv.config();
Expand All @@ -38,4 +40,6 @@ export const config: IConfig = {
"",
// Support openai-js use this proxy
openAIProxy: configFile.openAIProxy,
clearanceToken: configFile.clearanceToken,
userAgent: configFile.userAgent,
};
2 changes: 2 additions & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ export interface IConfig {
chatGptRetryTimes: number;
chatPrivateTiggerKeyword: string;
openAIProxy?: string;
clearanceToken: string;
userAgent: string;
}

0 comments on commit 11d25eb

Please sign in to comment.