Skip to content

Rewriters

Rewriters are pipeline components that transform and rewrite text content using language models. They can modify content style, format, tone, or structure while preserving meaning and important information.

datapizza.modules.rewriters.ToolRewriter

Bases: Rewriter

A tool-based query rewriter that uses LLMs to transform user queries through structured tool interactions.

a_rewrite async

a_rewrite(user_prompt, memory=None)

Parameters:

Name Type Description Default
user_prompt str

The user query to rewrite.

required
memory Memory | None

The memory to use for the rewrite.

None

Returns:

Type Description
str

The rewritten query.

rewrite

rewrite(user_prompt, memory=None)

Parameters:

Name Type Description Default
user_prompt str

The user query to rewrite.

required
memory Memory | None

The memory to use for the rewrite.

None

Returns:

Type Description
str

The rewritten query.

A rewriter that uses language models to transform text content with specific instructions and tools.

from datapizza.clients.openai import OpenAIClient
from datapizza.modules.rewriters import ToolRewriter

client = OpenAIClient(api_key="OPENAI_API_KEY", model="gpt-4o")

# Create a simplification rewriter
simplifier = ToolRewriter(
    client=client,
    system_prompt="You are an expert at simplifying complex text for general audiences.",
)

# Simplify technical content
technical_text = """
The algorithmic implementation utilizes a recursive binary search methodology
to optimize computational complexity in logarithmic time scenarios.
"""

simplified_text = simplifier(technical_text)
print(simplified_text)
# Output: recursive binary search

Features:

  • Flexible content transformation with custom instructions
  • Support for various rewriting tasks (summarization, style changes, format conversion)
  • Integration with tool calling for enhanced capabilities
  • Preserves important information while transforming presentation
  • Supports both sync and async processing
  • Configurable prompting for different rewriting strategies