Skip to content

feat: Handle errors, retries, and improve response types#302

Merged
cguedes merged 8 commits into
mainfrom
85-add-error-and-rate-limit-handling-for-calls-to-openai-api
Jul 14, 2023
Merged

feat: Handle errors, retries, and improve response types#302
cguedes merged 8 commits into
mainfrom
85-add-error-and-rate-limit-handling-for-calls-to-openai-api

Conversation

@gjreda

@gjreda gjreda commented Jul 13, 2023

Copy link
Copy Markdown
Collaborator

@cguedes @sehyod I pushed this with no-verify since I figured we might have some discussion on the typing changes. Leaving as draft for now, but please feel free to add your feedback.


fixes #85 and allows errors to be return within the sidecar response types

For now, I'm passing through the exception in the message, but I figured this PR would lead to some follow-up discussion on what we'd want to see on errors.


Ok

{
  "status": "ok",
  "message": "",
  "choices": [
    {
      "index": 0,
      "text": "ML engineering is an experimental and iterative discipline, unlike traditional software engineering. Despite the negative perception of many failed experiments and models not being deployed, it is acceptable for them to not reach production."
    }
  ]
}

Error

{
  "status": "error",
  "message": "RetryError[<Future at 0x118d40700 state=finished raised AuthenticationError>]",
  "choices": []
}

Comment thread .env.example
Comment thread python/sidecar/chat.py
docs = self.ranker.get_top_n(query=self.input_text, limit=5)
return docs

@retry(stop=stop_after_attempt(3), wait=wait_fixed(1))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't quite sure how we'd want to handle retries, but this felt like a fine starting point. In reality, I imagine if we need to spend more than a few second retrying (e.g. the user is rate limited or the service is down), we probably do not want to be retrying at all. Our user is still trying to write a document within Refstudio, even if the AI functionality is not working.

@codecov

codecov Bot commented Jul 13, 2023

Copy link
Copy Markdown

Codecov Report

Merging #302 (e05fc34) into main (f898380) will increase coverage by 0.07%.
The diff coverage is 100.00%.

❗ Current head e05fc34 differs from pull request most recent head 6f13602. Consider uploading reports for the commit 6f13602 to get more accurate results

@@            Coverage Diff             @@
##             main     #302      +/-   ##
==========================================
+ Coverage   85.52%   85.59%   +0.07%     
==========================================
  Files         132      132              
  Lines        7310     7346      +36     
  Branches      775      775              
==========================================
+ Hits         6252     6288      +36     
  Misses       1045     1045              
  Partials       13       13              
Impacted Files Coverage Δ
python/sidecar/chat.py 93.54% <100.00%> (+1.09%) ⬆️
python/sidecar/rewrite.py 94.02% <100.00%> (+1.72%) ⬆️
python/sidecar/typing.py 96.85% <100.00%> (+0.32%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@gjreda gjreda requested review from cguedes and sehyod July 13, 2023 22:34
@gjreda gjreda marked this pull request as ready for review July 14, 2023 16:40
@cguedes cguedes merged commit 015d2b5 into main Jul 14, 2023
@cguedes cguedes deleted the 85-add-error-and-rate-limit-handling-for-calls-to-openai-api branch July 14, 2023 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add error and rate limit handling for calls to OpenAI API

2 participants