core[patch]: Fix jsonOutputParser fails if a json value contains ``` inside it. (#19717)

- **Issue:** fix #19646 
- @baskaryan, @eyurtsev PTAL
This commit is contained in:
Guangdong Liu
2024-03-29 03:01:09 +08:00
committed by GitHub
parent f7042321f1
commit 0571f886d1
2 changed files with 26 additions and 11 deletions

View File

@@ -69,6 +69,10 @@ JSON_WITH_MARKDOWN_CODE_BLOCK = """```json
}
```"""
JSON_WITH_PART_MARKDOWN_CODE_BLOCK = """
{\"valid_json\": "hey ```print(hello world!)``` hey"}
"""
JSON_WITH_MARKDOWN_CODE_BLOCK_AND_NEWLINES = """```json
{
"action": "Final Answer",
@@ -191,6 +195,11 @@ def test_parse_json_with_code_blocks() -> None:
assert parsed == {"foo": "```bar```"}
def test_parse_json_with_part_code_blocks() -> None:
parsed = parse_json_markdown(JSON_WITH_PART_MARKDOWN_CODE_BLOCK)
assert parsed == {"valid_json": "hey ```print(hello world!)``` hey"}
def test_parse_json_with_code_blocks_and_newlines() -> None:
parsed = parse_json_markdown(JSON_WITH_MARKDOWN_CODE_BLOCK_AND_NEWLINES)