promptflow icon indicating copy to clipboard operation
promptflow copied to clipboard

[Feature Request] Configurable Retry Logic

Open georgeadam opened this issue 2 years ago • 2 comments

Dear Promptflow creators,

You've built an amazing framework!

Issue The retry logic implemented in the handle_openai_error decorator is hardcoded to be 10 tries with a delay of 8 seconds (see here). In cases of many requests, this is excessive, and 8^10 is too long to wait for. In particular, I am using Azure OpenAI, and I noticed this decorator is applied to the completion() and chat() methods of the AzureOpenAI tool.

Solution It would be great to be able to specify the number of tries/delay to the handle_openai_error decorator somehow when running a flow in code. E.g. something like

f = load_flow(source=flow_path)
flow_inputs = {"text": "here is some text"}
retry_options = {"tries": 2, "delay": 10}
response = f(**flow_inputs, retry_options=retry_options)

This could be an auxiliary attribute for each node instead since one can imagine that some nodes are expected to take a long time to run, while others should complete shortly.

Describe alternatives you've considered My current solution is to monkey-patch the AzureOpenAI class and change the decorator arguments like so before

@tool
@handle_openai_error()
@enable_cache(calculate_cache_string_for_completion)
def completion(

monkey-patched

@tool
@handle_openai_error(tries=1, delay=2)
@enable_cache(calculate_cache_string_for_completion)
def completion(

This is not good practice, and future changes to the API could easily break this code. Thanks for your consideration!

georgeadam avatar Dec 06 '23 04:12 georgeadam

This is the internal tool logic, currently, we do not have a plan to expose it in the tool interface. You can use the workaround here. Meanwhile, we have updated the support to openai 1.X and we would check the error handling logic in openai and refine our retry logic.

DaweiCai avatar Dec 14 '23 03:12 DaweiCai

Will keep the current implementation and do not have a plan to expose the retry logic in the tool interface.

DaweiCai avatar Jan 02 '24 03:01 DaweiCai