Metadata-Version: 2.4
Name: iil-chat-logging
Version: 0.2.0
Summary: Persistent chat conversation logging & QM for Django apps
Author: Achim Dehnert
License: MIT
Requires-Python: >=3.11
Requires-Dist: chat-agent>=0.1.0
Requires-Dist: django>=5.0
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
Requires-Dist: pytest-django>=4.8; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.1; extra == 'dev'
Provides-Extra: eval
Requires-Dist: deepeval>=1.0; extra == 'eval'
Requires-Dist: langfuse>=2.0; extra == 'eval'
Description-Content-Type: text/markdown

# chat-logging

Persistent chat conversation logging & quality management for Django apps.

Part of the platform ecosystem (ADR-037). Works with any app using `chat-agent`.

## Features

- **ChatConversation + ChatMessage** — Full conversation persistence
- **UseCaseCandidate** — Track unmet user needs
- **EvaluationScore** — Store evaluation metrics (DeepEval, LangFuse)
- **LoggingSessionBackend** — Drop-in wrapper for any SessionBackend
- **Django Admin** — Filter, search, review, export conversations

## Installation

```bash
pip install chat-logging
```

Add to `INSTALLED_APPS`:

```python
INSTALLED_APPS = [
    ...
    "chat_logging",
]
```

Run migrations:

```bash
python manage.py migrate chat_logging
```

## Usage

```python
from chat_agent import ChatAgent, InMemorySessionBackend
from chat_logging import LoggingSessionBackend

backend = LoggingSessionBackend(
    wrapped=InMemorySessionBackend(),
    app_name="drifttales",
    user=request.user,
)

agent = ChatAgent(
    toolkit=my_toolkit,
    completion=my_backend,
    session_backend=backend,  # conversations are now logged!
    system_prompt="...",
)
```

## Export

```python
from chat_logging.exporters import (
    export_conversations_csv,
    export_conversations_jsonl,
)
from chat_logging.models import ChatConversation

qs = ChatConversation.objects.filter(app_name="drifttales")
jsonl = export_conversations_jsonl(qs)
csv_data = export_conversations_csv(qs)
```
