sammo.components

sammo.components#

Module Contents#

Classes#

GenerateText

Call the LLM to generate a response.

Output

Final output of a prompt pipeline. Runs the child component on each batch in the input and has an optional extraction step.

Union

Union of multiple components. Runs all components and returns the union of their results as list.

ForEach

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#