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

53 行
1.7KB

  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": "chatGPT",
  14. "voice_to_text": "openai",
  15. "text_to_voice": "baidu"
  16. }
  17. self.bots={}
  18. def get_bot(self,typename):
  19. if self.bots.get(typename) is None:
  20. logger.info("create bot {} for {}".format(self.btype[typename],typename))
  21. if typename == "text_to_voice":
  22. self.bots[typename] = voice_factory.create_voice(self.btype[typename])
  23. elif typename == "voice_to_text":
  24. self.bots[typename] = voice_factory.create_voice(self.btype[typename])
  25. elif typename == "chat":
  26. self.bots[typename] = bot_factory.create_bot(self.btype[typename])
  27. return self.bots[typename]
  28. def get_bot_type(self,typename):
  29. return self.btype[typename]
  30. def fetch_reply_content(self, query, context : Context) -> Reply:
  31. bot_type = const.CHATGPT
  32. model_type = conf().get("model")
  33. if model_type in ["gpt-3.5-turbo", "gpt-4", "gpt-4-32k"]:
  34. bot_type = const.CHATGPT
  35. elif model_type in ["text-davinci-003"]:
  36. bot_type = const.OPEN_AI
  37. return bot_factory.create_bot(bot_type).reply(query, context)
  38. def fetch_voice_to_text(self, voiceFile) -> Reply:
  39. return self.get_bot("voice_to_text").voiceToText(voiceFile)
  40. def fetch_text_to_voice(self, text) -> Reply:
  41. return self.get_bot("text_to_voice").textToVoice(text)