Skip to main content

fabricatio-tagging

MIT Python Versions PyPI Version PyPI Downloads PyPI Downloads Build Tool: uv

LLM-powered tag generation for text content. Part of the Fabricatio agent framework.

Installation

This package is part of the fabricatio monorepo and can be installed as an optional dependency using either pip or uv:

pip install fabricatio[tagging]
# or
uv pip install fabricatio[tagging]

For a full installation that includes this package and all other components of fabricatio:

pip install fabricatio[full]
# or
uv pip install fabricatio[full]

Overview

fabricatio-tagging provides a Tagging mixin class that uses LLMs to generate descriptive tags from text. It accepts a single string or a list of strings and returns corresponding tag lists, driven by a configurable Handlebars template.

The package extends Propose from fabricatio-core, so any role class that mixes in Tagging gains the tagging() method alongside existing proposal capabilities.

Key Classes

Tagging (fabricatio_tagging.capabilities.tagging)

A mixin extending Propose that adds the tagging() async method.

Method Signature Returns Description
tagging (text: str, requirement: str = "", k: int = 0, **kwargs) -> List[str] | None Tag list or None Generate tags for a single string. Returns None if generation fails.
tagging (text: List[str], requirement: str = "", k: int = 0, **kwargs) -> List[List[str]] List of tag lists Generate tags for multiple strings. Each inner list corresponds to one input text.

Parameters:

Parameter Type Default Description
text str | List[str] (required) Input text(s) to tag
requirement str "" Additional constraints for tag generation
k int 0 Maximum number of tags per text (0 = no limit)
**kwargs Unpack[LLMKwargs] Generation parameters passed to the underlying LLM

Raises TypeError if text is neither a str nor a List[str].

TaggingConfig (fabricatio_tagging.config)

Frozen dataclass controlling which Handlebars template is used for tag generation.

Field Default Description
tagging_template "built-in/tagging" Template name resolved by TEMPLATE_MANAGER

Access via the singleton:

from fabricatio_tagging.config import tagging_config
print(tagging_config.tagging_template)

Usage

Mixin Tagging into a role class and call tagging():

import asyncio
from fabricatio_core.capabilities.propose import Propose
from fabricatio_tagging.capabilities.tagging import Tagging


class MyRole(Propose, Tagging):
    """A role that can generate tags."""
    pass


async def main():
    role = MyRole(name="tagger")

    # Tag a single string
    tags = await role.tagging("Python is a high-level programming language.")
    print(tags)  # e.g. ["python", "programming", "language"]

    # Tag with requirements and a cap
    tags = await role.tagging(
        "Rust is a systems language.",
        requirement="use lowercase technical tags only",
        k=3,
    )
    print(tags)  # e.g. ["rust", "systems", "memory-safety"]

    # Tag multiple strings in a batch
    batch_tags = await role.tagging([
        "Django is a Python web framework.",
        "Tokio is an async runtime for Rust.",
    ])
    print(batch_tags)  # e.g. [["python", "web", "django"], ["rust", "async", "tokio"]]


asyncio.run(main())

The requirement parameter provides natural-language guidance to the LLM (e.g. "use single words only", "tag by topic and difficulty level"). The k parameter limits the number of tags returned per text.

Configuration

All options below are read through the fabricatio configuration chain (see the Configuration Guide). Set them under the [ext.tagging] table in fabricatio.toml, equivalently under [tool.fabricatio.ext.tagging] in pyproject.toml, or via FABRICATIO_EXT__TAGGING__<FIELD_UPPER> environment variables.

[ext.tagging]
tagging_template = "built-in/tagging"
Option Type Default Description
tagging_template str "built-in/tagging" The template to use for tagging.

Access at runtime: from fabricatio_tagging.config import tagging_config.

Dependencies

  • fabricatio-core — Core interfaces, Propose capability, template manager, and configuration system.

No additional dependencies.

License

MIT – see LICENSE

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fabricatio_tagging-0.1.7-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file fabricatio_tagging-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: fabricatio_tagging-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fabricatio_tagging-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 20bc37f1a7a355ca38b68c6e7a8d6872a4a769b6cba7fe7c8f0d0352c98a70b0
MD5 5c0eb5f600ef1560532535831b88ddb8
BLAKE2b-256 0e8d1324e748b3b581e73b3849ef74159dcde32d0cb33f1d943e511ae725ef45

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.7 This release

1 file

0.1.6

1 file

0.1.4

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

1 file

0.1.0

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page