You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from bot import bot_factory
  2. from bridge.context import Context
  3. from bridge.reply import Reply
  4. from common import const
  5. from common.log import logger
  6. from common.singleton import singleton
  7. from config import conf
  8. from voice import voice_factory
  9. @singleton
  10. class Bridge(object):
  11. def __init__(self):
  12. self.btype = {
  13. "chat": const.CHATGPT,
  14. "voice_to_text": conf().get("voice_to_text", "openai"),
  15. "text_to_voice": conf().get("text_to_voice", "google"),
  16. }
  17. model_type = conf().get("model")
  18. if model_type in ["text-davinci-003"]:
  19. self.btype["chat"] = const.OPEN_AI
  20. if conf().get("use_azure_chatgpt", False):
  21. self.btype["chat"] = const.CHATGPTONAZURE
  22. self.bots = {}
  23. def get_bot(self, typename):
  24. if self.bots.get(typename) is None:
  25. logger.info("create bot {} for {}".format(self.btype[typename], typename))
  26. if typename == "text_to_voice":
  27. self.bots[typename] = voice_factory.create_voice(self.btype[typename])
  28. elif typename == "voice_to_text":
  29. self.bots[typename] = voice_factory.create_voice(self.btype[typename])
  30. elif typename == "chat":
  31. self.bots[typename] = bot_factory.create_bot(self.btype[typename])
  32. return self.bots[typename]
  33. def get_bot_type(self, typename):
  34. return self.btype[typename]
  35. def fetch_reply_content(self, query, context: Context) -> Reply:
  36. return self.get_bot("chat").reply(query, context)
  37. def fetch_voice_to_text(self, voiceFile) -> Reply:
  38. return self.get_bot("voice_to_text").voiceToText(voiceFile)
  39. def fetch_text_to_voice(self, text) -> Reply:
  40. return self.get_bot("text_to_voice").textToVoice(text)