mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-20 11:31:58 +00:00
Don't raise error if parent not found (#6538)
Done so that you can pass in a run from the low level api
This commit is contained in:
parent
49c864fa18
commit
07d802d088
@ -1,6 +1,7 @@
|
|||||||
"""Base interfaces for tracing runs."""
|
"""Base interfaces for tracing runs."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Dict, List, Optional, Union
|
from typing import Any, Dict, List, Optional, Union
|
||||||
@ -10,6 +11,8 @@ from langchain.callbacks.base import BaseCallbackHandler
|
|||||||
from langchain.callbacks.tracers.schemas import Run, RunTypeEnum
|
from langchain.callbacks.tracers.schemas import Run, RunTypeEnum
|
||||||
from langchain.schema import LLMResult
|
from langchain.schema import LLMResult
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class TracerException(Exception):
|
class TracerException(Exception):
|
||||||
"""Base class for exceptions in tracers module."""
|
"""Base class for exceptions in tracers module."""
|
||||||
@ -41,9 +44,7 @@ class BaseTracer(BaseCallbackHandler, ABC):
|
|||||||
if parent_run:
|
if parent_run:
|
||||||
self._add_child_run(parent_run, run)
|
self._add_child_run(parent_run, run)
|
||||||
else:
|
else:
|
||||||
raise TracerException(
|
logger.warning(f"Parent run with UUID {run.parent_run_id} not found.")
|
||||||
f"Parent run with UUID {run.parent_run_id} not found."
|
|
||||||
)
|
|
||||||
self.run_map[str(run.id)] = run
|
self.run_map[str(run.id)] = run
|
||||||
|
|
||||||
def _end_trace(self, run: Run) -> None:
|
def _end_trace(self, run: Run) -> None:
|
||||||
@ -53,10 +54,8 @@ class BaseTracer(BaseCallbackHandler, ABC):
|
|||||||
else:
|
else:
|
||||||
parent_run = self.run_map.get(str(run.parent_run_id))
|
parent_run = self.run_map.get(str(run.parent_run_id))
|
||||||
if parent_run is None:
|
if parent_run is None:
|
||||||
raise TracerException(
|
logger.warning(f"Parent run with UUID {run.parent_run_id} not found.")
|
||||||
f"Parent run with UUID {run.parent_run_id} not found."
|
elif (
|
||||||
)
|
|
||||||
if (
|
|
||||||
run.child_execution_order is not None
|
run.child_execution_order is not None
|
||||||
and parent_run.child_execution_order is not None
|
and parent_run.child_execution_order is not None
|
||||||
and run.child_execution_order > parent_run.child_execution_order
|
and run.child_execution_order > parent_run.child_execution_order
|
||||||
@ -71,7 +70,8 @@ class BaseTracer(BaseCallbackHandler, ABC):
|
|||||||
|
|
||||||
parent_run = self.run_map.get(parent_run_id)
|
parent_run = self.run_map.get(parent_run_id)
|
||||||
if parent_run is None:
|
if parent_run is None:
|
||||||
raise TracerException(f"Parent run with UUID {parent_run_id} not found.")
|
logger.warning(f"Parent run with UUID {parent_run_id} not found.")
|
||||||
|
return 1
|
||||||
if parent_run.child_execution_order is None:
|
if parent_run.child_execution_order is None:
|
||||||
raise TracerException(
|
raise TracerException(
|
||||||
f"Parent run with UUID {parent_run_id} has no child execution order."
|
f"Parent run with UUID {parent_run_id} has no child execution order."
|
||||||
|
Loading…
Reference in New Issue
Block a user