Skip to content

Commit

Permalink
Rm thread for blocking eval (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Sep 5, 2024
1 parent ef88ac7 commit dbe8eb9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions python/langsmith/evaluation/_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def evaluate(
Defaults to None.
description (Optional[str]): A free-form text description for the experiment.
max_concurrency (Optional[int]): The maximum number of concurrent
evaluations to run. Defaults to None.
evaluations to run. Defaults to None (max number of workers).
client (Optional[langsmith.Client]): The LangSmith client to use.
Defaults to None.
blocking (bool): Whether to block until the evaluation is complete.
Expand Down Expand Up @@ -371,16 +371,19 @@ class ExperimentResults:
wait() -> None: Waits for the experiment data to be processed.
"""

def __init__(
self,
experiment_manager: _ExperimentManager,
):
def __init__(self, experiment_manager: _ExperimentManager, blocking: bool = True):
self._manager = experiment_manager
self._results: List[ExperimentResultRow] = []
self._queue: queue.Queue[ExperimentResultRow] = queue.Queue()
self._processing_complete = threading.Event()
self._thread = threading.Thread(target=self._process_data)
self._thread.start()
if not blocking:
self._thread: Optional[threading.Thread] = threading.Thread(
target=self._process_data
)
self._thread.start()
else:
self._thread = None
self._process_data()

@property
def experiment_name(self) -> str:
Expand Down Expand Up @@ -426,7 +429,8 @@ def wait(self) -> None:
This method blocks the current thread until the evaluation runner has
finished its execution.
"""
self._thread.join()
if self._thread:
self._thread.join()


## Public API for Comparison Experiments
Expand Down Expand Up @@ -878,10 +882,7 @@ def _evaluate(
# Apply the experiment-level summary evaluators.
manager = manager.with_summary_evaluators(summary_evaluators)
# Start consuming the results.
results = ExperimentResults(manager)
if blocking:
# Wait for the evaluation to complete.
results.wait()
results = ExperimentResults(manager, blocking=blocking)
return results


Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langsmith"
version = "0.1.114"
version = "0.1.115"
description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform."
authors = ["LangChain <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit dbe8eb9

Please sign in to comment.