mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-21 14:17:11 +08:00
create bot when first need
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
from common.log import logger
|
||||||
from bot import bot_factory
|
from bot import bot_factory
|
||||||
from common.singleton import singleton
|
from common.singleton import singleton
|
||||||
from voice import voice_factory
|
from voice import voice_factory
|
||||||
@@ -6,15 +7,23 @@ from voice import voice_factory
|
|||||||
@singleton
|
@singleton
|
||||||
class Bridge(object):
|
class Bridge(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.bots = {
|
self.btype={
|
||||||
"chat": bot_factory.create_bot("chatGPT"),
|
"chat": "chatGPT",
|
||||||
"voice_to_text": voice_factory.create_voice("openai"),
|
"voice_to_text": "openai",
|
||||||
# "text_to_voice": voice_factory.create_voice("baidu")
|
"text_to_voice": "baidu"
|
||||||
}
|
}
|
||||||
try:
|
self.bots={}
|
||||||
self.bots["text_to_voice"] = voice_factory.create_voice("baidu")
|
|
||||||
except ModuleNotFoundError as e:
|
def getbot(self,typename):
|
||||||
print(e)
|
if self.bots.get(typename) is None:
|
||||||
|
logger.info("create bot {} for {}".format(self.btype[typename],typename))
|
||||||
|
if typename == "text_to_voice":
|
||||||
|
self.bots[typename] = voice_factory.create_voice(self.btype[typename])
|
||||||
|
elif typename == "voice_to_text":
|
||||||
|
self.bots[typename] = voice_factory.create_voice(self.btype[typename])
|
||||||
|
elif typename == "chat":
|
||||||
|
self.bots[typename] = bot_factory.create_bot(self.btype[typename])
|
||||||
|
return self.bots[typename]
|
||||||
|
|
||||||
# 以下所有函数需要得到一个reply字典,格式如下:
|
# 以下所有函数需要得到一个reply字典,格式如下:
|
||||||
# reply["type"] = "ERROR" / "TEXT" / "VOICE" / ...
|
# reply["type"] = "ERROR" / "TEXT" / "VOICE" / ...
|
||||||
@@ -28,3 +37,4 @@ class Bridge(object):
|
|||||||
|
|
||||||
def fetch_text_to_voice(self, text):
|
def fetch_text_to_voice(self, text):
|
||||||
return self.bots["text_to_voice"].textToVoice(text)
|
return self.bots["text_to_voice"].textToVoice(text)
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class PluginManager:
|
|||||||
|
|
||||||
def load_plugins(self):
|
def load_plugins(self):
|
||||||
pconf = self.load_config()
|
pconf = self.load_config()
|
||||||
logger.debug("plugins.json config={}" % pconf)
|
logger.debug("plugins.json config={}".format(pconf))
|
||||||
for plugin in pconf["plugins"]:
|
for plugin in pconf["plugins"]:
|
||||||
name = plugin["name"]
|
name = plugin["name"]
|
||||||
enabled = plugin["enabled"]
|
enabled = plugin["enabled"]
|
||||||
|
|||||||
Reference in New Issue
Block a user