0.6.1 • Published 3 years ago
chatgpt-api-pool v0.6.1
ChatGPT API Pool
Build your own ChatGPT with a request pool.
NOTICE: due to
chatgptdependency does not supportCJS, so this library does not work properly inCJSenvironment, use it on your own risk, recommend to useESM.Use
gpt-3.5-turbo
Usage
const API_KEYS = ['...', '...']
const EMAIL_CONFIG = {
  // Here is a documentation about QQ email:https://www.ujcms.com/documentation/351.html
  serverConfig: {
    host: 'smtp.xx.com',
    port: 465,
    secure: true,
    auth: {
      user: 'xxx',
      pass: 'xxx'
    }
  },
  targetEmail: 'xxx@qq.com'
}
// EMAIL_CONFIG is optional, to provide email notification when key is exhausted
const requestPool = new RequestPool(API_KEYS, EMAIL_CONFIG)
const response: {
  success: boolean
  message: ChatMessage /* from chatgpt library */
  error: ErrorType
} = await requestPool.sendMessage(q, options) // options, see https://github.com/transitive-bullshit/chatgpt-api/blob/main/src/types.ts#L5-L15ErrorType
enum ErrorType {
  NO_VALID_KEYS = 'no_valid_keys',
}