Skip to content

Commit

Permalink
Merge pull request #305 from Rqirus/master
Browse files Browse the repository at this point in the history
EdgeGPT (new bing)接入支持
  • Loading branch information
wzpan authored Jan 29, 2024
2 parents 8607167 + 20263a8 commit e409a4f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ websocket-client
pypinyin
jieba
pvporcupine
pvrecorder
pvrecorder==1.1.1
openai
apscheduler
asyncio
edge-tts
nest_asyncio
funasr_onnx
funasr_onnx
53 changes: 53 additions & 0 deletions robot/AI.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,59 @@ def chat(self, texts, parsed):
return "抱歉, 百度UNIT服务回答失败"


class BingRobot(AbstractRobot):

SLUG = "bing"

def __init__(self, prefix, proxy, mode):
"""
bing
"""
super(self.__class__, self).__init__()
self.prefix = prefix
self.proxy = proxy
self.mode = mode

@classmethod
def get_config(cls):
return config.get("bing", {})

def chat(self, texts, parsed):
"""
Arguments:
texts -- user input, typically speech, to be parsed by a module
"""
msg = "".join(texts)
msg = utils.stripPunctuation(msg)
try:
import asyncio, json
from EdgeGPT.EdgeGPT import Chatbot, ConversationStyle

async def query_bing():
# Passing cookies is "optional"
bot = await Chatbot.create(proxy=self.proxy)
m2s = {
"creative": ConversationStyle.creative,
"balanced": ConversationStyle.balanced,
"precise": ConversationStyle.precise
}
response = await bot.ask(prompt=self.prefix + "\n" + msg,
conversation_style=m2s[self.mode],
simplify_response=True)
#print(json.dumps(response, indent=2)) # Returns
return response["text"]
await bot.close()

result = asyncio.run(query_bing())

logger.info("{} 回答:{}".format(self.SLUG, result))
return result
except Exception:
logger.critical("bing robot failed to response for %r", msg, exc_info=True)
return "抱歉, bing回答失败"


class AnyQRobot(AbstractRobot):

SLUG = "anyq"
Expand Down
28 changes: 25 additions & 3 deletions static/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ server:
# 可选值:
# porcupine
# snowboy
detector: snowboy
detector: porcupine
# 灵敏度
sensitivity: 0.5

Expand All @@ -33,11 +33,13 @@ sensitivity: 0.5
porcupine:
keywords:
- 'porcupine'
- 'hello bing'
keyword_paths:
# 支持追加多个唤醒词
# 自定义唤醒词请放到 $HOME/.wukong 目录中
# - 'spiderman.ppn'
access_key: 'xxxxxxxxxxxxxxxxxxxxxxxx'
- 'hello-bing_en_raspberry-pi_v3_0_0.ppn'
access_key: ''

# snowboy 离线唤醒
# 建议使用 snowboy-seasalt (https://github.com/rhasspy/snowboy-seasalt)
Expand Down Expand Up @@ -228,7 +230,27 @@ nlu_engine: unit
# openai - OpenAI ChatGPT
# anyq - AnyQ
# tuling - 图灵机器人
robot: unit
robot: bing


# 必应 bing
bing:
prefix: "
# 角色: 语音化必应智能音箱
## 目标
- 您是一个语音化智能音箱,具备配合其他模块将你输出的文字转换为语音的能力。
## 约束
- 您的回复必须以口语化的形式呈现,不能包含任何链接、emoji表情、图片、网站推荐以及其他形式的书面语言。
- 请避免涉及到代码、图片生成等专业性的工作场景内容。
## 技能
- 百科问答技能: 您可以解答各种百科性的问题,进行科普教育。
- 咨询服务技能: 您可以接受各领域的咨询,为用户提供一对一的解答服务。
- 常见智能音箱功能: 您还能讲笑话、阅读短新闻,提供今日头条、热点等信息。
- 闲聊: 倾听倾诉给予建议"

proxy: "http://127.0.0.1:7890"
# creative, balanced, precise
mode: "creative"

# 百度 UNIT
unit:
Expand Down

0 comments on commit e409a4f

Please sign in to comment.