Metadata-Version: 2.1
Name: trulens-apps-gepa
Version: 2.8.1
Summary: Library to systematically track and evaluate LLM based applications.
Home-page: https://trulens.org/
License: MIT
Author: Snowflake Inc.
Author-email: ml-observability-wg-dl@snowflake.com
Requires-Python: >=3.9,<4.0
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: trulens-core (>=2.0.0,<3.0.0)
Project-URL: Documentation, https://trulens.org/getting_started/
Project-URL: Repository, https://github.com/truera/trulens
Description-Content-Type: text/markdown

# trulens-apps-gepa

TruLens adapter for GEPA (Genetic/Evolutionary Prompt Adaptation).

GEPA optimizes prompts using evolutionary algorithms. This package provides
`TruGEPA`, a thin adapter that wraps any TruLens feedback callable as a
GEPA-compatible fitness function and automatically logs every evaluation as a
`TruVirtual` record for dashboard visibility, plus a simple `run_evolution`
helper that implements the evolutionary loop.

## Installation

```bash
pip install trulens-apps-gepa
```

## Quick start

```python
from trulens.apps.gepa import TruGEPA, run_evolution

def my_relevance(prompt: str) -> float:
    return len(prompt) / 200  # replace with a real TruLens provider method

# Without logging:
fitness = TruGEPA(my_relevance, optimize_key="prompt")

# With logging — supply both app_name and app_version (omit both to disable;
# supplying only one raises a ValueError immediately):
from trulens.core import TruSession
session = TruSession()

fitness = TruGEPA(
    my_relevance,
    optimize_key="prompt",
    app_name="my_optimizer",
    app_version="v1",
)

# Works with any feedback signature — e.g. context_relevance(question, context):
# fitness = TruGEPA(
#     provider.context_relevance,
#     optimize_key="question",
#     feedback_args={"context": REFERENCE_CONTEXT},
# )

best_prompt, best_score, history = run_evolution(
    base_prompt="Summarize the document.",
    fitness_fn=fitness,
    mutate_fn=lambda p: p + " Be concise.",
    n_generations=5,
    population_size=4,
)
print(f"Best prompt ({best_score:.3f}): {best_prompt}")
```

When both `app_name` and `app_version` are provided, a `TruVirtual` recorder
is created automatically and every evaluation is logged. Omit both to run
without any logging.

