cuery.tools.flex.base#

Classes#

FlexTool

Base class for tools iterating over data records with arbitrary attributes.

Functions#

preprocess_records(records[, attrs, max_samples])

Sample and filter attributes/columns in records.

Module Contents#

cuery.tools.flex.base.preprocess_records(records, attrs=None, max_samples=None)#

Sample and filter attributes/columns in records.

Parameters:
  • records (pandas.DataFrame | list[dict])

  • attrs (list[str] | None)

  • max_samples (int | None)

Return type:

pandas.DataFrame

class cuery.tools.flex.base.FlexTool(/, **data)#

Bases: cuery.Tool

Base class for tools iterating over data records with arbitrary attributes.

Parameters:

data (Any)

model_config#

Needed to allow DataFrame and other non-Pydantic types.

records: pandas.DataFrame | list[dict]#

Data records to iterate over.

attrs: list[str] | None = None#

List of record attributes to use. If None, all attributes are used.

record_format: Literal['json', 'md', 'text'] = 'text'#

Format of the record in the prompt.

property template: str#

Get the name of the record template for the prompt.

Each record/row will be formatted into the prompt using this template.

Return type:

str

property context: list[dict]#

For each input record, returns an object with a single “record” key.

Jinja templates can then iterate over the “record” object’s attributes

Return type:

list[dict]

async __call__(**kwargs)#

Normalize the nested input records back into individual columns in output.

Return type:

pandas.DataFrame