-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tool calls with response model (#1812)
## Description Tool calling does not work correctly with response models. This will use the response model if there is one, overriding any tool calling. The tool calls are then displayed separately. This also solves the issue for teams. Fixes #1792
- Loading branch information
Showing
15 changed files
with
181 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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
File renamed without changes.
Empty file.
This file contains 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,65 @@ | ||
from phi.utils.string import extract_valid_json | ||
|
||
|
||
def test_extract_valid_json_with_valid_json(): | ||
content = 'Here is some text {"key": "value"} and more text.' | ||
expected_json = {"key": "value"} | ||
extracted_json = extract_valid_json(content) | ||
assert extracted_json == expected_json | ||
|
||
|
||
def test_extract_valid_json_with_nested_json(): | ||
content = 'Start {"key": {"nested_key": "nested_value"}} End' | ||
expected_json = {"key": {"nested_key": "nested_value"}} | ||
extracted_json = extract_valid_json(content) | ||
assert extracted_json == expected_json | ||
|
||
|
||
def test_extract_valid_json_with_multiple_json_objects(): | ||
content = 'First {"key1": "value1"} Second {"key2": "value2"}' | ||
expected_json = {"key1": "value1"} # Only the first JSON should be returned | ||
extracted_json = extract_valid_json(content) | ||
assert extracted_json == expected_json | ||
|
||
|
||
def test_extract_valid_json_with_no_json(): | ||
content = "This is a string without JSON." | ||
extracted_json = extract_valid_json(content) | ||
assert extracted_json is None | ||
|
||
|
||
def test_extract_valid_json_with_invalid_json(): | ||
content = "This string contains {invalid JSON}." | ||
extracted_json = extract_valid_json(content) | ||
assert extracted_json is None | ||
|
||
|
||
def test_extract_valid_json_with_json_array(): | ||
content = 'Here is a JSON array: ["item1", "item2"].' | ||
extracted_json = extract_valid_json(content) | ||
assert extracted_json is None # Only JSON objects are extracted | ||
|
||
|
||
def test_extract_valid_json_with_empty_json(): | ||
content = "Some text {} more text." | ||
expected_json = {} | ||
extracted_json = extract_valid_json(content) | ||
assert extracted_json == expected_json | ||
|
||
|
||
def test_extract_valid_json_with_multiline_json(): | ||
content = """ | ||
Here is some text { | ||
"key": "value", | ||
"another_key": "another_value" | ||
} and more text. | ||
""" | ||
expected_json = {"key": "value", "another_key": "another_value"} | ||
extracted_json = extract_valid_json(content) | ||
assert extracted_json == expected_json | ||
|
||
|
||
def test_extract_valid_json_with_json_in_quotes(): | ||
content = 'Text before "{\\"key\\": \\"value\\"}" text after.' | ||
extracted_json = extract_valid_json(content) | ||
assert extracted_json is None # JSON inside quotes should not be parsed |