cyberchitta / openai_ex

Community maintained Elixir library for OpenAI API
https://hexdocs.pm/openai_ex
Apache License 2.0
140 stars 19 forks source link

Enable retry on error? #78

Closed SinKasula closed 11 months ago

SinKasula commented 11 months ago

Describe the feature or improvement you're requesting

Could you please update the application.ex to include an option to retry when open ai endpoint responds with an error code.

A simple fix can be on this line https://github.com/restlessronin/openai_ex/blob/56be67e48a436e2950003e49eca439e1864f3d36/lib/openai_ex/application.ex#L13

opts = [ strategy: :one_for_one, restart: :transient, max_retry: 3 ]

Supervisor.start_link(children, opts)

Additional context

No response

restlessronin commented 11 months ago

I'm not sure I understand how restarting the application will help when the endpoint returns an error code. Is the application crashing in this situation?

SinKasula commented 11 months ago

In case where openai endpoint returns unexpected errors, supervisor could restart the request

restlessronin commented 11 months ago

I'm afraid that's not how supervisors work. They're meant to restart the application when it crashes. That isn't happening here.

AFAIK, the only time it might make sense to automatically retry a request is if you've hit a rate limit and need to wait. In other situations, you need to check why there was an error and modify your request. What kind of error are you seeing, that you want an automatic retry?

As of now, you need to write the code to check for this, and retry if necessary.

restlessronin commented 11 months ago

@SinKasula I noticed you upvoted https://github.com/restlessronin/openai_ex/issues/70, which is related to this. Please respond in detail about your retry use case on that issue. I will close this issue for now.

SinKasula commented 11 months ago

You are right, It only helps in cases of limited error cases. Nvm, I'll setup retry logic for cases necessary