mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-14 05:56:40 +00:00
core: Removing unnecessary pydantic
core schema rebuilds (#30848)
We only need to rebuild model schemas if type annotation information isn't available during declaration - that shouldn't be the case for these types corrected here. Need to do more thorough testing to make sure these structures have complete schemas, but hopefully this boosts startup / import time.
This commit is contained in:
@@ -227,9 +227,6 @@ class SerializableModel(GenericFakeChatModel):
|
||||
return True
|
||||
|
||||
|
||||
SerializableModel.model_rebuild()
|
||||
|
||||
|
||||
def test_serialization_with_rate_limiter() -> None:
|
||||
"""Test model serialization with rate limiter."""
|
||||
from langchain_core.load import dumps
|
||||
|
@@ -45,8 +45,6 @@ def test_base_generation_parser() -> None:
|
||||
assert isinstance(content, str)
|
||||
return content.swapcase()
|
||||
|
||||
StrInvertCase.model_rebuild()
|
||||
|
||||
model = GenericFakeChatModel(messages=iter([AIMessage(content="hEllo")]))
|
||||
chain = model | StrInvertCase()
|
||||
assert chain.invoke("") == "HeLLO"
|
||||
|
@@ -35,9 +35,6 @@ class FakeStructuredChatModel(FakeListChatModel):
|
||||
return "fake-messages-list-chat-model"
|
||||
|
||||
|
||||
FakeStructuredChatModel.model_rebuild()
|
||||
|
||||
|
||||
def test_structured_prompt_pydantic() -> None:
|
||||
class OutputSchema(BaseModel):
|
||||
name: str
|
||||
|
@@ -1188,9 +1188,6 @@ class HardCodedRetriever(BaseRetriever):
|
||||
return self.documents
|
||||
|
||||
|
||||
HardCodedRetriever.model_rebuild()
|
||||
|
||||
|
||||
async def test_event_stream_with_retriever() -> None:
|
||||
"""Test the event stream with a retriever."""
|
||||
retriever = HardCodedRetriever(
|
||||
|
20
libs/core/tests/unit_tests/test_pydantic_imports.py
Normal file
20
libs/core/tests/unit_tests/test_pydantic_imports.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import importlib
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
def test_all_models_built() -> None:
|
||||
for path in Path("../core/langchain_core/").glob("*"):
|
||||
module_name = path.stem
|
||||
if not module_name.startswith(".") and path.suffix != ".typed":
|
||||
module = importlib.import_module("langchain_core." + module_name)
|
||||
all_ = getattr(module, "__all__", [])
|
||||
for attr_name in all_:
|
||||
attr = getattr(module, attr_name)
|
||||
try:
|
||||
if issubclass(attr, BaseModel):
|
||||
assert attr.__pydantic_complete__ is True
|
||||
except TypeError:
|
||||
# This is expected for non-class attributes
|
||||
pass
|
@@ -1091,9 +1091,6 @@ class FooBase(BaseTool):
|
||||
return assert_bar(bar, bar_config)
|
||||
|
||||
|
||||
FooBase.model_rebuild()
|
||||
|
||||
|
||||
class AFooBase(FooBase):
|
||||
async def _arun(self, bar: Any, bar_config: RunnableConfig, **kwargs: Any) -> Any:
|
||||
return assert_bar(bar, bar_config)
|
||||
|
Reference in New Issue
Block a user