Skip to content

Commit eed2f8c

Browse files
Wrap langchain tool code example by asyncio runner (#8322)
* add asyncio runner * use a different alias
1 parent 19d846a commit eed2f8c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

dspy/adapters/types/tool.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,23 @@ def from_langchain(cls, tool: "BaseTool") -> "Tool":
206206
A Tool object.
207207
208208
Example:
209+
209210
```python
210-
from langchain.tools import tool
211+
import asyncio
211212
import dspy
213+
from langchain.tools import tool as lc_tool
212214
213-
@tool
215+
@lc_tool
214216
def add(x: int, y: int):
215217
"Add two numbers together."
216218
return x + y
217219
218-
tool = dspy.Tool.from_langchain(add)
219-
print(await tool.acall(x=1, y=2))
220+
dspy_tool = dspy.Tool.from_langchain(add)
221+
222+
async def run_tool():
223+
return await dspy_tool.acall(x=1, y=2)
224+
225+
print(asyncio.run(run_tool()))
220226
# 3
221227
```
222228
"""

0 commit comments

Comments
 (0)