sammo.components
#
Module Contents#
Classes#
Call the LLM to generate a response. |
|
Final output of a prompt pipeline. Runs the child component on each batch in the input and has an optional extraction step. |
|
Union of multiple components. Runs all components and returns the union of their results as list. |
|
Run a component for each output element of a child. The operator is run in parallel and the results are flattened. |
API#
- class sammo.components.GenerateText(child: sammo.base.ScalarComponent, name=None, system_prompt: str | None = None, history: sammo.base.ScalarComponent | None = None, seed=0, randomness: float = 0, max_tokens=None, json_mode: bool = False, on_error: beartype.typing.Literal[raise, empty_result] = 'empty_result')#
Bases:
sammo.base.ScalarComponent
Call the LLM to generate a response.
- Parameters:
child â The child component to run.
name â The name of the component for later querying.
system_prompt â A system prompt to use.
history â A previous chat conversation to continue. Cannot be used with system_prompt.
seed â The local seed to use for caching. Needs to be changed if sampling from LLM multiple times.
randomness â The how deterministic the LLM output should be (typically corresponds to temperature).
max_tokens â The maximum number of tokens to generate, defaulting to max length supported by Runner.
on_error â What to do in case the text cannot be generated.
Initialization
- NEEDS_SCHEDULING = True#
- class sammo.components.Output(child: sammo.base.Component, minibatch_size=1, on_error: beartype.typing.Literal[raise, empty_result, backoff] = 'raise')#
Bases:
sammo.base.Component
Final output of a prompt pipeline. Runs the child component on each batch in the input and has an optional extraction step.
- Parameters:
child â The child component to run.
minibatch_size â Number of rows to pack into a single prompt.
Initialization
- run(runner: sammo.base.Runner, data: sammo.data.DataTable | list | None = None, progress_callback: beartype.typing.Callable | bool = True, priority: int = 0, on_error: beartype.typing.Literal[raise, empty_result, backoff] | None = None) sammo.data.DataTable #
Synchronous version of arun.
- n_minibatches(table: sammo.data.DataTable) int #
Return the number of minibatches that will be run on the given table.
- Parameters:
table â The DataTable to estimate minibatches on.
- async arun(runner: sammo.base.Runner, data: sammo.data.DataTable | list | None = None, progress_callback: beartype.typing.Callable | bool = True, priority: int = 0, on_error: beartype.typing.Literal[raise, empty_result, backoff] | None = None)#
Run the component asynchronously and return a DataTable with the results.
- Parameters:
runner â The runner to use.
data â The input data to run on. Can be empty.
progress_callback â Called after each minibatch. If True, shows default progress bar. If False, shows nothing.
priority â The priority to use for scheduling (highest by default).
on_error â The error handling strategy to use. Backoff re-runs the prompt with minibatch size 1.
- class sammo.components.Union(*children: sammo.base.Component, name: str | None = None)#
Bases:
sammo.base.ListComponent
Union of multiple components. Runs all components and returns the union of their results as list.
- Parameters:
children â The child components to run.
name â The name of the component for later querying.
Initialization
- class sammo.components.ForEach(loop_variable: str, child: sammo.base.ListComponent, operator: sammo.base.Component, name: str | None = None)#
Bases:
sammo.base.ListComponent
Run a component for each output element of a child. The operator is run in parallel and the results are flattened.
- Parameters:
loop_variable â The name of the variable to use for the loop.
child â The child component whose results are looped over.
operator â The operator to run for each element.
name â The name of the component for later querying.
Initialization
- NEEDS_SCHEDULING = True#