phidatahq / phidata

Build AI Assistants with memory, knowledge and tools.
https://docs.phidata.com
Mozilla Public License 2.0
11.14k stars 1.65k forks source link

openrouter claude3.5 tool use failed #1104

Open wangdake5111 opened 3 weeks ago

wangdake5111 commented 3 weeks ago

When I use the the model 'anthropic/claude-3.5-sonnet' of openrouter to use tool yfinance,

from phi.assistant import Assistant
from phi.llm.openrouter import OpenRouter
from phi.tools.yfinance import YFinanceTools
assistant = Assistant(
    llm=OpenRouter(model="anthropic/claude-3.5-sonnet"),
    tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)],
    show_tool_calls=True,
    debug_mode=True,
    markdown=True,
)
assistant.print_response("What is the stock price of NVDA")
assistant.print_response("Write a comparison between NVDA and AMD, use all tools available.")

there will be an error

CleanShot 2024-08-21 at 20 18 41@2x

Missing required argument [type=missing_argument, input_value=ArgsKwargs(()), input_type=ArgsKwargs] I see in the debug mode, this is the output:

Tool Calls: [
           {
             "id": "toolu_016QmLxNKSHwVwzCEiUadoAx",
             "type": "function",
             "function": {
               "name": "get_current_stock_price",
               "arguments": ""
             }
           },
           {
             "id": null,
             "type": "function",
             "function": {
               "arguments": "{\"symbol\": \"NVDA\"}"
             }
           }
         ]

It seems the func and arguments separated. But if I use 'openai/gpt-4o', it will work well. Also, if I use 'anthropic/claude-3.5-sonnet' with tool DuckDuckGo, it will work well.

ysolanky commented 3 weeks ago

@wangdake5111 it looks like anthropic/claude-3.5-sonnet is making an incorrect function call, which is resulting in the pydantic error that you shared.

Could you please try updating the tools to the following and sharing your result? tools=[YFinanceTools(stock_price=True)]