MagnivOrg / prompt-layer-library

🍰 PromptLayer - Maintain a log of your prompts and OpenAI API requests. Track, debug, and replay old completions.
https://www.promptlayer.com
Apache License 2.0
479 stars 42 forks source link

Report error message correctly when request fails #46

Closed lfoppiano closed 1 year ago

lfoppiano commented 1 year ago

I've implemented a small fix to at least get the response status code, when a failure occurs.

WARNING: While logging your request PromptLayer had the following error: <Response [403]>
Traceback (most recent call last):
  File "/Users/lfoppiano/anaconda3/envs/magneto/lib/python3.9/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "/Users/lfoppiano/anaconda3/envs/magneto/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/Users/lfoppiano/anaconda3/envs/magneto/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Users/lfoppiano/anaconda3/envs/magneto/lib/python3.9/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)

I've also wrapped the code in the same method to reduce a bit the complexity.

I think this could be improved:

  1. by printing directly the response body, but I leave this up to you.
  2. by avoiding throwing the error after, but the request has to fail at some point:
         if return_pl_id:
               return request_response.json().get("request_id")
Jped commented 1 year ago

@lfoppiano thanks for this, this is something we wanted to fix. I left one comment, but otherwise it looks good to me.

Jped commented 1 year ago

@lfoppiano looks great, let me test it a bit and then will merge it in!

Jped commented 1 year ago

@lfoppiano what is your request that is giving you that response?

lfoppiano commented 1 year ago

@lfoppiano what is your request that is giving you that response?

It's a POST to https://api.promptlayer.com/track-request, I'm not sure why it fails, might be a problem in my network.

Jped commented 1 year ago

@lfoppiano would you mind joining our discord and I can help you debug there?

lfoppiano commented 1 year ago

@Jped no need, it was on my side and I fixed it 😄 Thanks anyway!