Skip to content

Commit

Permalink
core[patch]: Remove deep copying of run prior to submitting it to Lan…
Browse files Browse the repository at this point in the history
…gChain Tracing (langchain-ai#16904)
  • Loading branch information
hinthornw authored Feb 2, 2024
1 parent e02efd5 commit bdacfaf
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions libs/core/langchain_core/tracers/langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ def _get_executor() -> ThreadPoolExecutor:
return _EXECUTOR


def _copy(run: Run) -> Run:
"""Copy a run."""
try:
return run.copy(deep=True)
except TypeError:
# Fallback in case the object contains a lock or other
# non-pickleable object
return run.copy()


class LangChainTracer(BaseTracer):
"""An implementation of the SharedTracer that POSTS to the langchain endpoint."""

Expand Down Expand Up @@ -202,63 +192,63 @@ def _on_llm_start(self, run: Run) -> None:
"""Persist an LLM run."""
if run.parent_run_id is None:
run.reference_example_id = self.example_id
self._submit(self._persist_run_single, _copy(run))
self._submit(self._persist_run_single, run)

def _on_chat_model_start(self, run: Run) -> None:
"""Persist an LLM run."""
if run.parent_run_id is None:
run.reference_example_id = self.example_id
self._submit(self._persist_run_single, _copy(run))
self._submit(self._persist_run_single, run)

def _on_llm_end(self, run: Run) -> None:
"""Process the LLM Run."""
self._submit(self._update_run_single, _copy(run))
self._submit(self._update_run_single, run)

def _on_llm_error(self, run: Run) -> None:
"""Process the LLM Run upon error."""
self._submit(self._update_run_single, _copy(run))
self._submit(self._update_run_single, run)

def _on_chain_start(self, run: Run) -> None:
"""Process the Chain Run upon start."""
if run.parent_run_id is None:
run.reference_example_id = self.example_id
self._submit(self._persist_run_single, _copy(run))
self._submit(self._persist_run_single, run)

def _on_chain_end(self, run: Run) -> None:
"""Process the Chain Run."""
self._submit(self._update_run_single, _copy(run))
self._submit(self._update_run_single, run)

def _on_chain_error(self, run: Run) -> None:
"""Process the Chain Run upon error."""
self._submit(self._update_run_single, _copy(run))
self._submit(self._update_run_single, run)

def _on_tool_start(self, run: Run) -> None:
"""Process the Tool Run upon start."""
if run.parent_run_id is None:
run.reference_example_id = self.example_id
self._submit(self._persist_run_single, _copy(run))
self._submit(self._persist_run_single, run)

def _on_tool_end(self, run: Run) -> None:
"""Process the Tool Run."""
self._submit(self._update_run_single, _copy(run))
self._submit(self._update_run_single, run)

def _on_tool_error(self, run: Run) -> None:
"""Process the Tool Run upon error."""
self._submit(self._update_run_single, _copy(run))
self._submit(self._update_run_single, run)

def _on_retriever_start(self, run: Run) -> None:
"""Process the Retriever Run upon start."""
if run.parent_run_id is None:
run.reference_example_id = self.example_id
self._submit(self._persist_run_single, _copy(run))
self._submit(self._persist_run_single, run)

def _on_retriever_end(self, run: Run) -> None:
"""Process the Retriever Run."""
self._submit(self._update_run_single, _copy(run))
self._submit(self._update_run_single, run)

def _on_retriever_error(self, run: Run) -> None:
"""Process the Retriever Run upon error."""
self._submit(self._update_run_single, _copy(run))
self._submit(self._update_run_single, run)

def wait_for_futures(self) -> None:
"""Wait for the given futures to complete."""
Expand Down

0 comments on commit bdacfaf

Please sign in to comment.