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

49 行
1.6KB

  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. from config import conf
  8. from common import const
  9. @singleton
  10. class Bridge(object):
  11. def __init__(self):
  12. self.btype={
  13. "chat": const.CHATGPT,
  14. "voice_to_text": "openai",
  15. "text_to_voice": "baidu"
  16. }
  17. model_type = conf().get("model")
  18. if model_type in ["text-davinci-003"]:
  19. self.btype['chat'] = const.OPEN_AI
  20. self.bots={}
  21. def get_bot(self,typename):
  22. if self.bots.get(typename) is None:
  23. logger.info("create bot {} for {}".format(self.btype[typename],typename))
  24. if typename == "text_to_voice":
  25. self.bots[typename] = voice_factory.create_voice(self.btype[typename])
  26. elif typename == "voice_to_text":
  27. self.bots[typename] = voice_factory.create_voice(self.btype[typename])
  28. elif typename == "chat":
  29. self.bots[typename] = bot_factory.create_bot(self.btype[typename])
  30. return self.bots[typename]
  31. def get_bot_type(self,typename):
  32. return self.btype[typename]
  33. def fetch_reply_content(self, query, context : Context) -> Reply:
  34. return self.get_bot("chat").reply(query, context)
  35. def fetch_voice_to_text(self, voiceFile) -> Reply:
  36. return self.get_bot("voice_to_text").voiceToText(voiceFile)
  37. def fetch_text_to_voice(self, text) -> Reply:
  38. return self.get_bot("text_to_voice").textToVoice(text)