Refiner Class
The Refiner class is the core pipeline builder that allows you to chain multiple operations together.
prompt_refiner.refiner.Refiner
Bases: ABC
Base class for all prompt refining operations.
Functions
process
abstractmethod
Process the input text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input text to process |
required |
Returns:
| Type | Description |
|---|---|
str
|
The processed text |
__or__
Support pipe operator syntax for composing refiners.
Enables LangChain-style pipeline composition: refiner1 | refiner2 | refiner3
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Refiner
|
The refiner to chain with this refiner |
required |
Returns:
| Type | Description |
|---|---|
Pipeline
|
A Pipeline containing both refiners |
Example
from prompt_refiner import StripHTML, NormalizeWhitespace pipeline = StripHTML() | NormalizeWhitespace() result = pipeline.run("
hello")Returns: "hello"
Source code in src/prompt_refiner/refiner.py
Usage Examples
Pipe Operator (Recommended)
from prompt_refiner import StripHTML, NormalizeWhitespace
# Create a pipeline using the pipe operator
pipeline = (
StripHTML()
| NormalizeWhitespace()
)
# Execute the pipeline
result = pipeline.run("<p>Hello World!</p>")
print(result) # "Hello World!"
Fluent API with .pipe()
The Refiner class supports method chaining with .pipe():
from prompt_refiner import Refiner, StripHTML, NormalizeWhitespace
# Create a pipeline using the fluent API
pipeline = (
Refiner()
.pipe(StripHTML())
.pipe(NormalizeWhitespace())
)
# Execute the pipeline
result = pipeline.run("<p>Hello World!</p>")
print(result) # "Hello World!"
Both approaches work identically - choose the one that fits your style.
Pipeline Execution
When you call run(text), the Refiner:
- Takes the input text
- Passes it through each operation in sequence
- Each operation's output becomes the next operation's input
- Returns the final processed text