Add tigerbot

This commit is contained in:
Changhua
2023-07-09 07:57:39 +08:00
parent 78fa5035a1
commit bfb1735dd3
2 changed files with 16 additions and 9 deletions

View File

@@ -15,16 +15,18 @@ class TigerBot():
self.tbmodel = tbconf["model"]
self.fallback = ["", "快滚", "赶紧滚"]
def answer(self, msg: str, sender: str = None) -> str:
def get_answer(self, msg: str, sender: str = None) -> str:
payload = {
"text": msg,
"modelVersion": self.tbmodel
}
rsp = ""
try:
rsp = requests.post(self.tburl, headers=self.tbheaders, json=payload).json()["data"]["result"][0]
rsp = requests.post(self.tburl, headers=self.tbheaders, json=payload).json()
rsp = rsp["data"]["result"][0]
except Exception as e:
self.LOG.error(f"{e}")
idx = randint(0, len(self.fallback))
self.LOG.error(f"{e}: {payload}\n{rsp}")
idx = randint(0, len(self.fallback) - 1)
rsp = self.fallback[idx]
return rsp
@@ -34,5 +36,5 @@ if __name__ == "__main__":
from configuration import Config
c = Config()
tbot = TigerBot(c.TIGERBOT)
rsp = tbot.answer("你还活着?")
rsp = tbot.get_answer("你还活着?")
print(rsp)

View File

@@ -11,6 +11,7 @@ from configuration import Config
from func_chatgpt import ChatGPT
from func_chengyu import cy
from func_news import News
from func_tigerbot import TigerBot
from job_mgmt import Job
@@ -24,10 +25,14 @@ class Robot(Job):
self.LOG = logging.getLogger("Robot")
self.wxid = self.wcf.get_self_wxid()
self.allContacts = self.getAllContacts()
self.chat = None
chatgpt = self.config.CHATGPT
if chatgpt:
self.chat = ChatGPT(chatgpt.get("key"), chatgpt.get("api"), chatgpt.get("proxy"), chatgpt.get("prompt"))
if self.config.TIGERBOT:
self.chat = TigerBot(self.config.TIGERBOT)
elif self.config.CHATGPT:
cgpt = self.config.CHATGPT
self.chat = ChatGPT(cgpt.get("key"), cgpt.get("api"), cgpt.get("proxy"), cgpt.get("prompt"))
else:
self.chat = None
def toAt(self, msg: WxMsg) -> bool:
"""处理被 @ 消息