mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-04-05 10:38:15 +08:00
avoid repeatedly instantiating bot
This commit is contained in:
@@ -1,16 +1,25 @@
|
||||
from bot import bot_factory
|
||||
from common.singleton import singleton
|
||||
from voice import voice_factory
|
||||
|
||||
|
||||
@singleton
|
||||
class Bridge(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
self.bots = {
|
||||
"chat": bot_factory.create_bot("chatGPT"),
|
||||
"voice_to_text": voice_factory.create_voice("openai"),
|
||||
# "text_to_voice": voice_factory.create_voice("baidu")
|
||||
}
|
||||
try:
|
||||
self.bots["text_to_voice"] = voice_factory.create_voice("baidu")
|
||||
except ModuleNotFoundError as e:
|
||||
print(e)
|
||||
|
||||
def fetch_reply_content(self, query, context):
|
||||
return bot_factory.create_bot("chatGPT").reply(query, context)
|
||||
return self.bots["chat"].reply(query, context)
|
||||
|
||||
def fetch_voice_to_text(self, voiceFile):
|
||||
return voice_factory.create_voice("openai").voiceToText(voiceFile)
|
||||
return self.bots["voice_to_text"].voiceToText(voiceFile)
|
||||
|
||||
def fetch_text_to_voice(self, text):
|
||||
return voice_factory.create_voice("baidu").textToVoice(text)
|
||||
return self.bots["text_to_voice"].textToVoice(text)
|
||||
Reference in New Issue
Block a user