Skip to content

Commit 0b5e106

Browse files
committed
add headers
1 parent 79005ad commit 0b5e106

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

packages/toolbox-langchain/src/toolbox_langchain/async_client.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Any, Callable, Optional, Union
15+
from typing import Any, Callable, Optional, Union, Mapping, Awaitable
1616
from warnings import warn
1717

1818
from aiohttp import ClientSession
@@ -30,6 +30,9 @@ def __init__(
3030
self,
3131
url: str,
3232
session: ClientSession,
33+
client_headers: Optional[
34+
Mapping[str, Union[Callable[[], str], Callable[[], Awaitable[str]], str]]
35+
] = None,
3336
):
3437
"""
3538
Initializes the AsyncToolboxClient for the Toolbox service at the given URL.
@@ -38,7 +41,7 @@ def __init__(
3841
url: The base URL of the Toolbox service.
3942
session: An HTTP client session.
4043
"""
41-
self.__core_client = ToolboxCoreClient(url=url, session=session)
44+
self.__core_client = ToolboxCoreClient(url=url, session=session, client_headers=client_headers)
4245

4346
async def aload_tool(
4447
self,
@@ -185,3 +188,18 @@ def load_toolset(
185188
strict: bool = False,
186189
) -> list[AsyncToolboxTool]:
187190
raise NotImplementedError("Synchronous methods not supported by async client.")
191+
192+
def add_headers(
193+
self,
194+
headers: Mapping[str, Union[Callable[[], str], Callable[[], Awaitable[str]]]],
195+
) -> None:
196+
"""
197+
Add headers to be included in each request sent through this client.
198+
199+
Args:
200+
headers: Headers to include in each request sent through this client.
201+
202+
Raises:
203+
ValueError: If any of the headers are already registered in the client.
204+
"""
205+
self.__core_client.add_headers(headers)

packages/toolbox-langchain/src/toolbox_langchain/client.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
from asyncio import to_thread
16-
from typing import Any, Callable, Optional, Union
16+
from typing import Any, Callable, Optional, Union, Mapping, Awaitable
1717
from warnings import warn
1818

1919
from toolbox_core.sync_client import ToolboxSyncClient as ToolboxCoreSyncClient
@@ -26,14 +26,17 @@ class ToolboxClient:
2626
def __init__(
2727
self,
2828
url: str,
29+
client_headers: Optional[
30+
Mapping[str, Union[Callable[[], str], Callable[[], Awaitable[str]], str]]
31+
] = None,
2932
) -> None:
3033
"""
3134
Initializes the ToolboxClient for the Toolbox service at the given URL.
3235
3336
Args:
3437
url: The base URL of the Toolbox service.
3538
"""
36-
self.__core_client = ToolboxCoreSyncClient(url=url)
39+
self.__core_client = ToolboxCoreSyncClient(url=url, client_headers=client_headers)
3740

3841
async def aload_tool(
3942
self,
@@ -286,3 +289,18 @@ def load_toolset(
286289
for core_sync_tool in core_sync_tools:
287290
tools.append(ToolboxTool(core_tool=core_sync_tool))
288291
return tools
292+
293+
def add_headers(
294+
self,
295+
headers: Mapping[str, Union[Callable[[], str], Callable[[], Awaitable[str]]]],
296+
) -> None:
297+
"""
298+
Add headers to be included in each request sent through this client.
299+
300+
Args:
301+
headers: Headers to include in each request sent through this client.
302+
303+
Raises:
304+
ValueError: If any of the headers are already registered in the client.
305+
"""
306+
self.__core_client.add_headers(headers)

0 commit comments

Comments
 (0)