-
Notifications
You must be signed in to change notification settings - Fork 2.1k
anthropic fix #4733
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
Merged
Merged
anthropic fix #4733
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from unittest.mock import MagicMock | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from onyx.llm.llm_provider_options import ANTHROPIC_PROVIDER_NAME | ||
from onyx.tools.utils import explicit_tool_calling_supported | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"model_provider, model_name, mock_model_supports_fc, mock_litellm_anthropic_models, expected_result", | ||
[ | ||
# === Anthropic Scenarios (expected False due to override) === | ||
# Provider is Anthropic, base model claims FC support | ||
(ANTHROPIC_PROVIDER_NAME, "claude-3-opus-20240229", True, [], False), | ||
# Model name in litellm.anthropic_models, base model claims FC support | ||
( | ||
"another-provider", | ||
"claude-3-haiku-20240307", | ||
True, | ||
["claude-3-haiku-20240307"], | ||
False, | ||
), | ||
# Both provider is Anthropic AND model name in litellm.anthropic_models, base model claims FC support | ||
( | ||
ANTHROPIC_PROVIDER_NAME, | ||
"claude-3-sonnet-20240229", | ||
True, | ||
["claude-3-sonnet-20240229"], | ||
False, | ||
), | ||
# === Anthropic Scenarios (expected False due to base support being False) === | ||
# Provider is Anthropic, base model does NOT claim FC support | ||
(ANTHROPIC_PROVIDER_NAME, "claude-2.1", False, [], False), | ||
# === Non-Anthropic Scenarios === | ||
# Non-Anthropic provider, base model claims FC support -> True | ||
("openai", "gpt-4o", True, [], True), | ||
# Non-Anthropic provider, base model does NOT claim FC support -> False | ||
("openai", "gpt-3.5-turbo-instruct", False, [], False), | ||
# Non-Anthropic provider, model name happens to be in litellm list (should still be True if provider isn't Anthropic) | ||
( | ||
"yet-another-provider", | ||
"model-also-in-anthropic-list", | ||
True, | ||
["model-also-in-anthropic-list"], | ||
False, | ||
), | ||
# Control for the above: Non-Anthropic provider, model NOT in litellm list, supports FC -> True | ||
( | ||
"yet-another-provider", | ||
"some-other-model", | ||
True, | ||
["model-NOT-this-one"], | ||
True, | ||
), | ||
], | ||
) | ||
@patch("onyx.tools.utils.find_model_obj") | ||
@patch("onyx.tools.utils.litellm") | ||
def test_explicit_tool_calling_supported( | ||
mock_litellm: MagicMock, | ||
mock_find_model_obj: MagicMock, | ||
model_provider: str, | ||
model_name: str, | ||
mock_model_supports_fc: bool, | ||
mock_litellm_anthropic_models: list[str], | ||
expected_result: bool, | ||
) -> None: | ||
""" | ||
Anthropic models support tool calling, but | ||
a) will raise an error if you provide any tool messages and don't provide a list of tools. | ||
b) will send text before and after generating tool calls. | ||
We don't want to provide that list of tools because our UI doesn't support sequential | ||
tool calling yet for (a) and just looks bad for (b), so for now we just treat anthropic | ||
models as non-tool-calling. | ||
""" | ||
mock_find_model_obj.return_value = { | ||
"supports_function_calling": mock_model_supports_fc | ||
} | ||
mock_litellm.anthropic_models = mock_litellm_anthropic_models | ||
|
||
# get_model_map is called inside explicit_tool_calling_supported before find_model_obj, | ||
# but its return value doesn't affect the mocked find_model_obj. | ||
# So, no need to mock get_model_map separately if find_model_obj is fully mocked. | ||
|
||
actual_result = explicit_tool_calling_supported(model_provider, model_name) | ||
assert actual_result == expected_result |
Oops, something went wrong.
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.