Skip to content

Commit ac1df51

Browse files
committed
fix: Use correct core client interfaces in langchain client
1 parent 6f13f6c commit ac1df51

File tree

1 file changed

+16
-50
lines changed
  • packages/toolbox-langchain/src/toolbox_langchain

1 file changed

+16
-50
lines changed

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

Lines changed: 16 additions & 50 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-
import asyncio
15+
from asyncio import wrap_future
1616
from typing import Any, Callable, Optional, Union
1717
from warnings import warn
1818

@@ -85,30 +85,14 @@ async def aload_tool(
8585
)
8686
auth_token_getters = auth_headers
8787

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,
10193
)
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,
11094
)
111-
return ToolboxTool(core_tool=core_sync_tool)
95+
return ToolboxTool(core_tool=core_tool)
11296

11397
async def aload_toolset(
11498
self,
@@ -167,36 +151,18 @@ async def aload_toolset(
167151
)
168152
auth_token_getters = auth_headers
169153

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,
184160
)
161+
)
185162

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-
]
197163
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))
200166
return tools
201167

202168
def load_tool(

0 commit comments

Comments
 (0)