Coverage for src/appl/core/promptable/base.py: 78%

9 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-22 15:39 -0800

1from ..types import * 

2 

3 

4class Promptable(ABC): 

5 """Interface for objects that can be converted to a prompt string.""" 

6 

7 @abstractmethod 

8 def __prompt__(self) -> Any: 

9 """Convert the object to a prompt object.""" 

10 raise NotImplementedError 

11 

12 

13def promptify(obj: Any) -> Any: 

14 """Convert an object to a prompt object if it is promptable.""" 

15 if isinstance(obj, Promptable): 

16 s = obj.__prompt__() 

17 if isinstance(s, str): 

18 s = StringFuture(s) 

19 return s 

20 

21 return StringFuture(str(obj))