This PR introduces the MessagePart API, which allows messages to be comprised of a number of MessageParts rather than a singular str. To accomplish this, the following changes were made:
ChatMessage.content now has the type str | tuple[MessagePart | str, ...] | None
For base engines (e.g. OpenAI, LLaMA), this will not affect their functionality and they will continue to operate as in kani v0.4
content has to be a tuple to enforce immutability; constructors and copy methods enforce this/cast Sequences to the right underlying type
Added ChatMessage.text: str and ChatMessage.parts: list[MessagePart | str] to get a consistent type from the message content
These are properties that proxy the underlying content; .part returns a list proxy of the underlying tuple content or returns a one-element list of the string content
Refactored a bunch of places across the library where .content was assumed to be a str to use .text instead
Added a Chain of Thought example using MessageParts to demonstrate how to use the interface
This will lay the foundation for future implementation of multimodal models and engines with engine-specific metadata (e.g. ReAct).
We discussed these comments IRL and will make an update to _auto_truncate_message in a future update that will also allow function calls to return ChatMessages rather than just strings.
This PR introduces the MessagePart API, which allows messages to be comprised of a number of
MessagePart
s rather than a singularstr
. To accomplish this, the following changes were made:ChatMessage.content
now has the typestr | tuple[MessagePart | str, ...] | None
Sequence
s to the right underlying typeChatMessage.text: str
andChatMessage.parts: list[MessagePart | str]
to get a consistent type from the message content.part
returns a list proxy of the underlying tuple content or returns a one-element list of the string content.content
was assumed to be a str to use.text
insteadThis will lay the foundation for future implementation of multimodal models and engines with engine-specific metadata (e.g. ReAct).