增加星火API

This commit is contained in:
TechShrimp
2023-10-11 07:52:58 +08:00
parent 572499f8bb
commit 7ced27123a
6 changed files with 40 additions and 0 deletions

View File

@@ -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

View File

@@ -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")

24
func_xinghuo_web.py Normal file
View File

@@ -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)

View File

@@ -41,6 +41,8 @@ def main():
# 机器人启动发送测试消息
robot.sendTextMsg("机器人启动成功!", "filehelper")
#print(robot.getAllContacts())
# 接收消息
# robot.enableRecvMsg() # 可能会丢消息?
robot.enableReceivingMsg() # 加队列

View File

@@ -5,4 +5,7 @@ pandas
pyyaml
requests
schedule
requests
pyhandytools
sparkdesk-api==1.3.0
wcferry>=39.0.3.0

View File

@@ -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