Skip to content

Commit

Permalink
chore: add EU API URl to docs & infer web URL (#883)
Browse files Browse the repository at this point in the history
* Add API URL of new EU instance to READMEs:
https://docs.smith.langchain.com/reference/cloud_architecture_and_scalability#architecture
* Infer the web/host URL from the EU API URL
  • Loading branch information
dqbd authored Jul 18, 2024
2 parents 02a60d7 + 7f0e26f commit 1a69df4
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = "<YOUR-LANGSMITH-API-KEY>";
// process.env["LANGCHAIN_PROJECT"] = "My Project Name"; // Optional: "default" is used if not set
```
Expand Down
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,4 @@
},
"./package.json": "./package.json"
}
}
}
3 changes: 3 additions & 0 deletions js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions js/src/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = "<YOUR-LANGSMITH-API-KEY>"
# os.environ["LANGSMITH_PROJECT"] = "My Project Name" # Optional: "default" is used if not set
```
Expand Down
2 changes: 2 additions & 0 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions python/tests/unit_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 1a69df4

Please sign in to comment.