Skip to content

Commit

Permalink
nit: stop calling importlib on every api req (#1219)
Browse files Browse the repository at this point in the history
Each call is like 1-3ms, and we call to get the version as part of every
client request's headers. If you're running an eval over a lot of traces
(say 10 evaluators on 1k examples), that's slow. Esp if just doing
custom code evaluators which should run fast.

### Flame Graphs before and after
(ran on 2k smallish examples w 10 evaluators)
<img width="1510" alt="Screenshot 2024-11-14 at 5 25 43 PM"
src="https://github.com/user-attachments/assets/2366b357-f3de-4f18-b7a8-5b362c992119">

<img width="1507" alt="Screenshot 2024-11-14 at 5 25 53 PM"
src="https://github.com/user-attachments/assets/3311e686-373c-4fd7-80e1-d6939a3c4632">

---------

Co-authored-by: William FH <[email protected]>
  • Loading branch information
jakerachleff and hinthornw authored Nov 15, 2024
1 parent 2df6407 commit 2cc6e1f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions python/langsmith/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""LangSmith Client."""

from importlib import metadata
from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
Expand All @@ -21,15 +22,17 @@
ContextThreadPoolExecutor,
)

# Avoid calling into importlib on every call to __version__
version = ""
try:
version = metadata.version(__package__)
except metadata.PackageNotFoundError:
pass


def __getattr__(name: str) -> Any:
if name == "__version__":
try:
from importlib import metadata

return metadata.version(__package__)
except metadata.PackageNotFoundError:
return ""
return version
elif name == "Client":
from langsmith.client import Client

Expand Down

0 comments on commit 2cc6e1f

Please sign in to comment.