Skip to main content

An extension of fabricatio, provide capalability to tag on data.

Project description

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()

    # 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

The default template "built-in/tagging" is registered by fabricatio-core. Override it by loading a custom template and updating the config:

from fabricatio_core import TEMPLATE_MANAGER
from fabricatio_tagging.config import tagging_config

# Register a custom Handlebars template
TEMPLATE_MANAGER.register_template("my-tags", "Generate {{k}} tags for: {{text}}. {{requirement}}")

# Point config at it
object.__setattr__(tagging_config, "tagging_template", "my-tags")

Dependencies

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

No additional dependencies.

License

MIT – see LICENSE

Project details


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.5.dev0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file fabricatio_tagging-0.1.5.dev0-py3-none-any.whl.

File metadata

  • Download URL: fabricatio_tagging-0.1.5.dev0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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.5.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e01632ed0448abc15c0eac67a5478a7cc90bc59d1da3b7d7b161293d15c05e5
MD5 f5a62dd25e04df0231f5d70302fa15ee
BLAKE2b-256 619ea03a5ec50b4d66abb0cb40820a579eb505bdb0a51d401fd2b72c824ea649

See more details on using hashes here.

Supported by

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