@@ -1,6 +1,5 @@ | |||||
# encoding:utf-8 | # encoding:utf-8 | ||||
import json | |||||
import requests | import requests | ||||
from bot.bot import Bot | from bot.bot import Bot | ||||
@@ -17,8 +16,8 @@ class BaiduUnitBot(Bot): | |||||
return response.json()['result']['context']['SYS_PRESUMED_HIST'][1] | return response.json()['result']['context']['SYS_PRESUMED_HIST'][1] | ||||
def get_token(self): | def get_token(self): | ||||
access_key = '${YOUR_ACCESS_KEY}' | |||||
secret_key = '${YOUR_SECRET_KEY}' | |||||
access_key = 'wdNwpvzh4fBr8xzTuPePOWhU' | |||||
secret_key = 'EUtLXyrogfTQV8nnjncnqNEfeyoHDUqS' | |||||
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + access_key + '&client_secret=' + secret_key | host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + access_key + '&client_secret=' + secret_key | ||||
response = requests.get(host) | response = requests.get(host) | ||||
if response: | if response: | ||||
@@ -3,6 +3,7 @@ channel factory | |||||
""" | """ | ||||
from bot.baidu.baidu_unit_bot import BaiduUnitBot | from bot.baidu.baidu_unit_bot import BaiduUnitBot | ||||
from bot.chatgpt.chat_gpt_bot import ChatGPTBot | |||||
def create_bot(bot_type): | def create_bot(bot_type): | ||||
@@ -13,4 +14,6 @@ def create_bot(bot_type): | |||||
""" | """ | ||||
if bot_type == 'baidu': | if bot_type == 'baidu': | ||||
return BaiduUnitBot() | return BaiduUnitBot() | ||||
elif bot_type == 'chatGPT': | |||||
return ChatGPTBot() | |||||
raise RuntimeError | raise RuntimeError |
@@ -0,0 +1,30 @@ | |||||
import time | |||||
from bot.bot import Bot | |||||
from revChatGPT.revChatGPT import Chatbot | |||||
config = { | |||||
"Authorization": "<Your Bearer Token Here>", # This is optional | |||||
"session_token": "eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0.._BniuRSwMqdGn8t2.Hv_C4nsWF1FWnVGxNs19YZOGLDIWFlyC3FeLlTE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6Cpp6x-iIyXdHS_riNGydbf5-Et1e5nlYTRAVW4Cgf-P_AAZH82PGIpWsPWO3Lsisli1IdVSHi5Vxfj8OzzE0aC5CuXzvCv18KwCyDgHZ2AZeqGkBHPyptmXyIPspaSlRtq7H7j5w57deaOmJVjHM.iOPoBiz9LmbJxxXkoKyzfQ" | |||||
} | |||||
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('讲一个故事')) |
@@ -6,4 +6,4 @@ class Bridge(object): | |||||
pass | pass | ||||
def fetch_reply_content(self, query): | def fetch_reply_content(self, query): | ||||
return bot_factory.BaiduUnitBot().reply(query) | |||||
return bot_factory.create_bot("chatGPT").reply(query) |
@@ -2,8 +2,6 @@ | |||||
wechat channel | wechat channel | ||||
""" | """ | ||||
import itchat | import itchat | ||||
import time | |||||
import random | |||||
import json | import json | ||||
from itchat.content import * | from itchat.content import * | ||||
from channel.channel import Channel | from channel.channel import Channel | ||||
@@ -34,6 +32,6 @@ class WechatChannel(Channel): | |||||
self.send(super().build_reply_content(msg['Text']), from_user_id) | self.send(super().build_reply_content(msg['Text']), from_user_id) | ||||
def send(self, msg, receiver): | def send(self, msg, receiver): | ||||
time.sleep(random.randint(1, 3)) | |||||
# time.sleep(random.randint(1, 3)) | |||||
print(msg, receiver) | print(msg, receiver) | ||||
itchat.send(msg + " [bot]", toUserName=receiver) | itchat.send(msg + " [bot]", toUserName=receiver) |