Metadata-Version: 2.4
Name: lexigram-ai-feedback
Version: 0.1.1
Summary: AI feedback collection for the Lexigram Framework — collection, processing, and storage
Project-URL: Homepage, https://github.com/lexigram-dev/lexigram
Project-URL: Repository, https://github.com/lexigram-dev/lexigram
Project-URL: Documentation, https://docs.lexigram.dev
Project-URL: Issues, https://github.com/lexigram-dev/lexigram/issues
Project-URL: Changelog, https://github.com/lexigram-dev/lexigram/blob/main/CHANGELOG.md
Author-email: Lexigram Framework Team <team@lexigram.dev>
Maintainer-email: Lexigram Framework Team <team@lexigram.dev>
License: MIT
License-File: LICENSE
Keywords: ai,ai-feedback,async,feedback,framework,lexigram,python,rlhf
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: lexigram-contracts>=0.1.0
Requires-Dist: lexigram>=0.1.1
Requires-Dist: typing-extensions>=4.0.0
Provides-Extra: dev
Requires-Dist: mypy>=1.0.0; extra == 'dev'
Requires-Dist: ruff>=0.8.0; extra == 'dev'
Provides-Extra: test
Requires-Dist: lexigram-testing>=0.1.1; extra == 'test'
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'test'
Requires-Dist: pytest-cov>=4.0.0; extra == 'test'
Requires-Dist: pytest-mock>=3.10.0; extra == 'test'
Requires-Dist: pytest>=8.0.0; extra == 'test'
Description-Content-Type: text/markdown

# lexigram-ai-feedback

AI feedback collection for the Lexigram Framework — collection, processing, and storage

---

## Overview

AI feedback collection and continuous-learning loop for the Lexigram Framework. Captures user ratings, corrections, text feedback, and ground-truth labels from LLM interactions and routes them through an extensible processor pipeline to configurable storage backends. Zero-config usage starts with sensible defaults.


> Full documentation: [docs.lexigram.dev](https://docs.lexigram.dev)
## Install

```bash
uv add lexigram-ai-feedback
```

## Quick Start

```python
from lexigram import Application
from lexigram.di.module import Module, module

from lexigram.ai.feedback import FeedbackModule
from lexigram.ai.feedback.config import FeedbackConfig

@module(imports=[
    FeedbackModule.configure(
        FeedbackConfig(
            enabled=True,
            async_processing=True,
            store_raw_payloads=False,
        )
    )
])
class AppModule(Module):
    pass

app = Application(modules=[AppModule])
if __name__ == "__main__":
    app.run()
```

## Configuration

> **Zero-config usage:** Call `FeedbackModule.configure()` with no arguments to use defaults.

### Option 1 — YAML file

```yaml
# application.yaml
ai_feedback:
  enabled: true
  async_processing: true
  store_raw_payloads: false
```

### Option 2 — Profiles + Environment Variables *(recommended)*

```bash
export LEX_AI_FEEDBACK__ENABLED=true
# Environment variables for each field
```

### Option 3 — Python

```python
from lexigram.ai.feedback.config import FeedbackConfig
from lexigram.ai.feedback import FeedbackModule

config = FeedbackConfig(
    enabled=True,
    async_processing=True,
    store_raw_payloads=False,
)
FeedbackModule.configure(config)
```

### Config reference

| Field | Default | Env var | Description |
|-------|---------|---------|-------------|
| `enabled` | `True` | `LEX_AI_FEEDBACK__ENABLED` | Master on/off switch for all feedback collection |
| `async_processing` | `True` | `LEX_AI_FEEDBACK__ASYNC_PROCESSING` | Process feedback handlers asynchronously in the background |
| `store_raw_payloads` | `False` | `LEX_AI_FEEDBACK__STORE_RAW_PAYLOADS` | Persist raw incoming feedback payloads for auditing |

## Module Factory Methods

| Method | Description |
|--------|-------------|
| `FeedbackModule.configure(config)` | Configure with explicit config |
| `FeedbackModule.stub()` | Minimal config for testing |

## Key Features

- **Four feedback types**: Rating, free-text, correction (original → corrected), and ground-truth labels
- **Extensible processor pipeline**: Custom processors via `FeedbackProcessorRegistry`
- **Storage backends**: In-memory, database (`DatabaseFeedbackStore`), and cache (`CachedFeedbackStore`)
- **Middleware integration**: `FeedbackMiddleware` and `FeedbackContext` for request/response capture
- **Lifecycle hooks**: `FeedbackSubmittedHook`, `FeedbackProcessedHook`, `FeedbackStoredHook`

## Testing

```python
async with Application.boot(modules=[FeedbackModule.stub()]) as app:
    # your test code
    ...
```

## Key Source Files

| File | What it contains |
|------|-----------------|
| `src/lexigram/ai/feedback/module.py` | `FeedbackModule.configure()`, `.stub()` |
| `src/lexigram/ai/feedback/config.py` | `FeedbackConfig` |
| `src/lexigram/ai/feedback/services/collector.py` | `FeedbackCollector` core service |
| `src/lexigram/ai/feedback/storage/database.py` | `DatabaseFeedbackStore` |
| `src/lexigram/ai/feedback/storage/cache.py` | `CachedFeedbackStore` |
| `src/lexigram/ai/feedback/processors/processor_registry.py` | `FeedbackProcessorRegistry` |
| `src/lexigram/ai/feedback/di/provider.py` | `FeedbackProvider` boot and registration |
