cuery.tools.flex.topics#
Tools that work with flexible input contexts.
I.e. these tools accept context objects that have arbitrary numbers and types of fields. The Jinja prompt templates auto-convert these fields into the appropriate format for LLMs.
Attributes#
Classes#
Extract topics from records with arbitrary attributes. |
|
Assign topics to records with arbitrary attributes. |
|
Enforce correct multi-topic-subtopic assignment via a Pydantic model. |
Module Contents#
- cuery.tools.flex.topics.TOPICS_PROMPT = ''#
- cuery.tools.flex.topics.LABEL_PROMPT_SYSTEM = ''#
- cuery.tools.flex.topics.LABEL_PROMPT_USER = ''#
- cuery.tools.flex.topics.MULTI_LABEL_PROMPT_SYSTEM = ''#
- cuery.tools.flex.topics.MULTI_LABEL_PROMPT_USER = ''#
- class cuery.tools.flex.topics.TopicExtractor(/, **data)#
Bases:
cuery.tools.flex.base.FlexToolExtract topics from records with arbitrary attributes.
- Parameters:
data (Any)
- n_topics: int = None#
Approximate number of top-level topics to extract (maximum 20).
- n_subtopics: int = None#
Approximate number of subtopics per top-level topic (At least 2, maximum 10).
- instructions: str = ''#
Additional use-case specific instructions or context for the topic extraction.
- min_ldist: int = None#
Minimum Levenshtein distance between topic labels.
- max_samples: int = 500#
Maximum number of samples to use for topic extraction.
- record_format: Literal['attr_wise', 'rec_wise'] = 'attr_wise'#
Format of the records in the prompt.
- property response_model: cuery.ResponseClass#
Defines the response model for this tool (ClassVar or property).
- Return type:
cuery.ResponseClass
- property prompt: cuery.Prompt#
Defines the prompt for this tool (ClassVar or property).
- Return type:
- property context: dict#
Override FlexTool base implementation.
This tool is different because it doesn’t iterate over records, but rather processes them all at once to extract topics.
- Return type:
dict
- async __call__(**kwargs)#
Normalize the nested input records back into individual columns in output.
- Return type:
- class cuery.tools.flex.topics.TopicAssigner(/, **data)#
Bases:
cuery.tools.flex.base.FlexToolAssign topics to records with arbitrary attributes.
- Parameters:
data (Any)
- topics: cuery.tools.topics.Topics#
Topics and subtopics to use for assignment, either as a Topics object or a dict.
- instructions: str = ''#
Additional use-case specific instructions or context for the topic extraction.
- SYSTEM_PROMPT: ClassVar[str] = ''#
- USER_PROMPT: ClassVar[str] = ''#
- classmethod validate_topics(topics)#
- Return type:
- property prompt: cuery.Prompt#
Defines the prompt for this tool (ClassVar or property).
- Return type:
- property response_model: cuery.ResponseClass#
Defines the response model for this tool (ClassVar or property).
- Return type:
cuery.ResponseClass
- class cuery.tools.flex.topics.MultiTopicAssigner(/, **data)#
Bases:
TopicAssignerEnforce correct multi-topic-subtopic assignment via a Pydantic model.
- Parameters:
data (Any)
- SYSTEM_PROMPT: ClassVar[str] = ''#
- USER_PROMPT: ClassVar[str] = ''#
- property response_model: cuery.ResponseClass#
Defines the response model for this tool (ClassVar or property).
- Return type:
cuery.ResponseClass