From 767d187f1e815c4d15a37e2a37942cb17bb1f1a0 Mon Sep 17 00:00:00 2001 From: Shroominic Date: Sat, 11 Nov 2023 22:02:16 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Update=20docstring,=20refactor?= =?UTF-8?q?=20imports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- funcchain/utils/function_frame.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/funcchain/utils/function_frame.py b/funcchain/utils/function_frame.py index 32d9033..b329e89 100644 --- a/funcchain/utils/function_frame.py +++ b/funcchain/utils/function_frame.py @@ -9,6 +9,9 @@ def get_parent_frame(depth: int = 5) -> FrameInfo: + """ + Get the dep'th parent function information. + """ return getouterframes(currentframe())[depth] @@ -36,24 +39,24 @@ def parser_for(output_type: type) -> BaseOutputParser | None: """ if isinstance(output_type, types.UnionType): return None + # return MultiPydanticOutputParser(pydantic_objects=output_type.__args__) if getattr(output_type, "__origin__", None) is Union: output_type = output_type.__args__[0] # type: ignore return None + # return MultiPydanticOutputParser(pydantic_objects=output_type.__args__) if output_type is str: return StrOutputParser() if output_type is bool: return BoolOutputParser() if issubclass(output_type, ParserBaseModel): - return output_type.output_parser() - from langchain.pydantic_v1 import BaseModel + return output_type.output_parser() # type: ignore + + from pydantic.v1 import BaseModel if issubclass(output_type, BaseModel): return PydanticOutputParser(pydantic_object=output_type) - # TODO: Add support for Union without function calling - # if getattr(output_type, "__origin__", None) is Union: - # return MultiPydanticOutputParser(pydantic_objects=output_type.__args__) else: - raise NotImplementedError(f"Unknown output type: {output_type}") + raise RuntimeError(f"Output Type is not supported: {output_type}") def kwargs_from_parent() -> dict[str, str]: