mirror of
https://github.com/hwchase17/langchain.git
synced 2026-02-21 14:43:07 +00:00
Add Skip Validation()
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import json
|
||||
from typing import Generic, List, Type
|
||||
from typing import Generic, List, Optional, Type, Annotated
|
||||
|
||||
import pydantic # pydantic: ignore
|
||||
|
||||
from langchain_core.exceptions import OutputParserException
|
||||
from langchain_core.output_parsers import JsonOutputParser
|
||||
from pydantic import SkipValidation
|
||||
from langchain_core.outputs import Generation
|
||||
from langchain_core.utils.pydantic import (
|
||||
PYDANTIC_MAJOR_VERSION,
|
||||
@@ -15,7 +16,7 @@ from langchain_core.utils.pydantic import (
|
||||
class PydanticOutputParser(JsonOutputParser, Generic[TBaseModel]):
|
||||
"""Parse an output using a pydantic model."""
|
||||
|
||||
pydantic_object: Type[TBaseModel] # type: ignore
|
||||
pydantic_object: Annotated[Type[TBaseModel], SkipValidation()] # type: ignore
|
||||
"""The pydantic model to parse."""
|
||||
|
||||
def _parse_obj(self, obj: dict) -> TBaseModel:
|
||||
@@ -105,7 +106,7 @@ class PydanticOutputParser(JsonOutputParser, Generic[TBaseModel]):
|
||||
return self.pydantic_object
|
||||
|
||||
|
||||
PydanticOutputParser.update_forward_refs()
|
||||
PydanticOutputParser.model_rebuild()
|
||||
|
||||
|
||||
_PYDANTIC_FORMAT_INSTRUCTIONS = """The output should be formatted as a JSON instance that conforms to the JSON schema below.
|
||||
|
||||
Reference in New Issue
Block a user