mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-12 22:28:03 +00:00
core[patch]: consolidate conditional in BaseTool (#16530)
- **Description:** Refactor contradictory conditional to single line - **Issue:** #16528
This commit is contained in:
parent
5c2538b9f7
commit
f9976b9630
@ -111,25 +111,24 @@ class BaseTool(RunnableSerializable[Union[str, Dict], Any]):
|
|||||||
|
|
||||||
args_schema_type = cls.__annotations__.get("args_schema", None)
|
args_schema_type = cls.__annotations__.get("args_schema", None)
|
||||||
|
|
||||||
if args_schema_type is not None:
|
if args_schema_type is not None and args_schema_type == BaseModel:
|
||||||
if args_schema_type is None or args_schema_type == BaseModel:
|
# Throw errors for common mis-annotations.
|
||||||
# Throw errors for common mis-annotations.
|
# TODO: Use get_args / get_origin and fully
|
||||||
# TODO: Use get_args / get_origin and fully
|
# specify valid annotations.
|
||||||
# specify valid annotations.
|
typehint_mandate = """
|
||||||
typehint_mandate = """
|
|
||||||
class ChildTool(BaseTool):
|
class ChildTool(BaseTool):
|
||||||
...
|
...
|
||||||
args_schema: Type[BaseModel] = SchemaClass
|
args_schema: Type[BaseModel] = SchemaClass
|
||||||
..."""
|
..."""
|
||||||
name = cls.__name__
|
name = cls.__name__
|
||||||
raise SchemaAnnotationError(
|
raise SchemaAnnotationError(
|
||||||
f"Tool definition for {name} must include valid type annotations"
|
f"Tool definition for {name} must include valid type annotations"
|
||||||
f" for argument 'args_schema' to behave as expected.\n"
|
f" for argument 'args_schema' to behave as expected.\n"
|
||||||
f"Expected annotation of 'Type[BaseModel]'"
|
f"Expected annotation of 'Type[BaseModel]'"
|
||||||
f" but got '{args_schema_type}'.\n"
|
f" but got '{args_schema_type}'.\n"
|
||||||
f"Expected class looks like:\n"
|
f"Expected class looks like:\n"
|
||||||
f"{typehint_mandate}"
|
f"{typehint_mandate}"
|
||||||
)
|
)
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
"""The unique name of the tool that clearly communicates its purpose."""
|
"""The unique name of the tool that clearly communicates its purpose."""
|
||||||
|
Loading…
Reference in New Issue
Block a user