Merge pull request #1829 from langchain-ai/vb/combine-sdk-into-single-file

sdk-py: combine sync & async into a single file
This commit is contained in:
Nuno Campos
2024-09-24 11:35:51 -07:00
committed by GitHub
7 changed files with 3638 additions and 3685 deletions
@@ -16,14 +16,14 @@ client = get_client(url="http://localhost:8123")
assistants = await client.assistants.get(assistant_id="some_uuid")
```
::: langgraph_sdk.client.async_client.get_client
::: langgraph_sdk.client.get_client
handler: python
## LangGraphClient
`LangGraphClient` is the top-level client for accessing `AssistantsClient`, `ThreadsClient`, `RunsClient`, and `CronClient`.
::: langgraph_sdk.client.async_client.LangGraphClient
::: langgraph_sdk.client.LangGraphClient
handler: python
## AssistantsClient
@@ -36,7 +36,7 @@ client = get_client(url="http://localhost:8123")
await client.assistants.<method_name>()
```
::: langgraph_sdk.client.async_client.AssistantsClient
::: langgraph_sdk.client.AssistantsClient
handler: python
## ThreadsClient
@@ -49,7 +49,7 @@ client = get_client(url="http://localhost:8123")
await client.threads.<method_name>()
```
::: langgraph_sdk.client.async_client.ThreadsClient
::: langgraph_sdk.client.ThreadsClient
handler: python
## RunsClient
@@ -62,7 +62,7 @@ client = get_client(url="http://localhost:8123")
await client.runs.<method_name>()
```
::: langgraph_sdk.client.async_client.RunsClient
::: langgraph_sdk.client.RunsClient
handler: python
## CronClient
@@ -75,5 +75,5 @@ client = get_client(url="http://localhost:8123")
await client.crons.<method_name>()
```
::: langgraph_sdk.client.async_client.CronClient
::: langgraph_sdk.client.CronClient
handler: python
+2 -2
View File
@@ -1,4 +1,4 @@
from langgraph_sdk.client import get_client
from langgraph_sdk.client import get_client, get_sync_client
try:
from importlib import metadata
@@ -7,4 +7,4 @@ try:
except metadata.PackageNotFoundError:
__version__ = "unknown"
__all__ = ["get_client"]
__all__ = ["get_client", "get_sync_client"]
File diff suppressed because it is too large Load Diff
@@ -1,3 +0,0 @@
from langgraph_sdk.client.async_client import LangGraphClient, get_client
__all__ = ["get_client", "LangGraphClient"]
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-53
View File
@@ -1,53 +0,0 @@
import os
from typing import Any, Optional
import langgraph_sdk
RESERVED_HEADERS = ("x-api-key",)
def _get_api_key(api_key: Optional[str] = None) -> Optional[str]:
"""Get the API key from the environment.
Precedence:
1. explicit argument
2. LANGGRAPH_API_KEY
3. LANGSMITH_API_KEY
4. LANGCHAIN_API_KEY
"""
if api_key:
return api_key
for prefix in ["LANGGRAPH", "LANGSMITH", "LANGCHAIN"]:
if env := os.getenv(f"{prefix}_API_KEY"):
return env.strip().strip('"').strip("'")
return None # type: ignore
def get_headers(
api_key: Optional[str], custom_headers: Optional[dict[str, str]]
) -> dict[str, str]:
"""Combine api_key and custom user-provided headers."""
custom_headers = custom_headers or {}
for header in RESERVED_HEADERS:
if header in custom_headers:
raise ValueError(f"Cannot set reserved header '{header}'")
headers = {
"User-Agent": f"langgraph-sdk-py/{langgraph_sdk.__version__}",
**custom_headers,
}
api_key = _get_api_key(api_key)
if api_key:
headers["x-api-key"] = api_key
return headers
def orjson_default(obj: Any) -> Any:
if hasattr(obj, "model_dump") and callable(obj.model_dump):
return obj.model_dump()
elif hasattr(obj, "dict") and callable(obj.dict):
return obj.dict()
elif isinstance(obj, (set, frozenset)):
return list(obj)
else:
raise TypeError(f"Object of type {type(obj)} is not JSON serializable")