create an abstract class for an existing class
This commit is contained in:
parent
f499e257f9
commit
d4b7d8b469
2 changed files with 36 additions and 2 deletions
33
src/backend/base/langflow/services/tracing/base.py
Normal file
33
src/backend/base/langflow/services/tracing/base.py
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from typing import Dict, Any
|
||||||
|
|
||||||
|
|
||||||
|
class BaseTrace(ABC):
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def ready(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def setup_langsmith(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def add_trace(self, trace_name: str, trace_type: str, inputs: Dict[str, Any], metadata: Dict[str, Any] = None):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def _convert_to_langchain_types(self, io_dict: Dict[str, Any]):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def _convert_to_langchain_type(self, value):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def end_trace(self, trace_name: str, outputs: Dict[str, Any] = None, error: str = None):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def end(self, outputs: Dict[str, Any], error: str | None = None):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
@ -13,6 +13,7 @@ from loguru import logger
|
||||||
from langflow.schema.data import Data
|
from langflow.schema.data import Data
|
||||||
from langflow.services.base import Service
|
from langflow.services.base import Service
|
||||||
from langflow.services.tracing.schema import Log
|
from langflow.services.tracing.schema import Log
|
||||||
|
from langflow.services.tracing.base import BaseTrace
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from langflow.services.monitor.service import MonitorService
|
from langflow.services.monitor.service import MonitorService
|
||||||
|
|
@ -180,8 +181,8 @@ class TracingService(Service):
|
||||||
self.outputs_metadata[trace_name] |= output_metadata or {}
|
self.outputs_metadata[trace_name] |= output_metadata or {}
|
||||||
|
|
||||||
|
|
||||||
class LangSmithTracer:
|
class LangSmithTracer(BaseTrace):
|
||||||
def __init__(self, trace_name: str, trace_type: str, project_name: str, trace_id: UUID):
|
def __init__(self, trace_name: str, trace_type: str, project_name: str, trace_id: str):
|
||||||
from langsmith.run_trees import RunTree
|
from langsmith.run_trees import RunTree
|
||||||
|
|
||||||
self.trace_name = trace_name
|
self.trace_name = trace_name
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue