mirror of
https://github.com/hwchase17/langchain
synced 2024-11-18 09:25:54 +00:00
Harrison/json new line (#4646)
Co-authored-by: David Chen <davidchen@gliacloud.com>
This commit is contained in:
parent
87d8d221fb
commit
f5e2f70115
@ -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:
|
||||
|
@ -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",
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user