Skip to main content

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

pip install trulens-apps-gepa

Quick start

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trulens_apps_gepa-2.12.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trulens_apps_gepa-2.12.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file trulens_apps_gepa-2.12.0.tar.gz.

File metadata

  • Download URL: trulens_apps_gepa-2.12.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for trulens_apps_gepa-2.12.0.tar.gz
Algorithm Hash digest
SHA256 7c6bf668f8fedf6a29ccc78e385b0ba9a7a31e0b2a7d334d2e67d7fdc58cc208
MD5 8c8aebc7ef73cb3d083680b2f6593df3
BLAKE2b-256 299b0abba7db1ff6bbb6cb069a36aa5e8c7bcf19d4b4375d2fd216d33a6d0f17

See more details on using hashes here.

File details

Details for the file trulens_apps_gepa-2.12.0-py3-none-any.whl.

File metadata

File hashes

Hashes for trulens_apps_gepa-2.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 339315ab3840567d1fa5ca1f70d114b9ffef97c8c515961625562214801dd6b7
MD5 097aff29cc6d21f84856c88ebeb92e5a
BLAKE2b-256 cdacec95a569425438f08ec0ea48d0b6be42b57d2ac8e2990715c59bf090543f

See more details on using hashes here.

Release history Release notifications | RSS feed

2.13.1

2 files

2.13.0

2 files

This release

2.12.0 This release

2 files

2.11.0

2 files

2.10.0

2 files

2.9.0

2 files

2.8.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page