scene.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from abc import ABCMeta, abstractmethod
  4. class Msg(object):
  5. def __init__(self, **kwargs):
  6. self.code = kwargs.get("code")
  7. self.question = kwargs.get("question")
  8. self.option = kwargs.get("option")
  9. self.asr = kwargs.get("asr")
  10. self.session = kwargs.get("session")
  11. self.record = kwargs.get("record")
  12. # event = kwargs.get("event")
  13. self.interruptable = kwargs.get("interruptable")
  14. self.wait_time = kwargs.get("wait_time")
  15. self.action = kwargs.get("action")
  16. self.talk_time = kwargs.get("talk_time")
  17. self.inputType = kwargs.get("inputType")
  18. class Scene(metaclass=ABCMeta):
  19. """
  20. 会话场景基类
  21. """
  22. @abstractmethod
  23. def dialogue(self, msg, bid, uid, session_id) -> Msg:
  24. """
  25. @param msg: 消息
  26. @param bid: 机器人id
  27. @param uid: 用户id
  28. @param session_id: 对话id
  29. @return:
  30. """
  31. pass
  32. class Kernel(metaclass=ABCMeta):
  33. """
  34. 会话场景驱动类,每个场景都有内部驱动逻辑
  35. """
  36. @abstractmethod
  37. def next(self, bot_id, uid, session_id):
  38. """
  39. 获取下一个数据
  40. """
  41. pass
  42. @abstractmethod
  43. def parse(self, msg, bot_id, uid, session_id) -> None:
  44. """
  45. 解析获取到的数据
  46. """
  47. pass