Skip to content

Commit

Permalink
serialization fix for defaults (#757)
Browse files Browse the repository at this point in the history
Fix serialization issue when there are defaults
  • Loading branch information
eyurtsev authored Sep 12, 2024
1 parent ff94f96 commit 36e9919
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 0 additions & 2 deletions langserve/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ def _decode_lc_objects(value: Any) -> Any:
try:
obj = WellKnownLCObject.model_validate(v)
parsed = obj.root
if set(parsed.model_dump()) != set(value):
raise ValueError("Invalid object")
return parsed
except (ValidationError, ValueError, TypeError):
return v
Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ python = "^3.9"
httpx = ">=0.23.0" # May be able to decrease this version
fastapi = {version = ">=0.90.1,<1", optional = true}
sse-starlette = {version = "^1.3.0", optional = true}
langchain-core = "0.3.0dev4"
langchain-core = "0.3.0dev5"
orjson = ">=2"
pyproject-toml = "^0.0.10"
pydantic = "^2.7"
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest
from langchain_core.documents.base import Document
from langchain_core.messages import HumanMessage, HumanMessageChunk, SystemMessage
from langchain_core.outputs import ChatGeneration
from pydantic import BaseModel

from langserve.serialization import (
Expand Down Expand Up @@ -48,8 +49,7 @@ def test_document_serialization() -> None:
"numbers": [1, 2, 3],
"boom": "Hello, world!",
},
# Requires typing ChatGeneration with Anymessage
# [ChatGeneration(message=HumanMessage(content="Hello"))],
[ChatGeneration(message=HumanMessage(content="Hello"))],
],
)
def test_serialization(data: Any) -> None:
Expand Down
2 changes: 2 additions & 0 deletions tests/unit_tests/test_server_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2675,6 +2675,7 @@ async def test_astream_events_with_prompt_model_parser_chain(
{
"additional_kwargs": {},
"content": "hello",
"example": False,
"name": None,
"response_metadata": {},
"type": "human",
Expand Down Expand Up @@ -2867,6 +2868,7 @@ async def test_astream_events_with_prompt_model_parser_chain(
],
"llm_output": None,
"run": None,
"type": "LLMResult",
},
},
"event": "on_chat_model_end",
Expand Down

0 comments on commit 36e9919

Please sign in to comment.