-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
What happened?
The manual tool calling provided in the documentation is itself not working giving the error provided in the description.
Steps to reproduce
import dspy
class ToolSignature(dspy.Signature):
"""Signature for manual tool handling."""
question: str = dspy.InputField()
tools: list[dspy.Tool] = dspy.InputField()
outputs: dspy.ToolCalls = dspy.OutputField()
def weather(city: str) -> str:
"""Get weather information for a city."""
return f"The weather in {city} is sunny"
def calculator(expression: str) -> str:
"""Evaluate a mathematical expression."""
try:
result = eval(expression) # Note: Use safely in production
return f"The result is {result}"
except:
return "Invalid expression"
Create tool instances
tools = {"weather": dspy.Tool(weather), "calculator": dspy.Tool(calculator)}
Create predictor
predictor = dspy.Predict(ToolSignature)
Make a prediction
response = predictor(
question="What's the weather in New York?", tools=list(tools.values())
)
Execute the tool calls
for call in response.outputs.tool_calls:
# Execute the tool call
result = call.execute()
print(f"Tool: {call.name}")
print(f"Args: {call.args}")
# print(f"Result: {result}")
This is the code that is present in the documentation. It is itself not working, giving the below error.
AttributeError Traceback (most recent call last)
Cell In[44], line 40
37 # Execute the tool calls
38 for call in response.outputs.tool_calls:
39 # Execute the tool call
---> 40 result = call.execute()
41 print(f"Tool: {call.name}")
42 print(f"Args: {call.args}")
File ~/Mayank_python/personal_projects/data_science_monorepo/projects/agents/.venv/lib/python3.11/site-packages/pydantic/main.py:991, in BaseModel.getattr(self, item)
988 return super().getattribute(item) # Raises AttributeError if appropriate
989 else:
990 # this is the current error
--> 991 raise AttributeError(f'{type(self).name!r} object has no attribute {item!r}')
AttributeError: 'ToolCall' object has no attribute 'execute'
DSPy version
3.0.3