@@ -50,7 +50,7 @@ def chunk_text(
5050 yield from (token_encoder .decode (list (chunk )) for chunk in chunk_iterator )
5151
5252
53- def try_parse_json_object (input : str ) -> tuple [str , dict ]:
53+ def try_parse_json_object (input : str , verbose : bool = True ) -> tuple [str , dict ]:
5454 """JSON cleaning and formatting utilities."""
5555 # Sometimes, the LLM returns a json string with some extra description, this function will clean it up.
5656
@@ -59,7 +59,8 @@ def try_parse_json_object(input: str) -> tuple[str, dict]:
5959 # Try parse first
6060 result = json .loads (input )
6161 except json .JSONDecodeError :
62- log .info ("Warning: Error decoding faulty json, attempting repair" )
62+ if verbose :
63+ log .info ("Warning: Error decoding faulty json, attempting repair" )
6364
6465 if result :
6566 return input , result
@@ -97,11 +98,13 @@ def try_parse_json_object(input: str) -> tuple[str, dict]:
9798 try :
9899 result = json .loads (input )
99100 except json .JSONDecodeError :
100- log .exception ("error loading json, json=%s" , input )
101+ if verbose :
102+ log .exception ("error loading json, json=%s" , input )
101103 return input , {}
102104 else :
103105 if not isinstance (result , dict ):
104- log .exception ("not expected dict type. type=%s:" , type (result ))
106+ if verbose :
107+ log .exception ("not expected dict type. type=%s:" , type (result ))
105108 return input , {}
106109 return input , result
107110 else :
0 commit comments