Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the timeout logic handling correct? #454

Closed
tim-tribble-ai opened this issue Oct 27, 2023 · 8 comments
Closed

Is the timeout logic handling correct? #454

tim-tribble-ai opened this issue Oct 27, 2023 · 8 comments
Labels
question Further information is requested

Comments

@tim-tribble-ai
Copy link

I've got the following config setup:

        "request_timeout": 30,
        "max_retry_period": 200,
        "retry_wait_time": 30

However, I'm noticing that when there's a read timeout, there's no retry happening:

Exception: Timeout: Request timed out: HTTPSConnectionPool(host='blah123.openai.azure.com', port=443): Read timed out. (read timeout=30)

I'm unsure if the timeout handling in oai/completion.py is correct:

except (RateLimitError, Timeout) as err:
                time_left = max_retry_period - (time.time() - start_time + retry_wait_time)
                if (
                    time_left > 0
                    and isinstance(err, RateLimitError)
                    or time_left > request_timeout
                    and isinstance(err, Timeout)
                    and "request_timeout" not in config
                ):
                    if isinstance(err, Timeout):
                        request_timeout <<= 1
                    request_timeout = min(request_timeout, time_left)
                    logger.info(f"retrying in {retry_wait_time} seconds...", exc_info=1)
                    sleep(retry_wait_time)
                elif raise_on_ratelimit_or_timeout:
                    raise

In this case, it's not a rate limit exception, but just a Timeout exception. Why is there a check for ...and "request_timeout" not in config ? This seems to be skipping the retry for non-RateLimit timeouts.

Can that check be removed, and within the except logic,

request_timeout = request_timeout <<= 1 if "request_timeout" not in config else request_timeout

?

@tim-tribble-ai
Copy link
Author

Follow-on from the above: in the else branch of the above, I think the response = -1 is also incorrect:

                else:
                    response = -1
                    if use_cache and isinstance(err, Timeout):
                        cls._cache.set(key, response)
                    logger.warning(
                        f"Failed to get response from openai api due to getting RateLimitError or Timeout for {max_retry_period} seconds."
                    )
                    return response

This is causing issues if that else branch is returned to caller:

Getting Exception: TypeError: 'int' object is not subscriptable exceptions:

...
File "/Users/my_stuff/.venv/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 609, in generate_oai_reply
  return True, oai.ChatCompletion.extract_text_or_function_call(response)[0]
File "/Users/my_stuff/.venv/lib/python3.10/site-packages/autogen/oai/completion.py", line 1070, in extract_text_or_function_call
  choices = response["choices"]

So the caller should probably check if response is not a dict then act accordingly?

@gagb
Copy link
Collaborator

gagb commented Oct 27, 2023

@afourney is this related to an observation in your test suite?

@gagb gagb added question Further information is requested bug labels Oct 27, 2023
@afourney
Copy link
Member

afourney commented Oct 27, 2023

Yes I was getting many timeouts, but I hadn’t tracked down the source of the errors. To mitigate the problem, I extended the timeout.

Let me investigate.

This logic will also be replaced after #203 is merged since it uses OpenAI v1.0.

@Quintas168
Copy link

I have run into the same question but still don't know why

@tim-watcha
Copy link

openai.error.Timeout: Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=60)
I got same error

@mwahl217
Copy link

I too am seeing this error, openai.error.Timeout: Request timed out: HTTPSConnectionPool(host='api.openai.com', port=5001): Read timed out. (read timeout=60). However, I am using autogen with LM Studio

I did try and increase timeouts to see if that will help, but not sure I am addressing the root cause.

llm_config = {
"request_timeout": 800,
"max_retry_period": 50,
"retry_wait_time": 10,
#"seed": 0,
"seed":44,
"config_list": config_list,
"temperature": 0.2,
}

@sonichi
Copy link
Contributor

sonichi commented Dec 3, 2023

In v0.2 these settings changed: https://microsoft.github.io/autogen/docs/Installation#python

@thinkall
Copy link
Collaborator

We are closing this issue due to inactivity; please reopen if the problem persists.

jackgerrits pushed a commit that referenced this issue Oct 2, 2024
…r samples #454 (#469)

* create model context component, remove chat memory component, refactor samples #454

* Fix bugs in samples.

* Fix

* Update docs

* add unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

8 participants