|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 |
| -import asyncio |
| 15 | +from asyncio import wrap_future |
16 | 16 | from typing import Any, Callable, Optional, Union
|
17 | 17 | from warnings import warn
|
18 | 18 |
|
@@ -85,30 +85,14 @@ async def aload_tool(
|
85 | 85 | )
|
86 | 86 | auth_token_getters = auth_headers
|
87 | 87 |
|
88 |
| - coro = self.__core_client._async_client.load_tool( |
89 |
| - name=tool_name, |
90 |
| - auth_token_getters=auth_token_getters, |
91 |
| - bound_params=bound_params, |
92 |
| - ) |
93 |
| - |
94 |
| - if not self.__core_client._loop: |
95 |
| - # If a loop has not been provided, attempt to run in current thread. |
96 |
| - core_tool = await coro |
97 |
| - else: |
98 |
| - # Otherwise, run in the background thread. |
99 |
| - core_tool = await asyncio.wrap_future( |
100 |
| - asyncio.run_coroutine_threadsafe(coro, self.__core_client._loop) |
| 88 | + core_tool = await wrap_future( |
| 89 | + self.__core_client._load_tool_future( |
| 90 | + name=tool_name, |
| 91 | + auth_token_getters=auth_token_getters, |
| 92 | + bound_params=bound_params, |
101 | 93 | )
|
102 |
| - |
103 |
| - if not self.__core_client._loop or not self.__core_client._thread: |
104 |
| - raise ValueError("Background loop or thread cannot be None.") |
105 |
| - |
106 |
| - core_sync_tool = ToolboxSyncTool( |
107 |
| - core_tool, |
108 |
| - self.__core_client._loop, |
109 |
| - self.__core_client._thread, |
110 | 94 | )
|
111 |
| - return ToolboxTool(core_tool=core_sync_tool) |
| 95 | + return ToolboxTool(core_tool=core_tool) |
112 | 96 |
|
113 | 97 | async def aload_toolset(
|
114 | 98 | self,
|
@@ -167,36 +151,18 @@ async def aload_toolset(
|
167 | 151 | )
|
168 | 152 | auth_token_getters = auth_headers
|
169 | 153 |
|
170 |
| - coro = self.__core_client._async_client.load_toolset( |
171 |
| - name=toolset_name, |
172 |
| - auth_token_getters=auth_token_getters, |
173 |
| - bound_params=bound_params, |
174 |
| - strict=strict, |
175 |
| - ) |
176 |
| - |
177 |
| - if not self.__core_client._loop: |
178 |
| - # If a loop has not been provided, attempt to run in current thread. |
179 |
| - core_tools = await coro |
180 |
| - else: |
181 |
| - # Otherwise, run in the background thread. |
182 |
| - core_tools = await asyncio.wrap_future( |
183 |
| - asyncio.run_coroutine_threadsafe(coro, self.__core_client._loop) |
| 154 | + core_tools = await wrap_future( |
| 155 | + self.__core_client._load_toolset_future( |
| 156 | + name=toolset_name, |
| 157 | + auth_token_getters=auth_token_getters, |
| 158 | + bound_params=bound_params, |
| 159 | + strict=strict, |
184 | 160 | )
|
| 161 | + ) |
185 | 162 |
|
186 |
| - if not self.__core_client._loop or not self.__core_client._thread: |
187 |
| - raise ValueError("Background loop or thread cannot be None.") |
188 |
| - |
189 |
| - core_sync_tools = [ |
190 |
| - ToolboxSyncTool( |
191 |
| - core_tool, |
192 |
| - self.__core_client._loop, |
193 |
| - self.__core_client._thread, |
194 |
| - ) |
195 |
| - for core_tool in core_tools |
196 |
| - ] |
197 | 163 | tools = []
|
198 |
| - for core_sync_tool in core_sync_tools: |
199 |
| - tools.append(ToolboxTool(core_tool=core_sync_tool)) |
| 164 | + for core_tool in core_tools: |
| 165 | + tools.append(ToolboxTool(core_tool=core_tool)) |
200 | 166 | return tools
|
201 | 167 |
|
202 | 168 | def load_tool(
|
|
0 commit comments