Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add logic to serialize objects of Send class #722

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions langserve/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
any information about the exception. This is done to prevent leaking
sensitive information from the server to the client.
"""

import abc
import logging
from functools import lru_cache
Expand Down Expand Up @@ -38,6 +39,7 @@
)
from langchain_core.prompt_values import ChatPromptValueConcrete
from langchain_core.prompts.base import StringPromptValue
from langgraph.constants import Send

from langserve.pydantic_v1 import BaseModel, ValidationError
from langserve.validation import CallbackEvent
Expand Down Expand Up @@ -87,6 +89,8 @@ def default(obj) -> Any:
"""Default serialization for well known objects."""
if isinstance(obj, BaseModel):
return obj.dict()
if isinstance(obj, Send):
return {"node": obj.node, "arg": obj.arg}
return super().default(obj)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of super without a class context is a bug here. Can we give the default serializer more powers to allow any object to be become json serializable?

Suggested change
return super().default(obj)
try:
return obj.__dict__()
except:
pass
raise TypeError(f"Object of type {obj.__class__.__name__} is not JSON serializable")



Expand Down