Fix Mock len() error: Correct bind_tools chain

- bind_tools() now returns a mock chain
- chain.invoke() returns the result with tool_calls attribute
- Fixes TypeError: object of type 'Mock' has no len()
This commit is contained in:
佐藤優一 2025-08-11 11:01:16 +09:00
parent 5fbd49cedc
commit 085da18205
1 changed files with 6 additions and 1 deletions

View File

@ -37,8 +37,13 @@ def mock_llm():
mock_result.content = "Test response"
mock_result.tool_calls = [] # Add tool_calls attribute for len() check
# Fix: bind_tools returns a chain, chain.invoke returns the result
mock_chain = Mock()
mock_chain.invoke.return_value = mock_result
mock.bind_tools.return_value = mock_chain
# Keep direct invoke for backward compatibility
mock.invoke.return_value = mock_result
mock.bind_tools.return_value = mock
return mock