Metadata-Version: 2.4
Name: fabricatio-improve
Version: 0.1.11
Summary: A Python library for content review, correction, and improvement in LLM applications.
Project-URL: Homepage, https://github.com/Whth/fabricatio
Project-URL: Repository, https://github.com/Whth/fabricatio
Project-URL: Issues, https://github.com/Whth/fabricatio/issues
Author-email: Whth <zettainspector@foxmail.com>
License: MIT License
        
        Copyright (c) 2025 Whth Yotta
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Requires-Python: <3.15,>=3.12
Requires-Dist: fabricatio-capabilities
Requires-Dist: fabricatio-core
Requires-Dist: fabricatio-question
Description-Content-Type: text/markdown

# `fabricatio-improve`

[MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![Python Versions](https://img.shields.io/pypi/pyversions/fabricatio-improve)
[![PyPI Version](https://img.shields.io/pypi/v/fabricatio-improve)](https://pypi.org/project/fabricatio-improve/)
[![PyPI Downloads](https://static.pepy.tech/badge/fabricatio-improve/week)](https://pepy.tech/projects/fabricatio-improve)
[![PyPI Downloads](https://static.pepy.tech/badge/fabricatio-improve)](https://pepy.tech/projects/fabricatio-improve)
[![Build Tool: uv](https://img.shields.io/badge/built%20with-uv-orange)](https://github.com/astral-sh/uv)

A Python library for content review, correction, and improvement in LLM applications.

## 📦 Installation

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

```bash
pip install fabricatio[improve]
# or
uv pip install fabricatio[improve]
```

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

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

## 🔍 Overview

Provides tools for:

- Content review and problem detection
  The content review and problem detection tool analyzes the input text to identify various issues. It uses natural
  language processing techniques to check for grammar errors, spelling mistakes, and semantic inconsistencies. For
  example, it can detect incorrect word usage, missing punctuation, and unclear sentence structures. It also looks for
  logical problems in the content, such as contradictions or incomplete arguments.
- Problem-solution pair generation
  Once problems are detected, this feature generates appropriate solutions. It takes into account the nature of the
  problem and the context of the text. For grammar and spelling errors, it can suggest the correct words or phrases. For
  semantic issues, it can propose alternative ways to express the ideas. The solutions are presented in a clear and
  actionable format, making it easy for users to implement them.
- Text correction and refinement
  The text correction and refinement tool applies the generated solutions to the original text. It not only fixes the
  identified problems but also refines the overall quality of the text. This includes improving the readability, style,
  and coherence of the content. For example, it can rephrase sentences to make them more concise and clear, and adjust
  the tone of the text to be more appropriate for the intended audience.
- Improvement prioritization based on severity
  This feature prioritizes the detected problems based on their severity. It assigns a severity level to each problem,
  taking into account factors such as the impact on the meaning of the text, the frequency of occurrence, and the
  importance of the context. High - severity problems are given higher priority, ensuring that users focus on fixing the
  most critical issues first.
- Interactive feedback loops with users
  The interactive feedback loops allow users to participate in the improvement process. After the initial analysis and
  solution generation, the tool presents the problems and solutions to the users. Users can then provide their own
  feedback, accept or reject the proposed solutions, and suggest alternative approaches. This iterative process ensures
  that the final improved text meets the users' expectations.

Built on top of Fabricatio's agent framework with support for asynchronous execution.

## 🧩 Usage Example

```python
from fabricatio_improve.capabilities.correct import Correct
The `Correct` class is the core component for text correction. It uses a set of pre - trained models and rules to analyze the input text and generate correction suggestions. It can handle different types of text, including articles, reports, and emails.
from fabricatio_improve.models.improve import Improvement
The `Improvement` model represents the overall result of the text improvement process. It contains information about the detected problems, the proposed solutions, and the severity levels of each problem. It also provides methods for accessing and manipulating this information.
from fabricatio_improve.models.problem import Problem, Solution
The `Problem` class represents a detected issue in the text. It includes attributes such as the description of the problem, its location in the text, and its severity level. The `Solution` class represents the proposed solution for a problem. It contains the description of the solution and the steps to implement it.


async def improve_content():
    # Initialize corrector
    corrector = Correct()

    # Sample problematic text
    text = "Ths txt has many speling erors."

    # Get improvement suggestions
    improvement: Improvement = await corrector.correct(text)

    print(f"Found {len(improvement.problem_solutions)} issues:")
    for ps in improvement.problem_solutions:
        print(f"\nProblem: {ps.problem.description}")
        print(f"Location: {ps.problem.location}")
        print(f"Severity: {ps.problem.severity_level}/10")
        print(f"Solution: {ps.solution.description}")
        print(f"Steps: {', '.join(ps.solution.execute_steps)}")
```

## 📁 Structure

```
fabricatio-improve/
├── capabilities/     - Core improvement functionality
│   ├── correct.py    - Text correction capabilities
│   └── review.py     - Content review capabilities
└── models/           - Data models for improvements
    ├── improve.py    - Improvement result model
    ├── kwargs_types.py - Validation argument types
    └── problem.py    - Problem-solution pair definitions
```

## 🔗 Dependencies

Built on top of other Fabricatio modules:

- `fabricatio-core` - Core interfaces and utilities
- `fabricatio-capabilities` - Base capability patterns

## 📄 License

MIT – see [LICENSE](../../LICENSE)

