mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-26 16:43:35 +00:00
fix json tool (#9096)
This commit is contained in:
parent
2184e3a400
commit
3ab4e21579
@ -20,7 +20,7 @@ def _parse_input(text: str) -> List[Union[str, int]]:
|
||||
"""Parse input of the form data["key1"][0]["key2"] into a list of keys."""
|
||||
_res = re.findall(r"\[.*?]", text)
|
||||
# strip the brackets and quotes, convert to int if possible
|
||||
res = [i[1:-1].replace('"', "") for i in _res]
|
||||
res = [i[1:-1].replace('"', "").replace("'", "") for i in _res]
|
||||
res = [int(i) if i.isdigit() else i for i in res]
|
||||
return res
|
||||
|
||||
|
@ -30,6 +30,10 @@ def test_json_spec_value() -> None:
|
||||
assert spec.value('data["baz"]') == "{'test': {'foo': [1, 2, 3]}}"
|
||||
assert spec.value('data["baz"]["test"]') == "{'foo': [1, 2, 3]}"
|
||||
assert spec.value('data["baz"]["test"]["foo"]') == "[1, 2, 3]"
|
||||
assert spec.value("data['foo']") == "bar"
|
||||
assert spec.value("data['baz']") == "{'test': {'foo': [1, 2, 3]}}"
|
||||
assert spec.value("data['baz']['test']") == "{'foo': [1, 2, 3]}"
|
||||
assert spec.value("data['baz']['test']['foo']") == "[1, 2, 3]"
|
||||
|
||||
|
||||
def test_json_spec_value_max_length() -> None:
|
||||
|
Loading…
Reference in New Issue
Block a user