-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Python: Fix OllamaChatClient passing unsupported kwargs to ollama.AsyncClient… #4403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
max-montes
wants to merge
6
commits into
microsoft:main
from
max-montes:fix/ollama-filter-unsupported-kwargs
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6257983
Fix OllamaChatClient passing unsupported kwargs to ollama.AsyncClient…
max-montes af23914
ci: retrigger checks
max-montes 60d81fb
ci: retrigger checks (GitHub 500 on checkout)
max-montes 94091be
ci: retrigger checks (post-outage)
max-montes dda5159
Merge branch 'main' into fix/ollama-filter-unsupported-kwargs
max-montes fe62436
Merge branch 'main' into fix/ollama-filter-unsupported-kwargs
max-montes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -248,6 +248,62 @@ async def test_cmc( | |
| assert result.text == "test" | ||
|
|
||
|
|
||
| @patch.object(AsyncClient, "chat", new_callable=AsyncMock) | ||
| async def test_cmc_ignores_unsupported_kwargs( | ||
| mock_chat: AsyncMock, | ||
| ollama_unit_test_env: dict[str, str], | ||
| chat_history: list[Message], | ||
| mock_chat_completion_response: OllamaChatResponse, | ||
| ) -> None: | ||
| """Verify that unsupported kwargs (e.g. allow_multiple_tool_calls) are | ||
| silently filtered out and never forwarded to ollama.AsyncClient.chat(). | ||
|
|
||
| Regression test for: https://github.com/microsoft/agent-framework/issues/4402 | ||
| """ | ||
| mock_chat.return_value = mock_chat_completion_response | ||
| chat_history.append(Message(text="hello world", role="user")) | ||
|
|
||
| ollama_client = OllamaChatClient() | ||
| result = await ollama_client.get_response( | ||
| messages=chat_history, | ||
| allow_multiple_tool_calls=True, | ||
| ) | ||
|
|
||
| assert result.text == "test" | ||
| mock_chat.assert_called_once() | ||
| call_kwargs = mock_chat.call_args.kwargs | ||
| assert "allow_multiple_tool_calls" not in call_kwargs | ||
|
|
||
|
|
||
| @patch.object(AsyncClient, "chat", new_callable=AsyncMock) | ||
| async def test_cmc_streaming_ignores_unsupported_kwargs( | ||
| mock_chat: AsyncMock, | ||
| ollama_unit_test_env: dict[str, str], | ||
| chat_history: list[Message], | ||
| mock_streaming_chat_completion_response: AsyncStream[OllamaChatResponse], | ||
| ) -> None: | ||
| """Verify that unsupported kwargs are filtered in streaming mode too. | ||
|
|
||
| Regression test for: https://github.com/microsoft/agent-framework/issues/4402 | ||
| """ | ||
| mock_chat.return_value = mock_streaming_chat_completion_response | ||
| chat_history.append(Message(text="hello world", role="user")) | ||
|
|
||
| ollama_client = OllamaChatClient() | ||
| result = ollama_client.get_response( | ||
| messages=chat_history, | ||
| stream=True, | ||
| allow_multiple_tool_calls=True, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is no longer a valid pattern, one should always use |
||
| ) | ||
|
|
||
| async for chunk in result: | ||
| assert chunk.text == "test" | ||
|
|
||
| mock_chat.assert_called_once() | ||
| call_kwargs = mock_chat.call_args.kwargs | ||
| assert "allow_multiple_tool_calls" not in call_kwargs | ||
|
|
||
|
|
||
| @patch.object(AsyncClient, "chat", new_callable=AsyncMock) | ||
| async def test_cmc_reasoning( | ||
| mock_chat: AsyncMock, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.