Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡️ Speed up method LangSmithTracer.add_trace by 18% in src/backend/base/langflow/services/tracing/langsmith.py #92

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions src/backend/base/langflow/graph/vertex/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
from loguru import logger

from langflow.exceptions.component import ComponentBuildError
from langflow.graph.schema import INPUT_COMPONENTS, OUTPUT_COMPONENTS, InterfaceComponentTypes, ResultData
from langflow.graph.schema import (INPUT_COMPONENTS, OUTPUT_COMPONENTS,
InterfaceComponentTypes, ResultData)
from langflow.graph.utils import UnbuiltObject, UnbuiltResult, log_transaction
from langflow.interface import initialize
from langflow.interface.listing import lazy_load_dict
from langflow.schema.artifact import ArtifactType
from langflow.schema.data import Data
from langflow.schema.message import Message
from langflow.schema.schema import INPUT_FIELD_NAME, OutputValue, build_output_logs
from langflow.schema.schema import (INPUT_FIELD_NAME, OutputValue,
build_output_logs)
from langflow.services.deps import get_storage_service
from langflow.utils.constants import DIRECT_TYPES
from langflow.utils.schemas import ChatOutputResponse
Expand Down
15 changes: 8 additions & 7 deletions src/backend/base/langflow/services/tracing/langsmith.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import types
from datetime import datetime, timezone
from typing import TYPE_CHECKING, Any
from uuid import UUID

from loguru import logger

from langflow.graph.vertex.base import Vertex
from langflow.schema.data import Data
from langflow.services.tracing.base import BaseTracer

Expand Down Expand Up @@ -73,24 +75,23 @@ def add_trace(
) -> None:
if not self._ready or not self._run_tree:
return
processed_inputs = {}
if inputs:
processed_inputs = self._convert_to_langchain_types(inputs)

processed_inputs = self._convert_to_langchain_types(inputs) if inputs else {}

child = self._run_tree.create_child(
name=trace_name,
run_type=trace_type, # type: ignore[arg-type]
inputs=processed_inputs,
)

if metadata:
child.add_metadata(self._convert_to_langchain_types(metadata))

self._children[trace_name] = child
self._child_link: dict[str, str] = {}

def _convert_to_langchain_types(self, io_dict: dict[str, Any]):
converted = {}
for key, value in io_dict.items():
converted[key] = self._convert_to_langchain_type(value)
return converted
return {key: self._convert_to_langchain_type(value) for key, value in io_dict.items()}

def _convert_to_langchain_type(self, value):
from langflow.schema.message import Message
Expand Down