Types#

Flexible Input#

bodhilib defines a set of very flexible TypeAlias to hint at the type of inputs that can be taken by the method.

This allows a method to take in various types of valid inputs, that are internally converted to a standard input format, before being processed. This approach allows extremem composability of methods, and allowing easy building of complex flows.

SupportsText#

SupportsText is a Python protocol. This protocol enforces a Python object to have a property text with a type of str. This way, any object that has such property can be passed whenever a SupportsText type is expected.

class SupportsText(Protocol):
    @property
    def text(self) -> str: ...

Many of the Python models conforms to SupportsText. These are - Prompt, PromptStream, Node, Document.

TextLike#

TextLike extends the SupportsText by also including plain strings as a input type.

TextLike: TypeAlias = Union[str, "SupportsText"]

TextLikeOrTextLikeList#

TextLikeOrTextLikeList extends TextLike by also including list of TextLike as a input type.

TextLikeOrTextLikeList: TypeAlias = Union[TextLike, Iterable[TextLike]]

SerializedInput#

SerializedInput extends TextLikeOrTextLikeList by also including a serialized object as dict or a list of serialized object as dict as input type. These are handy when serialized Pydantic object are passed as input.

SerializedInput: TypeAlias = Union[TextLikeOrTextLikeList, Dict[str, Any], Iterable[Dict[str, Any]]]

🎉 We just got familiar with the types of bodhilib.

Next, let’s see different Models used in the library.