get_log_context
gepa.gepa_launcher.get_log_context() -> LogContext
Return the active log context for the current evaluator call.
Use this to propagate oa.log() capture to child threads spawned
inside your evaluator::
text
import threading
import gepa.gepa_launcher as oa
def my_evaluator(candidate):
ctx = oa.get_log_context()
def worker():
oa.set_log_context(ctx)
oa.log("from child thread")
t = threading.Thread(target=worker)
t.start()
t.join()
oa.log("from main evaluator thread")
return scoreRaises:
| Type | Description |
|---|---|
RuntimeError | If called outside an evaluator invocation. |
Source code in gepa/gepa_launcher.py
text
def get_log_context() -> LogContext:
"""Return the active log context for the current evaluator call.
Use this to propagate ``oa.log()`` capture to child threads spawned
inside your evaluator::
import threading
import gepa.gepa_launcher as oa
def my_evaluator(candidate):
ctx = oa.get_log_context()
def worker():
oa.set_log_context(ctx)
oa.log("from child thread")
t = threading.Thread(target=worker)
t.start()
t.join()
oa.log("from main evaluator thread")
return score
Raises:
RuntimeError: If called outside an evaluator invocation.
"""
ctx = _get_log_context()
if ctx is None:
raise RuntimeError(
"No active log context. get_log_context() must be called inside an evaluator passed to optimize_anything()."
)
return ctx