base.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import copy
  2. from dataclasses import dataclass
  3. @dataclass
  4. class Observation:
  5. """
  6. This data class represents an observation of the environment.
  7. """
  8. content: str
  9. def __str__(self) -> str:
  10. return self.content
  11. def to_dict(self) -> dict:
  12. """Converts the observation to a dictionary."""
  13. extras = copy.deepcopy(self.__dict__)
  14. content = extras.pop("content", "")
  15. observation = extras.pop("observation", "")
  16. return {
  17. "observation": observation,
  18. "content": content,
  19. "extras": extras,
  20. "message": self.message,
  21. }
  22. @property
  23. def message(self) -> str:
  24. """Returns a message describing the observation."""
  25. return ""
  26. @dataclass
  27. class NullObservation(Observation):
  28. """
  29. This data class represents a null observation.
  30. This is used when the produced action is NOT executable.
  31. """
  32. observation : str = "null"
  33. @property
  34. def message(self) -> str:
  35. return ""