-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
865 changed files
with
135,095 additions
and
63,619 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import ast | ||
import os | ||
from itertools import filterfalse | ||
from typing import List, Tuple | ||
|
||
ROOT_PATH = os.path.abspath(os.path.join(__file__, "..", "..", "..")) | ||
CLIENT_PATH = os.path.join(ROOT_PATH, "libs", "sdk-py", "langgraph_sdk", "client.py") | ||
|
||
|
||
def get_class_methods(node: ast.ClassDef) -> List[str]: | ||
return [n.name for n in node.body if isinstance(n, (ast.FunctionDef, ast.AsyncFunctionDef))] | ||
|
||
|
||
def find_classes(tree: ast.AST) -> List[Tuple[str, List[str]]]: | ||
classes = [] | ||
for node in ast.walk(tree): | ||
if isinstance(node, ast.ClassDef): | ||
methods = get_class_methods(node) | ||
classes.append((node.name, methods)) | ||
return classes | ||
|
||
|
||
def compare_sync_async_methods(sync_methods: List[str], async_methods: List[str]) -> List[str]: | ||
sync_set = set(sync_methods) | ||
async_set = set(async_methods) | ||
missing_in_sync = list(async_set - sync_set) | ||
missing_in_async = list(sync_set - async_set) | ||
return missing_in_sync + missing_in_async | ||
|
||
|
||
def main(): | ||
with open(CLIENT_PATH, "r") as file: | ||
tree = ast.parse(file.read()) | ||
|
||
classes = find_classes(tree) | ||
|
||
def is_sync(class_spec: Tuple[str, List[str]]) -> bool: | ||
return class_spec[0].startswith("Sync") | ||
|
||
sync_class_name_to_methods = {class_name: class_methods for class_name, class_methods in filter(is_sync, classes)} | ||
async_class_name_to_methods = {class_name: class_methods for class_name, class_methods in filterfalse(is_sync, classes)} | ||
|
||
mismatches = [] | ||
|
||
for async_class_name, async_class_methods in async_class_name_to_methods.items(): | ||
sync_class_name = "Sync" + async_class_name | ||
sync_class_methods = sync_class_name_to_methods.get(sync_class_name, []) | ||
diff = compare_sync_async_methods(sync_class_methods, async_class_methods) | ||
if diff: | ||
mismatches.append((sync_class_name, async_class_name, diff)) | ||
|
||
if mismatches: | ||
error_message = "Mismatches found between sync and async client methods:\n" | ||
for sync_class_name, async_class_name, diff in mismatches: | ||
error_message += f"{sync_class_name} vs {async_class_name}:\n" | ||
for method in diff: | ||
error_message += f" - {method}\n" | ||
raise ValueError(error_message) | ||
|
||
print("All sync and async client methods match.") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import asyncio | ||
import json | ||
import os | ||
import pathlib | ||
import sys | ||
import langgraph_cli | ||
import langgraph_cli.docker | ||
import langgraph_cli.config | ||
|
||
from langgraph_cli.exec import Runner, subp_exec | ||
from langgraph_cli.progress import Progress | ||
from langgraph_cli.constants import DEFAULT_PORT | ||
|
||
|
||
def test( | ||
config: pathlib.Path, | ||
port: int, | ||
tag: str, | ||
verbose: bool, | ||
): | ||
with Runner() as runner, Progress(message="Pulling...") as set: | ||
# check docker available | ||
capabilities = langgraph_cli.docker.check_capabilities(runner) | ||
# open config | ||
with open(config) as f: | ||
config_json = langgraph_cli.config.validate_config(json.load(f)) | ||
|
||
set("Running...") | ||
args = [ | ||
"run", | ||
"--rm", | ||
"-p", | ||
f"{port}:8000", | ||
] | ||
if isinstance(config_json["env"], str): | ||
args.extend( | ||
[ | ||
"--env-file", | ||
str(config.parent / config_json["env"]), | ||
] | ||
) | ||
else: | ||
for k, v in config_json["env"].items(): | ||
args.extend( | ||
[ | ||
"-e", | ||
f"{k}={v}", | ||
] | ||
) | ||
if capabilities.healthcheck_start_interval: | ||
args.extend( | ||
[ | ||
"--health-interval", | ||
"5s", | ||
"--health-retries", | ||
"1", | ||
"--health-start-period", | ||
"10s", | ||
"--health-start-interval", | ||
"1s", | ||
] | ||
) | ||
else: | ||
args.extend( | ||
[ | ||
"--health-interval", | ||
"5s", | ||
"--health-retries", | ||
"2", | ||
] | ||
) | ||
|
||
_task = None | ||
|
||
def on_stdout(line: str): | ||
nonlocal _task | ||
if "GET /ok" in line or "Uvicorn running on" in line: | ||
set("") | ||
sys.stdout.write( | ||
f"""Ready! | ||
- API: http://localhost:{port} | ||
""" | ||
) | ||
sys.stdout.flush() | ||
_task.cancel() | ||
return True | ||
return False | ||
|
||
async def subp_exec_task(*args, **kwargs): | ||
nonlocal _task | ||
_task = asyncio.create_task(subp_exec(*args, **kwargs)) | ||
await _task | ||
|
||
try: | ||
runner.run( | ||
subp_exec_task( | ||
"docker", | ||
*args, | ||
tag, | ||
verbose=verbose, | ||
on_stdout=on_stdout, | ||
) | ||
) | ||
except asyncio.CancelledError: | ||
pass | ||
|
||
|
||
if __name__ == "__main__": | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-t", "--tag", type=str) | ||
parser.add_argument("-c", "--config", type=str, default="./langgraph.json") | ||
parser.add_argument("-p", "--port", default=DEFAULT_PORT) | ||
args = parser.parse_args() | ||
test(pathlib.Path(args.config), args.port, args.tag, verbose=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: test | ||
|
||
on: | ||
workflow_call: | ||
|
||
env: | ||
POETRY_VERSION: "1.7.1" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: | ||
- "3.9" | ||
- "3.10" | ||
- "3.11" | ||
- "3.12" | ||
- "3.13" | ||
core-version: | ||
- "latest" | ||
include: | ||
- python-version: "3.11" | ||
core-version: ">=0.2.39,<0.3.0" | ||
|
||
defaults: | ||
run: | ||
working-directory: libs/langgraph | ||
name: "test #${{ matrix.python-version }} (langchain-core: ${{ matrix.core-version }})" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }} | ||
uses: "./.github/actions/poetry_setup" | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
poetry-version: ${{ env.POETRY_VERSION }} | ||
cache-key: test-langgraph | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
if: ${{ !github.event.pull_request.head.repo.fork }} | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_RO_TOKEN }} | ||
|
||
- name: Install dependencies | ||
shell: bash | ||
run: | | ||
poetry install --with dev | ||
if [ "${{ matrix.core-version }}" != "latest" ]; then | ||
poetry run pip install "langchain-core${{ matrix.core-version }}" | ||
fi | ||
- name: Run tests | ||
shell: bash | ||
run: | | ||
make test | ||
- name: Ensure the tests did not create any additional files | ||
shell: bash | ||
run: | | ||
set -eu | ||
STATUS="$(git status)" | ||
echo "$STATUS" | ||
# grep will exit non-zero if the target message isn't found, | ||
# and `set -e` above will cause the step to fail. | ||
echo "$STATUS" | grep 'nothing to commit, working tree clean' |
Oops, something went wrong.