parea-ai/parea-sdk-py

Parea wrapper not re-raising root exception

seanr-cardless opened this issue ยท 2 comments

๐Ÿ› Bug Report

The Parea wrapper code returns in the finally block which swallows the exception caught when actually calling the OpenAI models. This makes things very difficult to log/monitor/debug as the root exception is swallowed by Parea and failures occur downstream.

Link to offending code.

return self._cleanup_trace(trace_id, start_time, error, cache_hit, args, kwargs, response)

๐Ÿ”ฌ How To Reproduce

Steps to reproduce the behavior:

  1. I'm not sure how to repro an OpenAI failure but it can be monkey patched if needed. Looking at the offending code probably provides all the context necessary

Code sample

Try running this function. 1 is returned and the exception isn't raised

def run():
    try:
        raise Exception("bad")
    except Exception as e:
        print(e)
        raise e
    finally:
        return 1

Environment

  • OS: MacOS apple silicon
  • Python version: 3.9
python --version

๐Ÿ“ˆ Expected behavior

The error isn't swallowed by Parea and is surfaced to the consumer of the Open API call.

๐Ÿ“Ž Additional context

I ran into this using Langchain with the following (abbreviated) code

    llm = ChatOpenAI(
        openai_api_key=openai_api_key,
        temperature=0,
        model_name=model,
        model_kwargs=llm_kwargs,
        max_retries=3
    )
    response = llm([HumanMessage(content="model query here...any will work")

This became relevant on the OpenAI outage on 2023-10-19

Hey, thanks for raising! I will update you once it's resolved.

@seanr-cardless it's fixed now with #168!
You can simply run pip install -U parea-ai