-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️: Refactor code for add more error log
- Loading branch information
1 parent
acc63b6
commit 069c7a8
Showing
3 changed files
with
145 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import * as dotenv from "dotenv"; | ||
import { parse, stringify } from "yaml"; | ||
import { parse } from "yaml"; | ||
import fs from "fs"; | ||
import { IConfig, IAccount } from "./interface"; | ||
const file = fs.readFileSync("./config.yaml", "utf8"); | ||
const configFile = parse(file); | ||
dotenv.config(); | ||
export const config = { | ||
chatGPTAccountPool: configFile.chatGPTAccountPool, | ||
export const config: IConfig = { | ||
chatGPTAccountPool: configFile.chatGPTAccountPool as Array<IAccount>, | ||
chatGptRetryTimes: | ||
configFile.chatGptRetryTimes || | ||
Number(process.env.CHAT_GPT_RETRY_TIMES) || | ||
3, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { ChatGPTConversation, ChatGPTAPI } from "chatgpt"; | ||
export interface AccountWithUserInfo { | ||
password: string; | ||
email: string; | ||
} | ||
export interface AccountWithSessionToken { | ||
session_token: string; | ||
} | ||
export const isAccountWithUserInfo = ( | ||
account: IAccount | ||
): account is AccountWithUserInfo => { | ||
return ( | ||
(account as AccountWithUserInfo).email !== undefined && | ||
(account as AccountWithUserInfo).password !== undefined | ||
); | ||
}; | ||
export const isAccountWithSessionToken = ( | ||
account: IAccount | ||
): account is AccountWithSessionToken => { | ||
return (account as AccountWithSessionToken).session_token !== undefined; | ||
}; | ||
|
||
// Account will be one in the session token or email and password | ||
export type IAccount = AccountWithUserInfo | AccountWithSessionToken; | ||
|
||
export interface IChatGPTItem { | ||
chatGpt: ChatGPTAPI; | ||
account: IAccount; | ||
} | ||
export interface IConversationItem { | ||
conversation: ChatGPTConversation; | ||
account: IAccount; | ||
} | ||
|
||
export interface IConfig { | ||
chatGPTAccountPool: IAccount[]; | ||
chatGptRetryTimes: number; | ||
} |