mellea.stdlib.base
Basic stdlib data structures.
Functions
get_images_from_component
Component
if they are present and a non-empty list, otherwise returns None.
blockify
blockify
is a helper function that turns raw strings into CBlocks.
Classes
CBlock
A CBlock
is a block of content that can serve as input to or output from an LLM.
Methods:
value
value
ImageBlock
A ImageBlock
represents an image (as base64 PNG).
Methods:
is_valid_base64_png
pil_to_base64
from_pil_image
Component
A Component
is a composite data structure that is intended to be represented to an LLM.
Methods:
parts
Component
.
format_for_llm
Component
into a TemplateRepresentation
or string.
Returns: a TemplateRepresentation
or string
GenerateType
Used to track what functions can be used to extract a value from a ModelOutputThunk.
ModelOutputThunk
A ModelOutputThunk
is a special type of CBlock
that we know came from a model’s output. It is possible to instantiate one without the output being computed yet.
Methods:
is_computed
value
value
avalue
Exception
: Propagates any errors from the underlying inference engine api request.RuntimeError
: If called when the ModelOutputThunk’s generate function is not async compatible.
astream
Exception
: Propagates any errors from the underlying inference engine api request.RuntimeError
: If called when the ModelOutputThunk’s generate function is not async compatible.
ContextTurn
A turn of model input and model output.
Context
A Context
is used to track the state of a MelleaSession
.
A context is immutable. Every alteration leads to a new context.
Methods:
from_previous
reset_to_new
is_root_node
previous_node
node_data
is_chat_context
as_list
last_n_components
is None
, then all components are returned.
actions_for_available_tools
last_output
last_turn
add
c
to this context.
view_for_generation
ChatContext
Initializes a chat context with unbounded window_size and is_chat=True by default.
Methods:
add
view_for_generation
SimpleContext
A SimpleContext
is a context in which each interaction is a separate and independent turn. The history of all previous turns is NOT saved..
Methods: