langchain[patch]: Migrate output parsers to support optional community imports (#21103)

Migrate output parsers
This commit is contained in:
Eugene Yurtsev 2024-04-30 16:24:29 -04:00 committed by GitHub
parent 3853fe9f64
commit 9e788f09c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 82 additions and 11 deletions

View File

@ -12,6 +12,8 @@
Serializable, Generation, PromptValue
""" # noqa: E501
from typing import TYPE_CHECKING, Any
from langchain_core.output_parsers import (
CommaSeparatedListOutputParser,
ListOutputParser,
@ -26,6 +28,7 @@ from langchain_core.output_parsers.openai_tools import (
PydanticToolsParser,
)
from langchain._api import create_importer
from langchain.output_parsers.boolean import BooleanOutputParser
from langchain.output_parsers.combining import CombiningOutputParser
from langchain.output_parsers.datetime import DatetimeOutputParser
@ -39,6 +42,24 @@ from langchain.output_parsers.retry import RetryOutputParser, RetryWithErrorOutp
from langchain.output_parsers.structured import ResponseSchema, StructuredOutputParser
from langchain.output_parsers.yaml import YamlOutputParser
if TYPE_CHECKING:
from langchain_community.output_parsers.rail_parser import GuardrailsOutputParser
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"GuardrailsOutputParser": "langchain_community.output_parsers.rail_parser"
}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"BooleanOutputParser",
"CombiningOutputParser",

View File

@ -1,10 +1,40 @@
from langchain_community.output_parsers.ernie_functions import (
JsonKeyOutputFunctionsParser,
JsonOutputFunctionsParser,
OutputFunctionsParser,
PydanticAttrOutputFunctionsParser,
PydanticOutputFunctionsParser,
)
from typing import TYPE_CHECKING, Any
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.output_parsers.ernie_functions import (
JsonKeyOutputFunctionsParser,
JsonOutputFunctionsParser,
OutputFunctionsParser,
PydanticAttrOutputFunctionsParser,
PydanticOutputFunctionsParser,
)
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"JsonKeyOutputFunctionsParser": (
"langchain_community.output_parsers.ernie_functions"
),
"JsonOutputFunctionsParser": "langchain_community.output_parsers.ernie_functions",
"OutputFunctionsParser": "langchain_community.output_parsers.ernie_functions",
"PydanticAttrOutputFunctionsParser": (
"langchain_community.output_parsers.ernie_functions"
),
"PydanticOutputFunctionsParser": (
"langchain_community.output_parsers.ernie_functions"
),
}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"JsonKeyOutputFunctionsParser",

View File

@ -1,5 +1,25 @@
from langchain_community.output_parsers.rail_parser import (
GuardrailsOutputParser,
)
from typing import TYPE_CHECKING, Any
__all__ = ["GuardrailsOutputParser"]
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.output_parsers.rail_parser import GuardrailsOutputParser
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"GuardrailsOutputParser": "langchain_community.output_parsers.rail_parser"
}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"GuardrailsOutputParser",
]