From f5af0dda42f00b8078266e230c76a04fec3b6828 Mon Sep 17 00:00:00 2001 From: Samiur Rahman Date: Mon, 31 Jul 2023 08:40:36 -0700 Subject: [PATCH] Allow less strict JSON parsing (#75) When getting longform answers from OpenAI that contains newlines or tabs, the string returned doesn't have escaped control characters. `strict=False` allows parsing of these strings with control characters, with character codes in the 0-31 range, including '\t' (tab), '\n', '\r' and '\0'." --- openai_function_call/function_calls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openai_function_call/function_calls.py b/openai_function_call/function_calls.py index 42208bc..ddd4a91 100644 --- a/openai_function_call/function_calls.py +++ b/openai_function_call/function_calls.py @@ -109,7 +109,7 @@ class openai_function: ), "Function name does not match" function_call = message["function_call"] - arguments = json.loads(function_call["arguments"]) + arguments = json.loads(function_call["arguments"], strict=False) return self.validate_func(**arguments) @@ -163,7 +163,7 @@ class OpenAISchema(BaseModel): ), "Function name does not match" function_call = message["function_call"] - arguments = json.loads(function_call["arguments"]) + arguments = json.loads(function_call["arguments"], strict=False) return cls(**arguments)