cognition.language.population

Filling a data structure with values based upon natural language input

Classes

ModelPopulator

Function to instantiate a model with values based upon an utterance

Module Contents

class cognition.language.population.ModelPopulator[T: pydantic.BaseModel](model_type, task_desc)

Function to instantiate a model with values based upon an utterance

Parameters:
  • model_type (type[T]) – type needing instantiation

  • task_desc (str | None) – textual description of the task

prompt(utterance, *extra)

Produces the prompt for a supplied utterance

Parameters:
  • utterance (str) – user input

  • extra (str) – dynamic extra context to supply

Returns:

resulting filler llm prompt

Return type:

str

__call__(utterance, llm, *extra, timeout_secs=10)

Produces a model instance based upon a timeout budget.

Parameters:
  • utterance (str) – text to instantiate

  • llm (pydantic_ai.models.Model) – textual model to utilize

  • extra (str) – dynamic extra context to supply

  • timeout_secs (int)

Timeout_secs:

time given per LLM call

Returns:

model instance

Return type:

T

classmethod populate(utterance, model_type, llm, task_desc, *extra, timeout_secs=10)

One-off instantiation and calling of a populator

Parameters:
  • utterance (str) – text to classify

  • model_type (type[T]) – type needing instantiation

  • llm (pydantic_ai.models.Model) – textual model to utilize

  • task_desc (str | None) – textual description of the task

  • extra (str) – dynamic extra context to supply

  • timeout_secs (int)

Timeout_secs:

time given per LLM call

Returns:

most common classification with confidence

Return type:

T