cuery.tools.flex ================ .. py:module:: cuery.tools.flex .. autoapi-nested-parse:: Flex tools (flexible tools) are tools with flexible inputs. Instead of expecting a fixed set of attributes in input records (DataFrame rows), which are validated on execution, and mapped to specific substitutions in prompt templates, flexible tools allow data records with arbitrary attributes. Each record is essentially an object/dict with a single "record" key and a nested object as value, which in turn can have arbitrary data. Prompts are dynamically generated from Jinja templates based on the attributes present in the input records. Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/cuery/tools/flex/base/index /autoapi/cuery/tools/flex/classify/index /autoapi/cuery/tools/flex/entities/index /autoapi/cuery/tools/flex/generic/index /autoapi/cuery/tools/flex/score/index /autoapi/cuery/tools/flex/topics/index Classes ------- .. autoapisummary:: cuery.tools.flex.Classifier cuery.tools.flex.EntityExtractor cuery.tools.flex.Scorer cuery.tools.flex.MultiTopicAssigner cuery.tools.flex.TopicAssigner cuery.tools.flex.TopicExtractor Package Contents ---------------- .. py:class:: Classifier(/, **data) Bases: :py:obj:`cuery.tools.flex.base.FlexTool` Zero-shot classify a data record with arbitrary attributes. .. py:attribute:: categories :type: dict[str, str] Dictionary of category labels and their descriptions. .. py:attribute:: instructions :type: str :value: '' Additional instructions (context) for the classification task. .. py:property:: prompt :type: cuery.Prompt Defines the prompt for this tool (ClassVar or property). .. py:property:: response_model :type: cuery.ResponseClass Defines the response model for this tool (ClassVar or property). .. py:class:: EntityExtractor(/, **data) Bases: :py:obj:`cuery.tools.flex.base.FlexTool` "Extract SEO-relevant entities from Google SERP AI Overview data. .. py:attribute:: entities :type: dict[str, str] Dictionary of entity names/categories and their descriptions. .. py:property:: prompt :type: cuery.Prompt Defines the prompt for this tool (ClassVar or property). .. py:property:: response_model :type: cuery.ResponseClass Defines the response model for this tool (ClassVar or property). .. py:method:: __call__(**kwargs) :async: Normalize the nested input records back into individual columns in output. .. py:class:: Scorer(/, **data) Bases: :py:obj:`cuery.tools.flex.base.FlexTool` Classify intent for keywords based on their SERP results. .. py:attribute:: name :type: str Name of the score to assign. .. py:attribute:: type :type: Literal['integer', 'float'] :value: 'float' Whether to return the score as integer or float. .. py:attribute:: min :type: float Minimum value of the score. .. py:attribute:: max :type: float Maximum value of the score. .. py:attribute:: description :type: str Description of the score to assign. .. py:method:: validate_name(name) :classmethod: Ensure the name is a valid Python identifier. .. py:property:: scorer_params :type: dict Get the parameters for the score model. .. py:property:: prompt :type: cuery.Prompt Defines the prompt for this tool (ClassVar or property). .. py:property:: response_model :type: cuery.ResponseClass Defines the response model for this tool (ClassVar or property). .. py:class:: MultiTopicAssigner(/, **data) Bases: :py:obj:`TopicAssigner` Enforce correct multi-topic-subtopic assignment via a Pydantic model. .. py:attribute:: SYSTEM_PROMPT :type: ClassVar[str] :value: '' .. py:attribute:: USER_PROMPT :type: ClassVar[str] :value: '' .. py:property:: response_model :type: cuery.ResponseClass Defines the response model for this tool (ClassVar or property). .. py:class:: TopicAssigner(/, **data) Bases: :py:obj:`cuery.tools.flex.base.FlexTool` Assign topics to records with arbitrary attributes. .. py:attribute:: topics :type: cuery.tools.topics.Topics Topics and subtopics to use for assignment, either as a Topics object or a dict. .. py:attribute:: instructions :type: str :value: '' Additional use-case specific instructions or context for the topic extraction. .. py:attribute:: SYSTEM_PROMPT :type: ClassVar[str] :value: '' .. py:attribute:: USER_PROMPT :type: ClassVar[str] :value: '' .. py:method:: validate_topics(topics) :classmethod: .. py:property:: prompt :type: cuery.Prompt Defines the prompt for this tool (ClassVar or property). .. py:property:: response_model :type: cuery.ResponseClass Defines the response model for this tool (ClassVar or property). .. py:class:: TopicExtractor(/, **data) Bases: :py:obj:`cuery.tools.flex.base.FlexTool` Extract topics from records with arbitrary attributes. .. py:attribute:: n_topics :type: int :value: None Approximate number of top-level topics to extract (maximum 20). .. py:attribute:: n_subtopics :type: int :value: None Approximate number of subtopics per top-level topic (At least 2, maximum 10). .. py:attribute:: instructions :type: str :value: '' Additional use-case specific instructions or context for the topic extraction. .. py:attribute:: min_ldist :type: int :value: None Minimum Levenshtein distance between topic labels. .. py:attribute:: max_samples :type: int :value: 500 Maximum number of samples to use for topic extraction. .. py:attribute:: record_format :type: Literal['attr_wise', 'rec_wise'] :value: 'attr_wise' Format of the records in the prompt. .. py:property:: response_model :type: cuery.ResponseClass Defines the response model for this tool (ClassVar or property). .. py:property:: prompt :type: cuery.Prompt Defines the prompt for this tool (ClassVar or property). .. py:property:: context :type: 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. .. py:method:: __call__(**kwargs) :async: Normalize the nested input records back into individual columns in output.