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

Support parent=false to prune trees #1429

Merged
merged 1 commit into from
Jan 17, 2025
Merged
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
8 changes: 6 additions & 2 deletions python/langsmith/run_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Decorator for creating a run tree from functions."""

Check notice on line 1 in python/langsmith/run_helpers.py

View workflow job for this annotation

GitHub Actions / benchmark

Benchmark results

........... create_5_000_run_trees: Mean +- std dev: 653 ms +- 50 ms ........... create_10_000_run_trees: Mean +- std dev: 1.32 sec +- 0.10 sec ........... create_20_000_run_trees: Mean +- std dev: 2.59 sec +- 0.15 sec ........... dumps_class_nested_py_branch_and_leaf_200x400: Mean +- std dev: 715 us +- 17 us ........... dumps_class_nested_py_leaf_50x100: Mean +- std dev: 24.8 ms +- 0.2 ms ........... dumps_class_nested_py_leaf_100x200: Mean +- std dev: 104 ms +- 3 ms ........... dumps_dataclass_nested_50x100: Mean +- std dev: 25.1 ms +- 0.1 ms ........... WARNING: the benchmark result may be unstable * the standard deviation (17.2 ms) is 24% of the mean (73.1 ms) Try to rerun the benchmark with more runs, values and/or loops. Run 'python -m pyperf system tune' command to reduce the system jitter. Use pyperf stats, pyperf dump and pyperf hist to analyze results. Use --quiet option to hide these warnings. dumps_pydantic_nested_50x100: Mean +- std dev: 73.1 ms +- 17.2 ms ........... dumps_pydanticv1_nested_50x100: Mean +- std dev: 198 ms +- 12 ms

Check notice on line 1 in python/langsmith/run_helpers.py

View workflow job for this annotation

GitHub Actions / benchmark

Comparison against main

+-----------------------------------------------+----------+------------------------+ | Benchmark | main | changes | +===============================================+==========+========================+ | dumps_pydanticv1_nested_50x100 | 217 ms | 198 ms: 1.10x faster | +-----------------------------------------------+----------+------------------------+ | dumps_dataclass_nested_50x100 | 25.4 ms | 25.1 ms: 1.01x faster | +-----------------------------------------------+----------+------------------------+ | dumps_class_nested_py_leaf_50x100 | 25.1 ms | 24.8 ms: 1.01x faster | +-----------------------------------------------+----------+------------------------+ | dumps_class_nested_py_leaf_100x200 | 104 ms | 104 ms: 1.00x faster | +-----------------------------------------------+----------+------------------------+ | create_20_000_run_trees | 2.58 sec | 2.59 sec: 1.00x slower | +-----------------------------------------------+----------+------------------------+ | create_5_000_run_trees | 650 ms | 653 ms: 1.01x slower | +-----------------------------------------------+----------+------------------------+ | dumps_class_nested_py_branch_and_leaf_200x400 | 707 us | 715 us: 1.01x slower | +-----------------------------------------------+----------+------------------------+ | create_10_000_run_trees | 1.30 sec | 1.32 sec: 1.02x slower | +-----------------------------------------------+----------+------------------------+ | dumps_pydantic_nested_50x100 | 65.8 ms | 73.1 ms: 1.11x slower | +-----------------------------------------------+----------+------------------------+ | Geometric mean | (ref) | 1.00x slower | +-----------------------------------------------+----------+------------------------+

from __future__ import annotations

Expand Down Expand Up @@ -102,7 +102,7 @@
project_name: Optional[str] = None,
tags: Optional[List[str]] = None,
metadata: Optional[Dict[str, Any]] = None,
parent: Optional[Union[run_trees.RunTree, Mapping, str]] = None,
parent: Optional[Union[run_trees.RunTree, Mapping, str, Literal[False]]] = None,
enabled: Optional[Union[bool, Literal["local"]]] = None,
client: Optional[ls_client.Client] = None,
**kwargs: Any,
Expand All @@ -129,7 +129,11 @@
DeprecationWarning,
)
current_context = get_tracing_context()
parent_run = _get_parent_run({"parent": parent or kwargs.get("parent_run")})
parent_run = (
_get_parent_run({"parent": parent or kwargs.get("parent_run")})
if parent is not False
else None
)
if parent_run is not None:
tags = sorted(set(tags or []) | set(parent_run.tags or []))
metadata = {**parent_run.metadata, **(metadata or {})}
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.2.10"
version = "0.2.11"
description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform."
authors = ["LangChain <[email protected]>"]
license = "MIT"
Expand Down
15 changes: 13 additions & 2 deletions python/tests/unit_tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import langsmith.utils as ls_utils
from langsmith import Client, traceable
from langsmith.run_helpers import tracing_context
from langsmith.run_helpers import get_current_run_tree, tracing_context


class LangSmithProjectNameTest(unittest.TestCase):
Expand Down Expand Up @@ -107,10 +107,21 @@ def test_tracing_enabled():
assert not ls_utils.tracing_is_enabled()

@traceable
def child_function():
def grandchild_function():
assert ls_utils.tracing_is_enabled()
rt = get_current_run_tree()
assert rt
assert rt.parent_run_id is None
assert "." not in rt.dotted_order
assert rt.parent_run is None
return 1

@traceable
def child_function():
assert ls_utils.tracing_is_enabled()
with tracing_context(parent=False):
return grandchild_function()

@traceable
def untraced_child_function():
assert not ls_utils.tracing_is_enabled()
Expand Down
Loading