iw4p / partialjson

Parsing ChatGPT JSON stream response — Partial and incomplete JSON parser python library for OpenAI | repair invalid JSON, parse output of LLMs
MIT License
64 stars 6 forks source link

Parsing failure with boolean value #7

Closed black7375 closed 7 months ago

black7375 commented 7 months ago

Expect True if the value starts with t, False if it starts with f.

print(parser.parse('{"chat": "hello", "is_result": t'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/json-test//.venv/lib/python3.11/site-packages/partialjson/json_parser.py", line 32, in parse
    data, reminding = self.parse_any(s, e)
                      ^^^^^^^^^^^^^^^^^^^^
  File "/home/json-test//.venv/lib/python3.11/site-packages/partialjson/json_parser.py", line 46, in parse_any
    return parser(s, e)
           ^^^^^^^^^^^^
  File "/home/json-test//.venv/lib/python3.11/site-packages/partialjson/json_parser.py", line 97, in parse_object
    value, s = self.parse_any(s, e)
               ^^^^^^^^^^^^^^^^^^^^
  File "/home/json-test//.venv/lib/python3.11/site-packages/partialjson/json_parser.py", line 46, in parse_any
    return parser(s, e)
           ^^^^^^^^^^^^
  File "/home/json-test//.venv/lib/python3.11/site-packages/partialjson/json_parser.py", line 133, in parse_true
    raise e
  File "/home/json-test//.venv/lib/python3.11/site-packages/partialjson/json_parser.py", line 30, in parse
    return json.loads(s)
           ^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 32 (char 31)
iw4p commented 7 months ago

Hi, May I have your full string and what you expected?

iw4p commented 7 months ago

Fixed. Please use the latest version (0.0.6).

black7375 commented 7 months ago

I read your reply a little late. I installed the new version to check it out and it works very well.

Thanks for the quick patch!!