Skip to content

Commit

Permalink
Add SDK (#1892)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Sep 29, 2024
1 parent c352b60 commit 121587b
Show file tree
Hide file tree
Showing 3 changed files with 456 additions and 7 deletions.
25 changes: 22 additions & 3 deletions libs/checkpoint/langgraph/store/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from abc import ABC, abstractmethod
from datetime import datetime
from typing import Any, Iterable, Literal, NamedTuple, Optional, Union
from typing import Any, Iterable, Literal, NamedTuple, Optional, Union, cast


class Item:
Expand Down Expand Up @@ -35,9 +35,19 @@ def __init__(
):
self.value = value
self.key = key
# The casting from json-like types is for if this object is
# deserialized.
self.namespace = tuple(namespace)
self.created_at = created_at
self.updated_at = updated_at
self.created_at = (
datetime.fromisoformat(cast(str, created_at))
if isinstance(created_at, str)
else created_at
)
self.updated_at = (
datetime.fromisoformat(cast(str, created_at))
if isinstance(updated_at, str)
else updated_at
)

def __eq__(self, other: object) -> bool:
if not isinstance(other, Item):
Expand All @@ -53,6 +63,15 @@ def __eq__(self, other: object) -> bool:
def __hash__(self) -> int:
return hash((self.namespace, self.key))

def dict(self) -> dict:
return {
"value": self.value,
"key": self.key,
"namespace": list(self.namespace),
"created_at": self.created_at.isoformat(),
"updated_at": self.updated_at.isoformat(),
}


class GetOp(NamedTuple):
"""Operation to retrieve an item by namespace and key."""
Expand Down
Loading

0 comments on commit 121587b

Please sign in to comment.