Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
eyurtsev committed Sep 14, 2024
1 parent f048281 commit 3310b00
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
2 changes: 1 addition & 1 deletion langserve/api_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
PublicTraceLink,
PublicTraceLinkCreateRequest,
)
from langserve.serialization import WellKnownLCSerializer, Serializer
from langserve.serialization import Serializer, WellKnownLCSerializer
from langserve.validation import (
BatchBaseResponse,
BatchRequestShallowValidator,
Expand Down
16 changes: 4 additions & 12 deletions langserve/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ def _decode_event_data(value: Any) -> Any:


class Serializer(abc.ABC):
@abc.abstractmethod
def dumpd(self, obj: Any) -> Any:
"""Convert the given object to a JSON serializable object."""
return orjson.loads(self.dumps(obj))

@abc.abstractmethod
def dumps(self, obj: Any) -> bytes:
Expand All @@ -169,16 +169,12 @@ def dumps(self, obj: Any) -> bytes:
def loads(self, s: bytes) -> Any:
"""Load the given JSON string."""

@abc.abstractmethod
def loadd(self, obj: Any) -> Any:
"""Load the given object."""
def loads(self, s: bytes) -> Any:
"""Load the given JSON string."""
return self.loadd(orjson.loads(s))


class WellKnownLCSerializer(Serializer):
def dumpd(self, obj: Any) -> Any:
"""Convert the given object to a JSON serializable object."""
return orjson.loads(orjson.dumps(obj, default=default))

def dumps(self, obj: Any) -> bytes:
"""Dump the given object as a JSON string."""
return orjson.dumps(obj, default=default)
Expand All @@ -187,10 +183,6 @@ def loadd(self, obj: Any) -> Any:
"""Load the given object."""
return _decode_lc_objects(obj)

def loads(self, s: bytes) -> Any:
"""Load the given JSON string."""
return self.loadd(orjson.loads(s))


def _project_top_level(model: BaseModel) -> Dict[str, Any]:
"""Project the top level of the model as dict."""
Expand Down

0 comments on commit 3310b00

Please sign in to comment.