nat.plugins.langchain.eval.langsmith_evaluator_adapter#
Classes#
Detected evaluator calling convention. |
|
NAT evaluator adapter that wraps a LangSmith/openevals evaluator callable. |
Functions#
|
Invoke fn with the given arguments, adapting sync callables to async. |
Module Contents#
- class _EvaluatorConvention#
Bases:
enum.StrEnumDetected evaluator calling convention.
Initialize self. See help(type(self)) for accurate signature.
- RUN_EVALUATOR_CLASS = 'run_evaluator_class'#
- RUN_EXAMPLE_FUNCTION = 'run_example_function'#
- OPENEVALS_FUNCTION = 'openevals_function'#
- async _invoke_maybe_sync(fn: collections.abc.Callable[Ellipsis, Any], *args: Any, \*\*kwargs: Any) Any#
Invoke fn with the given arguments, adapting sync callables to async.
If fn is a coroutine function it is awaited directly. Otherwise it is dispatched to the default executor so that it never blocks the event loop.
The current
contextvarscontext is explicitly copied into the executor thread so that caller-side context managers (e.g.,tracing_context(enabled=False)) remain effective.
- class LangSmithEvaluatorAdapter(
- evaluator: Any,
- convention: str,
- max_concurrency: int = 4,
- evaluator_name: str = 'langsmith',
- extra_fields: dict[str, str] | None = None,
- score_field: str | None = None,
Bases:
nat.plugins.eval.evaluator.base_evaluator.BaseEvaluatorNAT evaluator adapter that wraps a LangSmith/openevals evaluator callable.
Adapts various LangSmith evaluator calling conventions into NAT’s
BaseEvaluatorinterface:RunEvaluator: calls
aevaluate_runwith synthetic Run/Example objects(run, example)functions: constructs synthetic Run/Example objects(inputs, outputs, reference_outputs)functions: passes kwargs directly
All evaluator calls are wrapped in
tracing_context(enabled=False)so that LangSmith auto-tracing does not produce unintended traces. NAT’s own observability pipeline (OTEL-based LangSmith exporter) handles tracing separately.- _evaluator#
- _extra_fields = None#
- _score_field = None#
- async evaluate_item( ) nat.data_models.evaluator.EvalOutputItem#
Evaluate a single item using the wrapped evaluator.
- async _call_run_evaluator( ) Any#
Call a RunEvaluator subclass instance via
aevaluate_run.
- async _call_run_example_function( ) Any#
Call a function with
(run, example)signature.
- async _call_openevals_function( ) Any#
Call a function with
(inputs, outputs, reference_outputs)signature.