response.py 931 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. from __future__ import annotations
  2. from abc import abstractmethod
  3. class ResponseType:
  4. @abstractmethod
  5. def __str__(self) -> str:
  6. pass
  7. class FinishReason():
  8. def __init__(self, reason: str):
  9. self.reason = reason
  10. def __str__(self) -> str:
  11. return ""
  12. class Sources(ResponseType):
  13. def __init__(self, sources: list[dict[str, str]]) -> None:
  14. self.list = sources
  15. def __str__(self) -> str:
  16. return "\n\n" + ("\n".join([f"{idx+1}. [{link['title']}]({link['url']})" for idx, link in enumerate(self.list)]))
  17. class BaseConversation(ResponseType):
  18. def __str__(self) -> str:
  19. return ""
  20. class SynthesizeData(ResponseType):
  21. def __init__(self, provider: str, data: dict):
  22. self.provider = provider
  23. self.data = data
  24. def to_json(self) -> dict:
  25. return {
  26. **self.__dict__
  27. }
  28. def __str__(self) -> str:
  29. return ""