Skip to content

Commit

Permalink
Back out Python package changes for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi committed Nov 26, 2024
1 parent 287711d commit c7b3a73
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 84 deletions.
71 changes: 6 additions & 65 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ class Client:
"_write_api_urls",
"_settings",
"_manual_cleanup",
"_pyo3_client",
]

def __init__(
Expand Down Expand Up @@ -517,54 +516,6 @@ def __init__(
else ls_utils.get_env_var("HIDE_OUTPUTS") == "true"
)

# To set this up on the Rust side:
# - Navigate to the rust/crates/langsmith-pyo3 directory.
# - Run:
# maturin build --release
# - Then, back inside python/langsmith, run:
# poetry install --with pyo3
#
# To trigger this code, set the `LANGSMITH_USE_PYO3_CLIENT` env var to any value.
#
# Currently this requires Python 3.13 since the Poetry setup references the 3.13 wheel.
# Once the PyO3 package is uploaded to PyPI, we won't have to specify the *wheel* itself
# and can instead reference the *PyPI package name*. That will allow Poetry to choose
# a wheel that matches the locally-installed version of Python.
self._pyo3_client = None
if ls_utils.get_env_var("USE_PYO3_CLIENT") is not None:
langsmith_pyo3 = None
try:
import langsmith_pyo3
except ImportError as e:
logger.warning(
"Failed to import `langsmith_pyo3` when PyO3 client was requested, "
"falling back to Python impl: %s",
repr(e),
)

if langsmith_pyo3:
# TODO: tweak these constants as needed
queue_capacity = 1_000_000
batch_size = 100
batch_timeout_millis = 1000
worker_threads = 1

try:
self._pyo3_client = langsmith_pyo3.BlockingTracingClient(
self.api_url,
self.api_key,
queue_capacity,
batch_size,
batch_timeout_millis,
worker_threads,
)
except Exception as e:
logger.warning(
"Failed to instantiate `langsmith_pyo3.BlockingTracingClient` "
"when PyO3 client was requested, falling back to Python impl: %s",
repr(e),
)

self._settings: Union[ls_schemas.LangSmithSettings, None] = None

self._manual_cleanup = False
Expand Down Expand Up @@ -1275,26 +1226,16 @@ def create_run(
copy=False,
)
self._insert_runtime_env([run_create])

if (
self.tracing_queue is not None
# batch ingest requires trace_id and dotted_order to be set
run_create.get("trace_id") is not None
and run_create.get("trace_id") is not None
and run_create.get("dotted_order") is not None
):
if self._pyo3_client is not None:
# `self._run_transform()` above turns the `id` key into a `UUID` object.
# We need to pass a string since `orjson` doesn't seem to serialize `UUID` objects.
run_create["id"] = str(run_create["id"])
self._pyo3_client.create_run(run_create)
elif self.tracing_queue is not None:
serialized_op = serialize_run_dict("post", run_create)
self.tracing_queue.put(
TracingQueueItem(run_create["dotted_order"], serialized_op)
)
else:
# Neither Rust nor Python batch ingestion is configured,
# fall back to the non-batch approach.
self._create_run(run_create)
serialized_op = serialize_run_dict("post", run_create)
self.tracing_queue.put(
TracingQueueItem(run_create["dotted_order"], serialized_op)
)
else:
self._create_run(run_create)

Expand Down
18 changes: 2 additions & 16 deletions python/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ openai = "^1.10"
[tool.poetry.group.test.dependencies]
pytest-socket = "^0.7.0"

[tool.poetry.group.pyo3.dependencies]
langsmith-pyo3 = {path = "../rust/target/wheels/langsmith_pyo3-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl"}

[tool.poetry.extras]
vcr = ["vcrpy"]

Expand Down

0 comments on commit c7b3a73

Please sign in to comment.