Skip to content

doc: Improve docstrings for toolbox-langchain methods. #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions packages/toolbox-langchain/src/toolbox_langchain/async_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ 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
parameters is missing from the schema or requires
authentication. If False, only issues a warning.
"""

Expand Down Expand Up @@ -260,7 +260,7 @@ 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
parameters is missing from the schema or requires
authentication. If False, only issues a warning.

Returns:
Expand Down Expand Up @@ -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.
Expand All @@ -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)

Expand All @@ -359,17 +361,18 @@ 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 requires
authentication. If False, only a warning is issued.

Returns:
A new AsyncToolboxTool instance that is a deep copy of the current
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 requires authentication, and strict is
True.
"""

# Check if the parameter is already bound.
Expand Down Expand Up @@ -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
Expand Down
32 changes: 17 additions & 15 deletions packages/toolbox-langchain/src/toolbox_langchain/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -152,17 +153,18 @@ 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 requires
authentication. If False, only a warning is issued.

Returns:
A new ToolboxTool instance that is a deep copy of the current
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),
Expand All @@ -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:
Expand Down