From c082a6d72710b7bf87b0c75376350cf26c3792f7 Mon Sep 17 00:00:00 2001 From: Anubhav Dhawan Date: Fri, 11 Apr 2025 17:27:54 +0530 Subject: [PATCH 1/2] doc: Improve docstrings for toolbox-langchain methods. --- .../src/toolbox_langchain/async_tools.py | 43 ++++++++++--------- .../src/toolbox_langchain/tools.py | 32 +++++++------- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/packages/toolbox-langchain/src/toolbox_langchain/async_tools.py b/packages/toolbox-langchain/src/toolbox_langchain/async_tools.py index 0593213c..4d7663bf 100644 --- a/packages/toolbox-langchain/src/toolbox_langchain/async_tools.py +++ b/packages/toolbox-langchain/src/toolbox_langchain/async_tools.py @@ -62,8 +62,8 @@ def __init__( bound_params: A mapping of parameter names to their bound values. strict: If True, raises a ValueError if any of the given bound - parameters are missing from the schema or require - authentication. If False, only issues a warning. + parameters is missing from the schema or require authentication. + If False, only issues a warning. """ # If the schema is not already a ToolSchema instance, we create one from @@ -260,8 +260,8 @@ def __create_copy( bound values or functions to retrieve the values. These params will be merged with the existing bound params. strict: If True, raises a ValueError if any of the given bound - parameters are missing from the schema or require - authentication. If False, only issues a warning. + parameters is missing from the schema or require authentication. + If False, only issues a warning. Returns: A new AsyncToolboxTool instance that is a deep copy of the current @@ -297,16 +297,18 @@ def add_auth_tokens( auth_tokens: A dictionary of authentication source names to the functions that return corresponding ID token. strict: If True, a ValueError is raised if any of the provided auth - tokens are already bound. If False, only a warning is issued. + parameters is already bound. If False, only a warning is issued. Returns: A new AsyncToolboxTool instance that is a deep copy of the current instance, with added auth tokens. Raises: - ValueError: If the provided auth tokens are already registered. - ValueError: If the provided auth tokens are already bound and strict - is True. + ValueError: If any of the provided auth parameters is already + registered. + ValueError: If any of the provided auth parameters is already bound + and strict is True. + """ # Check if the authentication source is already registered. @@ -332,17 +334,17 @@ def add_auth_token( Args: auth_source: The name of the authentication source. get_id_token: A function that returns the ID token. - strict: If True, a ValueError is raised if any of the provided auth - token is already bound. If False, only a warning is issued. + strict: If True, a ValueError is raised if the provided auth + parameter is already bound. If False, only a warning is issued. Returns: A new ToolboxTool instance that is a deep copy of the current instance, with added auth token. Raises: - ValueError: If the provided auth token is already registered. - ValueError: If the provided auth token is already bound and strict - is True. + ValueError: If the provided auth parameter is already registered. + ValueError: If the provided auth parameter is already bound and + strict is True. """ return self.add_auth_tokens({auth_source: get_id_token}, strict=strict) @@ -359,7 +361,7 @@ def bind_params( bound_params: A dictionary of the bound parameter name to the value or function of the bound value. strict: If True, a ValueError is raised if any of the provided bound - params are not defined in the tool's schema, or require + params is not defined in the tool's schema, or require authentication. If False, only a warning is issued. Returns: @@ -367,9 +369,10 @@ def bind_params( instance, with added bound params. Raises: - ValueError: If the provided bound params are already bound. - ValueError: if the provided bound params are not defined in the tool's schema, or require - authentication, and strict is True. + ValueError: If any of the provided bound params is already bound. + ValueError: if any of the provided bound params is not defined in + the tool's schema, or require authentication, and strict is + True. """ # Check if the parameter is already bound. @@ -399,9 +402,9 @@ def bind_param( param_name: The name of the bound parameter. param_value: The value of the bound parameter, or a callable that returns the value. - strict: If True, a ValueError is raised if any of the provided bound - params is not defined in the tool's schema, or requires - authentication. If False, only a warning is issued. + strict: If True, a ValueError is raised if the provided bound param + is not defined in the tool's schema, or requires authentication. + If False, only a warning is issued. Returns: A new ToolboxTool instance that is a deep copy of the current diff --git a/packages/toolbox-langchain/src/toolbox_langchain/tools.py b/packages/toolbox-langchain/src/toolbox_langchain/tools.py index f19b3d61..6db37fed 100644 --- a/packages/toolbox-langchain/src/toolbox_langchain/tools.py +++ b/packages/toolbox-langchain/src/toolbox_langchain/tools.py @@ -94,16 +94,17 @@ def add_auth_tokens( auth_tokens: A dictionary of authentication source names to the functions that return corresponding ID token. strict: If True, a ValueError is raised if any of the provided auth - tokens are already bound. If False, only a warning is issued. + parameters is already bound. If False, only a warning is issued. Returns: A new ToolboxTool instance that is a deep copy of the current instance, with added auth tokens. Raises: - ValueError: If the provided auth tokens are already registered. - ValueError: If the provided auth tokens are already bound and strict - is True. + ValueError: If any of the provided auth parameters is already + registered. + ValueError: If any of the provided auth parameters is already bound + and strict is True. """ return ToolboxTool( self.__async_tool.add_auth_tokens(auth_tokens, strict), @@ -121,17 +122,17 @@ def add_auth_token( Args: auth_source: The name of the authentication source. get_id_token: A function that returns the ID token. - strict: If True, a ValueError is raised if any of the provided auth - token is already bound. If False, only a warning is issued. + strict: If True, a ValueError is raised if the provided auth + parameter is already bound. If False, only a warning is issued. Returns: A new ToolboxTool instance that is a deep copy of the current instance, with added auth token. Raises: - ValueError: If the provided auth token is already registered. - ValueError: If the provided auth token is already bound and strict - is True. + ValueError: If the provided auth parameter is already registered. + ValueError: If the provided auth parameter is already bound and + strict is True. """ return ToolboxTool( self.__async_tool.add_auth_token(auth_source, get_id_token, strict), @@ -152,7 +153,7 @@ def bind_params( bound_params: A dictionary of the bound parameter name to the value or function of the bound value. strict: If True, a ValueError is raised if any of the provided bound - params are not defined in the tool's schema, or require + params is not defined in the tool's schema, or require authentication. If False, only a warning is issued. Returns: @@ -160,9 +161,10 @@ def bind_params( instance, with added bound params. Raises: - ValueError: If the provided bound params are already bound. - ValueError: if the provided bound params are not defined in the tool's schema, or require - authentication, and strict is True. + ValueError: If any of the provided bound params is already bound. + ValueError: if any of the provided bound params is not defined in + the tool's schema, or require authentication, and strict is + True. """ return ToolboxTool( self.__async_tool.bind_params(bound_params, strict), @@ -184,8 +186,8 @@ def bind_param( param_name: The name of the bound parameter. param_value: The value of the bound parameter, or a callable that returns the value. - strict: If True, a ValueError is raised if any of the provided bound - params is not defined in the tool's schema, or requires + strict: If True, a ValueError is raised if the provided bound + param is not defined in the tool's schema, or requires authentication. If False, only a warning is issued. Returns: From 927806d44b0ea0038d1a8d8fe2508cc0e3c49d9b Mon Sep 17 00:00:00 2001 From: Anubhav Dhawan Date: Mon, 14 Apr 2025 18:46:43 +0530 Subject: [PATCH 2/2] doc: Fix grammatical errors --- .../src/toolbox_langchain/async_tools.py | 12 ++++++------ .../toolbox-langchain/src/toolbox_langchain/tools.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/toolbox-langchain/src/toolbox_langchain/async_tools.py b/packages/toolbox-langchain/src/toolbox_langchain/async_tools.py index 4d7663bf..c7aafc12 100644 --- a/packages/toolbox-langchain/src/toolbox_langchain/async_tools.py +++ b/packages/toolbox-langchain/src/toolbox_langchain/async_tools.py @@ -62,8 +62,8 @@ def __init__( bound_params: A mapping of parameter names to their bound values. strict: If True, raises a ValueError if any of the given bound - parameters is missing from the schema or require authentication. - If False, only issues a warning. + parameters is missing from the schema or requires + authentication. If False, only issues a warning. """ # If the schema is not already a ToolSchema instance, we create one from @@ -260,8 +260,8 @@ def __create_copy( bound values or functions to retrieve the values. These params will be merged with the existing bound params. strict: If True, raises a ValueError if any of the given bound - parameters is missing from the schema or require authentication. - If False, only issues a warning. + parameters is missing from the schema or requires + authentication. If False, only issues a warning. Returns: A new AsyncToolboxTool instance that is a deep copy of the current @@ -361,7 +361,7 @@ def bind_params( bound_params: A dictionary of the bound parameter name to the value or function of the bound value. strict: If True, a ValueError is raised if any of the provided bound - params is not defined in the tool's schema, or require + params is not defined in the tool's schema, or requires authentication. If False, only a warning is issued. Returns: @@ -371,7 +371,7 @@ def bind_params( Raises: ValueError: If any of the provided bound params is already bound. ValueError: if any of the provided bound params is not defined in - the tool's schema, or require authentication, and strict is + the tool's schema, or requires authentication, and strict is True. """ diff --git a/packages/toolbox-langchain/src/toolbox_langchain/tools.py b/packages/toolbox-langchain/src/toolbox_langchain/tools.py index 6db37fed..b7793b96 100644 --- a/packages/toolbox-langchain/src/toolbox_langchain/tools.py +++ b/packages/toolbox-langchain/src/toolbox_langchain/tools.py @@ -153,7 +153,7 @@ def bind_params( bound_params: A dictionary of the bound parameter name to the value or function of the bound value. strict: If True, a ValueError is raised if any of the provided bound - params is not defined in the tool's schema, or require + params is not defined in the tool's schema, or requires authentication. If False, only a warning is issued. Returns: