Skip to content

Commit

Permalink
Rm lock
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Oct 3, 2024
1 parent 92d8e66 commit b67d2e4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
9 changes: 4 additions & 5 deletions python/langsmith/run_trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
LANGSMITH_PREFIX = "langsmith-"
LANGSMITH_DOTTED_ORDER = f"{LANGSMITH_PREFIX}trace"
_CLIENT: Optional[Client] = None
_LOCK = threading.Lock()
_LOCK = threading.Lock() # Keeping around for a while for backwards compat


# Note, this is called directly by langchain. Do not remove.
Expand All @@ -37,9 +37,8 @@
def get_cached_client(**init_kwargs: Any) -> Client:
global _CLIENT
if _CLIENT is None:
with _LOCK:
if _CLIENT is None:
_CLIENT = Client(**init_kwargs)
if _CLIENT is None:
_CLIENT = Client(**init_kwargs)
return _CLIENT


Expand Down Expand Up @@ -163,7 +162,7 @@ def add_metadata(self, metadata: Dict[str, Any]) -> None:
"""Add metadata to the run."""
if self.extra is None:
self.extra = {}
metadata_: dict = self.extra.setdefault("metadata", {})
metadata_: dict = cast(dict, self.extra).setdefault("metadata", {})
metadata_.update(metadata)

def add_outputs(self, outputs: Dict[str, Any]) -> None:
Expand Down
17 changes: 8 additions & 9 deletions python/langsmith/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

import threading
from datetime import datetime, timedelta, timezone
from decimal import Decimal
from enum import Enum
Expand Down Expand Up @@ -201,6 +200,10 @@ class DatasetVersion(BaseModel):
as_of: datetime


def _default_extra():
return {"metadata": {}}


class RunBase(BaseModel):
"""Base Run schema.
Expand All @@ -226,7 +229,7 @@ class RunBase(BaseModel):
end_time: Optional[datetime] = None
"""End time of the run, if applicable."""

extra: Optional[dict] = None
extra: Optional[dict] = Field(default_factory=_default_extra)
"""Additional metadata or settings related to the run."""

error: Optional[str] = None
Expand Down Expand Up @@ -258,16 +261,12 @@ class RunBase(BaseModel):
"""Attachments associated with the run.
Each entry is a tuple of (mime_type, bytes)."""

_lock: threading.Lock = PrivateAttr(default_factory=threading.Lock)

@property
def metadata(self) -> dict[str, Any]:
"""Retrieve the metadata (if any)."""
with self._lock:
if self.extra is None:
self.extra = {}
metadata = self.extra.setdefault("metadata", {})
return metadata
if self.extra is None:
self.extra = {}
return self.extra.setdefault("metadata", {})

@property
def revision_id(self) -> Optional[UUID]:
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.1.130"
version = "0.1.131"
description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform."
authors = ["LangChain <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit b67d2e4

Please sign in to comment.