wzpan / wukong-robot

🤖 wukong-robot 是一个简单、灵活、优雅的中文语音对话机器人/智能音箱项目,支持ChatGPT多轮对话能力,还可能是首个支持脑机交互的开源智能音箱项目。
https://wukong.hahack.com/
MIT License
6.33k stars 1.34k forks source link

修复OpenAI的API过期失效。 #261

Closed prairiewolf11 closed 1 year ago

prairiewolf11 commented 1 year ago

.

prairiewolf11 commented 1 year ago

搞定 pip install revChatGPT

class ChatGPTRobot(AbstractRobot):

SLUG = "ChatGPT"

def __init__(self, email, password, proxy, paid):
    """
    ChatGPT机器人
    """
    super(self.__class__, self).__init__()
    self.proxy = proxy
    self.chatbot = Chatbot(config={
        "email": email,
        "password": password,
        "paid": paid
    })
@classmethod
def get_config(cls):
    # Try to get chatgpt config from config
    return config.get("ChatGPT", {})

def chat(self, texts, parsed):
    msg = "".join(texts)
    msg = utils.stripPunctuation(msg)
    logger.info("msg: " + msg)
    try:
        respond = ""
        for data in self.chatbot.ask(msg):
            respond = data["message"]
        logger.info("{} 回答:{}".format(self.SLUG, respond))
        return respond

    except Exception:
        logger.critical("ChatGPT robot failed to response for %r", msg, exc_info=True)
        return "抱歉, ChatGPT回答失败"