mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-13 21:47:12 +00:00
core[patch]: Fix jsonOutputParser fails if a json value contains ``` inside it. (#19717)
- **Issue:** fix #19646 - @baskaryan, @eyurtsev PTAL
This commit is contained in:
@@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user