From 9bf79171d7600752011784a849c4cb637b8a0234 Mon Sep 17 00:00:00 2001 From: Brian Vander Schaaf Date: Thu, 18 Jul 2024 11:08:27 -0400 Subject: [PATCH 1/2] chore: add EU API URl to docs & infer web URL --- js/README.md | 1 + js/package.json | 2 +- js/src/client.ts | 3 +++ js/src/tests/client.test.ts | 9 +++++++++ python/README.md | 1 + python/langsmith/client.py | 2 ++ python/tests/unit_tests/test_client.py | 3 +++ 7 files changed, 20 insertions(+), 1 deletion(-) diff --git a/js/README.md b/js/README.md index 9eba64647..b8d337bdd 100644 --- a/js/README.md +++ b/js/README.md @@ -53,6 +53,7 @@ Tracing can be activated by setting the following environment variables or by ma ```typescript process.env["LANGSMITH_TRACING"] = "true"; process.env["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"; +process.env["LANGCHAIN_ENDPOINT"] = "https://eu.api.smith.langchain.com"; // If signed up in the EU region process.env["LANGCHAIN_API_KEY"] = ""; // process.env["LANGCHAIN_PROJECT"] = "My Project Name"; // Optional: "default" is used if not set ``` diff --git a/js/package.json b/js/package.json index f6bb02d18..a3a2d979e 100644 --- a/js/package.json +++ b/js/package.json @@ -261,4 +261,4 @@ }, "./package.json": "./package.json" } -} \ No newline at end of file +} diff --git a/js/src/client.ts b/js/src/client.ts index 6cba0c43b..b68105c41 100644 --- a/js/src/client.ts +++ b/js/src/client.ts @@ -481,6 +481,9 @@ export class Client { } else if (this.apiUrl.split(".", 1)[0].includes("dev")) { this.webUrl = "https://dev.smith.langchain.com"; return this.webUrl; + } else if (this.apiUrl.split(".", 1)[0].includes("eu")) { + this.webUrl = "https://eu.smith.langchain.com"; + return this.webUrl; } else { this.webUrl = "https://smith.langchain.com"; return this.webUrl; diff --git a/js/src/tests/client.test.ts b/js/src/tests/client.test.ts index 245c9487e..000dd460b 100644 --- a/js/src/tests/client.test.ts +++ b/js/src/tests/client.test.ts @@ -115,6 +115,15 @@ describe("Client", () => { expect(result).toBe("https://dev.smith.langchain.com"); }); + it("should return 'https://eu.smith.langchain.com' if apiUrl contains 'eu'", () => { + const client = new Client({ + apiUrl: "https://eu.smith.langchain.com/api", + apiKey: "test-api-key", + }); + const result = (client as any).getHostUrl(); + expect(result).toBe("https://eu.smith.langchain.com"); + }); + it("should return 'https://smith.langchain.com' for any other apiUrl", () => { const client = new Client({ apiUrl: "https://smith.langchain.com/api", diff --git a/python/README.md b/python/README.md index 97fbfb296..85de1e11a 100644 --- a/python/README.md +++ b/python/README.md @@ -70,6 +70,7 @@ Tracing can be activated by setting the following environment variables or by ma import os os.environ["LANGSMITH_TRACING_V2"] = "true" os.environ["LANGSMITH_ENDPOINT"] = "https://api.smith.langchain.com" +# os.environ["LANGSMITH_ENDPOINT"] = "https://eu.api.smith.langchain.com" # If signed up in the EU region os.environ["LANGSMITH_API_KEY"] = "" # os.environ["LANGSMITH_PROJECT"] = "My Project Name" # Optional: "default" is used if not set ``` diff --git a/python/langsmith/client.py b/python/langsmith/client.py index 3ddcc9df0..d37d04438 100644 --- a/python/langsmith/client.py +++ b/python/langsmith/client.py @@ -654,6 +654,8 @@ def _host_url(self) -> str: elif parsed_url.path.endswith("/api"): new_path = parsed_url.path.rsplit("/api", 1)[0] link = urllib_parse.urlunparse(parsed_url._replace(path=new_path)) + elif parsed_url.netloc.startswith("eu."): + link = "https://eu.smith.langchain.com" elif parsed_url.netloc.startswith("dev."): link = "https://dev.smith.langchain.com" else: diff --git a/python/tests/unit_tests/test_client.py b/python/tests/unit_tests/test_client.py index a653cf704..0d247d836 100644 --- a/python/tests/unit_tests/test_client.py +++ b/python/tests/unit_tests/test_client.py @@ -898,6 +898,9 @@ def test_host_url(_: MagicMock) -> None: client = Client(api_url="http://localhost:8000", api_key="API_KEY") assert client._host_url == "http://localhost" + client = Client(api_url="https://eu.api.smith.langchain.com", api_key="API_KEY") + assert client._host_url == "https://eu.smith.langchain.com" + client = Client(api_url="https://dev.api.smith.langchain.com", api_key="API_KEY") assert client._host_url == "https://dev.smith.langchain.com" From 7f0e26f0fb91be5d9d1c682366b4b8dd8879d186 Mon Sep 17 00:00:00 2001 From: Brian Vander Schaaf Date: Thu, 18 Jul 2024 11:11:28 -0400 Subject: [PATCH 2/2] fix readme --- js/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/README.md b/js/README.md index b8d337bdd..7aa73a1c9 100644 --- a/js/README.md +++ b/js/README.md @@ -53,7 +53,7 @@ Tracing can be activated by setting the following environment variables or by ma ```typescript process.env["LANGSMITH_TRACING"] = "true"; process.env["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"; -process.env["LANGCHAIN_ENDPOINT"] = "https://eu.api.smith.langchain.com"; // If signed up in the EU region +// process.env["LANGCHAIN_ENDPOINT"] = "https://eu.api.smith.langchain.com"; // If signed up in the EU region process.env["LANGCHAIN_API_KEY"] = ""; // process.env["LANGCHAIN_PROJECT"] = "My Project Name"; // Optional: "default" is used if not set ```