tlofreso / bulletin

0 stars 1 forks source link

OpenAI Returns Empty JSON #13

Open mfgarvin opened 8 months ago

mfgarvin commented 8 months ago

OpenAI assistant will occasionally return empty JSON. Just need to catch this error, I think.

Traceback (most recent call last):
  File "/home/runner/work/bulletin/bulletin/main.py", line 111, in <module>
    main()
  File "/home/runner/work/bulletin/bulletin/main.py", line 108, in main
    run_parish(parish_id, config, args.dry_run, args.verbose)
  File "/home/runner/work/bulletin/bulletin/main.py", line 61, in run_parish
    mass_times = get_mass_times(openai_client, config.bulletin_assistant_id, temp_file)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/bulletin/bulletin/info_extract.py", line 69, in get_mass_times
    response_json = json.loads(json_str)
                    ^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.2/x64/lib/python3.12/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.2/x64/lib/python3.12/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.2/x64/lib/python3.12/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 1 (char 0)
mfgarvin commented 8 months ago

Aha! On difficult bulletins, OpenAI returns this (or at least it did this time)

I am unable to locate the specific times for Mass at this parish. The document provided seems to be difficult to process, and my attempts have not yielded the necessary information regarding Mass times. If you can provide additional details or context that might help locate this information within the document, that would be greatly appreciated. Hence, no JSON.