Harrison/json new line (#4646)

Co-authored-by: David Chen <davidchen@gliacloud.com>
This commit is contained in:
Harrison Chase 2023-05-13 21:46:33 -07:00 committed by GitHub
parent 87d8d221fb
commit f5e2f70115
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -22,7 +22,7 @@ class PydanticOutputParser(BaseOutputParser[T]):
json_str = ""
if match:
json_str = match.group()
json_object = json.loads(json_str)
json_object = json.loads(json_str, strict=False)
return self.pydantic_object.parse_obj(json_object)
except (json.JSONDecodeError, ValidationError) as e:

View File

@ -21,6 +21,7 @@ class TestModel(BaseModel):
additional_fields: Optional[str] = Field(
description="Additional fields", default=None
)
for_new_lines: str = Field(description="To be used to test newlines")
# Prevent pytest from trying to run tests on TestModel
@ -30,7 +31,8 @@ TestModel.__test__ = False # type: ignore[attr-defined]
DEF_RESULT = """{
"action": "Update",
"action_input": "The PydanticOutputParser class is powerful",
"additional_fields": null
"additional_fields": null,
"for_new_lines": "not_escape_newline:\n escape_newline: \\n"
}"""
# action 'update' with a lowercase 'u' to test schema validation failure.
@ -44,6 +46,7 @@ DEF_EXPECTED_RESULT = TestModel(
action=Actions.UPDATE,
action_input="The PydanticOutputParser class is powerful",
additional_fields=None,
for_new_lines="not_escape_newline:\n escape_newline: \n",
)