選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

43 行
1.4KB

  1. from bridge.context import Context
  2. from bridge.reply import Reply
  3. from common.log import logger
  4. from bot import bot_factory
  5. from common.singleton import singleton
  6. from voice import voice_factory
  7. @singleton
  8. class Bridge(object):
  9. def __init__(self):
  10. self.btype={
  11. "chat": "chatGPT",
  12. "voice_to_text": "openai",
  13. "text_to_voice": "baidu"
  14. }
  15. self.bots={}
  16. def get_bot(self,typename):
  17. if self.bots.get(typename) is None:
  18. logger.info("create bot {} for {}".format(self.btype[typename],typename))
  19. if typename == "text_to_voice":
  20. self.bots[typename] = voice_factory.create_voice(self.btype[typename])
  21. elif typename == "voice_to_text":
  22. self.bots[typename] = voice_factory.create_voice(self.btype[typename])
  23. elif typename == "chat":
  24. self.bots[typename] = bot_factory.create_bot(self.btype[typename])
  25. return self.bots[typename]
  26. def get_bot_type(self,typename):
  27. return self.btype[typename]
  28. def fetch_reply_content(self, query, context : Context) -> Reply:
  29. return self.get_bot("chat").reply(query, context)
  30. def fetch_voice_to_text(self, voiceFile) -> Reply:
  31. return self.get_bot("voice_to_text").voiceToText(voiceFile)
  32. def fetch_text_to_voice(self, text) -> Reply:
  33. return self.get_bot("text_to_voice").textToVoice(text)