engineBase.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. from fastapi import WebSocket
  3. from typing import List
  4. from abc import abstractmethod
  5. from digitalHuman.core import BaseRunner
  6. from digitalHuman.protocol import BaseMessage, TextMessage, AudioMessage, VoiceDesc
  7. __all__ = ["BaseEngine"]
  8. class BaseEngine(BaseRunner):
  9. @abstractmethod
  10. async def run(self, input: BaseMessage, **kwargs) -> BaseMessage:
  11. raise NotImplementedError
  12. class BaseLLMEngine(BaseEngine):
  13. @abstractmethod
  14. async def run(self, input, streaming: bool = True, **kwargs):
  15. raise NotImplementedError
  16. class BaseASREngine(BaseEngine):
  17. @abstractmethod
  18. async def run(self, input: AudioMessage, **kwargs) -> TextMessage:
  19. raise NotImplementedError
  20. class BaseTTSEngine(BaseEngine):
  21. async def voices(self, **kwargs) -> List[VoiceDesc]:
  22. return []
  23. @abstractmethod
  24. async def run(self, input: TextMessage, **kwargs) -> AudioMessage:
  25. raise NotImplementedError
  26. class StreamBaseEngine(BaseEngine):
  27. @abstractmethod
  28. async def run(self, websocket: WebSocket, **kwargs) -> None:
  29. raise NotImplementedError