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

python[patch]: fix example link [LS-2764] #1473

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions python/langsmith/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Generic utility functions."""

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

View workflow job for this annotation

GitHub Actions / benchmark

Benchmark results

........... create_5_000_run_trees: Mean +- std dev: 660 ms +- 42 ms ........... create_10_000_run_trees: Mean +- std dev: 1.31 sec +- 0.10 sec ........... create_20_000_run_trees: Mean +- std dev: 2.70 sec +- 0.18 sec ........... dumps_class_nested_py_branch_and_leaf_200x400: Mean +- std dev: 720 us +- 7 us ........... dumps_class_nested_py_leaf_50x100: Mean +- std dev: 25.6 ms +- 1.3 ms ........... dumps_class_nested_py_leaf_100x200: Mean +- std dev: 105 ms +- 3 ms ........... dumps_dataclass_nested_50x100: Mean +- std dev: 25.8 ms +- 0.3 ms ........... WARNING: the benchmark result may be unstable * the standard deviation (18.0 ms) is 24% of the mean (76.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: 76.1 ms +- 18.0 ms ........... dumps_pydanticv1_nested_50x100: Mean +- std dev: 202 ms +- 5 ms

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

View workflow job for this annotation

GitHub Actions / benchmark

Comparison against main

+-----------------------------------------------+----------+------------------------+ | Benchmark | main | changes | +===============================================+==========+========================+ | dumps_pydanticv1_nested_50x100 | 217 ms | 202 ms: 1.07x faster | +-----------------------------------------------+----------+------------------------+ | create_5_000_run_trees | 677 ms | 660 ms: 1.03x faster | +-----------------------------------------------+----------+------------------------+ | create_10_000_run_trees | 1.34 sec | 1.31 sec: 1.02x faster | +-----------------------------------------------+----------+------------------------+ | create_20_000_run_trees | 2.67 sec | 2.70 sec: 1.01x slower | +-----------------------------------------------+----------+------------------------+ | dumps_class_nested_py_branch_and_leaf_200x400 | 709 us | 720 us: 1.01x slower | +-----------------------------------------------+----------+------------------------+ | dumps_class_nested_py_leaf_100x200 | 103 ms | 105 ms: 1.02x slower | +-----------------------------------------------+----------+------------------------+ | dumps_dataclass_nested_50x100 | 25.3 ms | 25.8 ms: 1.02x slower | +-----------------------------------------------+----------+------------------------+ | dumps_class_nested_py_leaf_50x100 | 24.9 ms | 25.6 ms: 1.03x slower | +-----------------------------------------------+----------+------------------------+ | dumps_pydantic_nested_50x100 | 66.0 ms | 76.1 ms: 1.15x slower | +-----------------------------------------------+----------+------------------------+ | Geometric mean | (ref) | 1.01x slower | +-----------------------------------------------+----------+------------------------+

from __future__ import annotations

Expand Down Expand Up @@ -770,10 +770,15 @@
elif str(parsed_url.path).endswith("/api"):
new_path = str(parsed_url.path).rsplit("/api", 1)[0]
link = urllib_parse.urlunparse(parsed_url._replace(path=new_path))
elif str(parsed_url.path).endswith("/api/v1"):
new_path = str(parsed_url.path).rsplit("/api/v1", 1)[0]
link = urllib_parse.urlunparse(parsed_url._replace(path=new_path))
elif str(parsed_url.netloc).startswith("eu."):
link = "https://eu.smith.langchain.com"
elif str(parsed_url.netloc).startswith("dev."):
link = "https://dev.smith.langchain.com"
elif str(parsed_url.netloc).startswith("beta."):
link = "https://beta.smith.langchain.com"
else:
link = "https://smith.langchain.com"
return link
Expand Down
59 changes: 59 additions & 0 deletions python/tests/unit_tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,62 @@ class BarClass:
assert ls_utils._get_function_name(print) == "print"

assert ls_utils._get_function_name("not_a_function") == "not_a_function"


def test_get_host_url():
# If web_url is explicitly provided, it takes precedence over api_url.
assert (
ls_utils.get_host_url(
"https://my-custom-web.com", "https://api.smith.langchain.com"
)
== "https://my-custom-web.com"
)

# When web_url is None and api_url is localhost.
assert ls_utils.get_host_url(None, "http://localhost:5000") == "http://localhost"
# A port variation on localhost.
assert (
ls_utils.get_host_url(None, "http://127.0.0.1:8080") == "http://localhost"
), "Should recognize 127.x.x.x as localhost."

# If api_url path ends with /api, trimmed back to netloc.
assert (
ls_utils.get_host_url(None, "https://my-awesome-domain.com/api")
== "https://my-awesome-domain.com"
)

# If api_url path ends with /api/v1, trimmed back to netloc.
assert (
ls_utils.get_host_url(None, "https://my-other-domain.com/api/v1")
== "https://my-other-domain.com"
)

# If netloc begins with dev.
assert (
ls_utils.get_host_url(None, "https://dev.smith.langchain.com/api/v1")
== "https://dev.smith.langchain.com"
)

# If netloc begins with eu.
assert (
ls_utils.get_host_url(None, "https://eu.smith.langchain.com/api")
== "https://eu.smith.langchain.com"
)

# If netloc begins with beta.
assert (
ls_utils.get_host_url(None, "https://beta.smith.langchain.com")
== "https://beta.smith.langchain.com"
)

# If netloc begins with api.
assert (
ls_utils.get_host_url(None, "https://api.smith.langchain.com")
== "https://smith.langchain.com"
)

# Otherwise, returns https://smith.langchain.com for unknown host.
assert (
ls_utils.get_host_url(None, "https://unknownhost.com/api")
== "https://smith.langchain.com"
)
Loading