Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/humanloop/eval_utils/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,19 @@ def _overloaded_log(
CreateFlowLogResponse,
CreateEvaluatorLogResponse,
]:
evaluation_context = evaluation_context_variable.get()
try:
evaluation_context = evaluation_context_variable.get()
except LookupError:
# If the Evaluation Context is not set, an Evaluation is not running
evaluation_context = None

if _is_evaluated_file(
evaluation_context=evaluation_context, # type: ignore
log_args=kwargs,
):
# If the .log API user does not provide the source_datapoint_id or run_id,
# override them with the values from the EvaluationContext
# _is_evaluated_file ensures that evaluation_context is not None
evaluation_context = typing.cast(
EvaluationContext,
evaluation_context,
Expand All @@ -157,7 +162,7 @@ def _overloaded_log(
log_args=kwargs,
):
# Notify that the Log has been added to the Evaluation
# evaluation_context cannot be None
# _is_evaluated_file ensures that evaluation_context is not None
evaluation_context = typing.cast(
EvaluationContext,
evaluation_context,
Expand Down Expand Up @@ -463,6 +468,7 @@ def upload_callback(log: dict):
"process_datapoint on Thread %s: evaluating Datapoint %s with EvaluationContext %s",
threading.get_ident(),
datapoint_dict,
# .get() is safe since process_datapoint is always called in the context of an Evaluation
evaluation_context_variable.get(),
)
log_func = _get_log_func(
Expand Down Expand Up @@ -495,6 +501,7 @@ def upload_callback(log: dict):
# throw error if it fails to serialize
raise ValueError(f"Your {type_}'s `callable` must return a string or a JSON serializable object.")

# .get() is safe since process_datapoint is always called in the context of an Evaluation
context_variable = evaluation_context_variable.get()
if context_variable is not None:
# Evaluation Context has not been consumed
Expand Down
1 change: 1 addition & 0 deletions src/humanloop/otel/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def is_evaluated_file(
if not is_evaluated_file(spans[0], evaluation_context):
evaluation_context = None
except LookupError:
# No ongoing Evaluation happening
evaluation_context = None
for span in spans:
if is_humanloop_span(span):
Expand Down
Loading