JSONDecodeError

Prompt Engineering with Llama 2&3

I got the following error whenever I ran any code. For Example: In Lesson2 :

---------------
from utils import llama

prompt = “Help me write a birthday card for my dear friend Andrew.”

response = llama(prompt)
print(response)


JSONDecodeError Traceback (most recent call last)
File /usr/local/lib/python3.10/site-packages/requests/models.py:971, in Response.json(self, **kwargs)
970 try:
→ 971 return complexjson.loads(self.text, **kwargs)
972 except JSONDecodeError as e:
973 # Catch JSON-related errors and raise as requests.JSONDecodeError
974 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File /usr/local/lib/python3.10/json/_init_.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
343 if (cls is None and object_hook is None and
344 parse_int is None and parse_float is None and
345 parse_constant is None and object_pairs_hook is None and not kw):
→ 346 return _default_decoder.decode(s)
347 if cls is None:

File /usr/local/lib/python3.10/json/decoder.py:337, in JSONDecoder.decode(self, s, _w)
333 “”“Return the Python representation of ``s`` (a ``str`` instance
334 containing a JSON document).
335
336 “””
→ 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()

File /usr/local/lib/python3.10/json/decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
354 except StopIteration as err:
→ 355 raise JSONDecodeError(“Expecting value”, s, err.value) from None
356 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

JSONDecodeError Traceback (most recent call last)
Cell In[16], line 2
1 # pass prompt to the llama function, store output as ‘response’ then print
----> 2 response = llama(prompt)
3 print(response)

File ~/work/L2/utils.py:56, in llama(prompt, add_inst, model, temperature, max_tokens, verbose, url, headers, base, max_tries)
54 except Exception as e:
55 if response.status_code != 500:
—> 56 return response.json()
58 print(f"error message: {e}“)
59 print(f"response object: {response}”)

File /usr/local/lib/python3.10/site-packages/requests/models.py:975, in Response.json(self, **kwargs)
971 return complexjson.loads(self.text, **kwargs)
972 except JSONDecodeError as e:
973 # Catch JSON-related errors and raise as requests.JSONDecodeError
974 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
→ 975 raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

JSONDecodeError: Expecting value: line 1 column 1 (char 0)
---------------------------------------------------------------------------

I did the following actions, but they did not help.

  • Reload the page
  • log in and log out
  • use different browser
  • clear my web browser’s cache and cookies
  • “Restore Original Version” from three-dot menu (⋮)

Any input will be appreciated.

1 Like

Hi @hal9 !
looking at this notebook (released in Feb 2024) I can see there might be issues related to the key or a deprecated endpoint. I will check it with the team and will update these notebooks.

Thank you for reporting!