From 7ced27123a7a33f7a363750d772d07164532aefd Mon Sep 17 00:00:00 2001 From: TechShrimp <939178127@qq.com> Date: Wed, 11 Oct 2023 07:52:58 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=98=9F=E7=81=ABAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml.template | 7 +++++++ configuration.py | 1 + func_xinghuo_web.py | 24 ++++++++++++++++++++++++ main.py | 2 ++ requirements.txt | 3 +++ robot.py | 3 +++ 6 files changed, 40 insertions(+) create mode 100644 func_xinghuo_web.py diff --git a/config.yaml.template b/config.yaml.template index 9d507e6..93ffcc6 100644 --- a/config.yaml.template +++ b/config.yaml.template @@ -57,3 +57,10 @@ report_reminder: tigerbot: key: key model: tigerbot-7b-sft + +# 使用讯飞星火模型api需要抓取以下参数 +# 抓取方式详见:https://github.com/HildaM/sparkdesk-api/tree/main/docs +xinghuo_web: + cookie: cookie + fd: fd + GtToken: GtToken diff --git a/configuration.py b/configuration.py index 517d96e..afc2b04 100644 --- a/configuration.py +++ b/configuration.py @@ -32,3 +32,4 @@ class Config(object): self.NEWS = yconfig["news"]["receivers"] self.REPORT_REMINDERS = yconfig["report_reminder"]["receivers"] self.TIGERBOT = yconfig.get("tigerbot") + self.XINGHUO_WEB = yconfig.get("xinghuo_web") diff --git a/func_xinghuo_web.py b/func_xinghuo_web.py new file mode 100644 index 0000000..8709be1 --- /dev/null +++ b/func_xinghuo_web.py @@ -0,0 +1,24 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- +from sparkdesk_web.core import SparkWeb + +class XinghuoWeb(): + def __init__(self, xhconf=None) -> None: + + self._sparkWeb = SparkWeb( + cookie=xhconf["cookie"], + fd=xhconf["fd"], + GtToken=xhconf["GtToken"] + ) + self._chat = self._sparkWeb.create_continuous_chat() + + def get_answer(self, msg: str, sender: str = None) -> str: + answer = self._chat.chat(msg) + return answer + +if __name__ == "__main__": + from configuration import Config + c = Config() + xinghuo = XinghuoWeb(c.XINGHUO_WEB) + rsp = xinghuo.get_answer("你还活着?") + print(rsp) diff --git a/main.py b/main.py index 5e3288d..4705381 100644 --- a/main.py +++ b/main.py @@ -41,6 +41,8 @@ def main(): # 机器人启动发送测试消息 robot.sendTextMsg("机器人启动成功!", "filehelper") + #print(robot.getAllContacts()) + # 接收消息 # robot.enableRecvMsg() # 可能会丢消息? robot.enableReceivingMsg() # 加队列 diff --git a/requirements.txt b/requirements.txt index f76c6fa..e7326e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,7 @@ pandas pyyaml requests schedule +requests +pyhandytools +sparkdesk-api==1.3.0 wcferry>=39.0.3.0 diff --git a/robot.py b/robot.py index 5950ae9..c635b19 100644 --- a/robot.py +++ b/robot.py @@ -14,6 +14,7 @@ from func_chatgpt import ChatGPT from func_chengyu import cy from func_news import News from func_tigerbot import TigerBot +from func_xinghuo_web import XinghuoWeb from job_mgmt import Job @@ -33,6 +34,8 @@ class Robot(Job): elif self.config.CHATGPT: cgpt = self.config.CHATGPT self.chat = ChatGPT(cgpt.get("key"), cgpt.get("api"), cgpt.get("proxy"), cgpt.get("prompt")) + elif self.config.XINGHUO_WEB: + self.chat = XinghuoWeb(self.config.XINGHUO_WEB) else: self.chat = None From d1c1e2ca4351162c621849e27caf9469cb6c8d3e Mon Sep 17 00:00:00 2001 From: TechShrimp <939178127@qq.com> Date: Sun, 15 Oct 2023 15:12:12 +0800 Subject: [PATCH 2/4] AutoPEP8 --- config.yaml.template | 13 +++++++------ func_xinghuo_web.py | 7 ++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/config.yaml.template b/config.yaml.template index 93ffcc6..cdd5fb7 100644 --- a/config.yaml.template +++ b/config.yaml.template @@ -58,9 +58,10 @@ tigerbot: key: key model: tigerbot-7b-sft -# 使用讯飞星火模型api需要抓取以下参数 -# 抓取方式详见:https://github.com/HildaM/sparkdesk-api/tree/main/docs -xinghuo_web: - cookie: cookie - fd: fd - GtToken: GtToken +# 使用讯飞星火web模式api需要抓取以下参数 +# 抓取方式详见文档:https://www.bilibili.com/read/cv27066577 +# xinghuo_web: +# cookie: cookie +# fd: fd +# GtToken: GtToken +# prompt: 你是智能聊天机器人,你叫wcferry。请用这个角色回答我的问题 # 根据需要对角色进行设定 \ No newline at end of file diff --git a/func_xinghuo_web.py b/func_xinghuo_web.py index 8709be1..266eadf 100644 --- a/func_xinghuo_web.py +++ b/func_xinghuo_web.py @@ -2,20 +2,25 @@ # -*- coding: utf-8 -*- from sparkdesk_web.core import SparkWeb + class XinghuoWeb(): def __init__(self, xhconf=None) -> None: self._sparkWeb = SparkWeb( cookie=xhconf["cookie"], fd=xhconf["fd"], - GtToken=xhconf["GtToken"] + GtToken=xhconf["GtToken"], ) self._chat = self._sparkWeb.create_continuous_chat() + # 如果有提示词 + if xhconf["prompt"]: + self._chat.chat(xhconf["prompt"]) def get_answer(self, msg: str, sender: str = None) -> str: answer = self._chat.chat(msg) return answer + if __name__ == "__main__": from configuration import Config c = Config() From 1394bda837f7504ccc2c9f4ec8c673a12f88c3c2 Mon Sep 17 00:00:00 2001 From: TechShrimp <939178127@qq.com> Date: Sun, 15 Oct 2023 15:24:24 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.py b/main.py index 4705381..5e3288d 100644 --- a/main.py +++ b/main.py @@ -41,8 +41,6 @@ def main(): # 机器人启动发送测试消息 robot.sendTextMsg("机器人启动成功!", "filehelper") - #print(robot.getAllContacts()) - # 接收消息 # robot.enableRecvMsg() # 可能会丢消息? robot.enableReceivingMsg() # 加队列 From b4503c7f237276124a9287d1ec9595f2928d8a5f Mon Sep 17 00:00:00 2001 From: TechShrimp <939178127@qq.com> Date: Mon, 16 Oct 2023 16:17:11 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=A0=B9=E6=8D=AEPR=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml.template | 2 +- requirements.txt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/config.yaml.template b/config.yaml.template index cdd5fb7..e23de14 100644 --- a/config.yaml.template +++ b/config.yaml.template @@ -64,4 +64,4 @@ tigerbot: # cookie: cookie # fd: fd # GtToken: GtToken -# prompt: 你是智能聊天机器人,你叫wcferry。请用这个角色回答我的问题 # 根据需要对角色进行设定 \ No newline at end of file +# prompt: 你是智能聊天机器人,你叫wcferry。请用这个角色回答我的问题 # 根据需要对角色进行设定 diff --git a/requirements.txt b/requirements.txt index e7326e3..0394075 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,6 @@ pandas pyyaml requests schedule -requests pyhandytools sparkdesk-api==1.3.0 wcferry>=39.0.3.0