From a059005506afd82fee4c881b46a88f0f69ae1812 Mon Sep 17 00:00:00 2001 From: zhayujie Date: Sat, 10 Dec 2022 13:15:31 +0800 Subject: [PATCH] feat: chatGPT bot --- .../__pycache__/baidu_unit_bot.cpython-36.pyc | Bin 1537 -> 1458 bytes bot/baidu/baidu_unit_bot.py | 5 ++- bot/bot_factory.py | 3 ++ bot/chatgpt/chat_gpt_bot.py | 30 ++++++++++++++++++ bridge/bridge.py | 2 +- .../__pycache__/wechat_channel.cpython-36.pyc | Bin 1552 -> 1552 bytes channel/wechat/wechat_channel.py | 4 +-- 7 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 bot/chatgpt/chat_gpt_bot.py diff --git a/bot/baidu/__pycache__/baidu_unit_bot.cpython-36.pyc b/bot/baidu/__pycache__/baidu_unit_bot.cpython-36.pyc index 9a1fff91fc1d8789e0cc130ecc9e5c53a58aaa33..d453432f692a24cfa7981e02c1d3daa8f1ab2141 100644 GIT binary patch delta 113 zcmZqV*~G1E%*)H=n#qv7lZAodF#{3+@);a}xY%H#vOZf1V=#jz>&5~;RvAs!B0iva v5jT*CVo%C1(F5WlCXf*GVC%*)GF{P2AeKPv;nV+JI^0%SV?ak0llWqr9+))dxkrXrVAwp5m8hAj3J zwr0j=Mn;Ad#$X0b_KgvItZKJ7;^T7@GxOr(OGSbDp6p%ld{)czj*U;3?tM06{gd4d nPj+@_a!k%(mE)EK$`^5g2(igctZIB9CI=%2BM-BHC", # This is optional + "session_token": "eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0.._BniuRSwMqdGn8t2.Hv_C4nsWF1FWnVGxNs19YZOGLDIWFlyC3FeLlTE9HUEgV1M8IFmhz1aH0j40vutVTzoEv3JDSEZN8je4kzewXE5tcKqhQF_Jh0SSHNL52OdRe_tqu_aE61L39NkvxEkmMRP2teXmWtiBIGtrPX3B77IbHIyqx9Kbk17awwl_WJokr39KlWhHE-Mpf9AwPvOW4UPi2csIxVNsVFW6MjxffRL8QZAqhXa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+last_replay_time = time.time() +chatbot = Chatbot(config) + + +class ChatGPTBot(Bot): + def reply(self, query): + global last_replay_time + now = time.time() + if now - last_replay_time > 60 * 10: + chatbot.refresh_session() + last_replay_time = now + + res = chatbot.get_chat_response(query, output="text") + # print(res) + return res['message'] + + +if __name__ == '__main__': + + bot = ChatGPTBot() + print(bot.reply('讲一个故事')) diff --git a/bridge/bridge.py b/bridge/bridge.py index 3e5af00..97fecc5 100644 --- a/bridge/bridge.py +++ b/bridge/bridge.py @@ -6,4 +6,4 @@ class Bridge(object): pass def fetch_reply_content(self, query): - return bot_factory.BaiduUnitBot().reply(query) + return bot_factory.create_bot("chatGPT").reply(query) diff --git a/channel/wechat/__pycache__/wechat_channel.cpython-36.pyc b/channel/wechat/__pycache__/wechat_channel.cpython-36.pyc index 1efc97cdabf7425e83637443f128f9fddcef2f65..835416f2198f9373f9a3361039462c7cf9924286 100644 GIT binary patch delta 36 ucmV+<0NekN43G>7GYt(2;DqvGoUsY*0|5b(_XFYqB$L_%mH`NpaRr~}#th{E delta 36 ucmV+<0NekN43G>7GYt(2_T%qj>ahv!0|5e)_XFYqCX?C(mH`TraRs0HrVXk9 diff --git a/channel/wechat/wechat_channel.py b/channel/wechat/wechat_channel.py index bcae08e..02624a8 100644 --- a/channel/wechat/wechat_channel.py +++ b/channel/wechat/wechat_channel.py @@ -2,8 +2,6 @@ wechat channel """ import itchat -import time -import random import json from itchat.content import * from channel.channel import Channel @@ -34,6 +32,6 @@ class WechatChannel(Channel): self.send(super().build_reply_content(msg['Text']), from_user_id) def send(self, msg, receiver): - time.sleep(random.randint(1, 3)) + # time.sleep(random.randint(1, 3)) print(msg, receiver) itchat.send(msg + " [bot]", toUserName=receiver)