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

Timeout Error OpenAI #3512

Closed
shreyabhadwal opened this issue Apr 25, 2023 · 30 comments
Closed

Timeout Error OpenAI #3512

shreyabhadwal opened this issue Apr 25, 2023 · 30 comments

Comments

@shreyabhadwal
Copy link

I am facing a Warning similar to the one described here #3005

WARNING:langchain.embeddings.openai:Retrying langchain.embeddings.openai.embed_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised Timeout: Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=600).
It just keeps retrying. How do I get around this?

@dnrico1
Copy link

dnrico1 commented Apr 26, 2023

Same for me as well

@La1c
Copy link

La1c commented Apr 27, 2023

Getting the same error, with map-reduce summarizing chain.
Vanilla open ai api works as expected.

@gabacode
Copy link

Same, following 👀

@shreyabhadwal
Copy link
Author

shreyabhadwal commented Apr 28, 2023

@dnrico1 @La1c @gabacode
When are y'all getting the error?
For instance, I am getting it through my websocket app deployed on Azure (it's a chatbot application). Weirdly enough, I don't face it when I run the application locally.

@bkamapantula
Copy link
Contributor

bkamapantula commented Apr 28, 2023

+1

OpenAI chat endpoint always seems to time out when using the summarization chain.

It works with the anthropic endpoint though.

hwchase17 pushed a commit that referenced this issue May 1, 2023
With longer context and completions, gpt-3.5-turbo and, especially,
gpt-4, will more times than not take > 60seconds to respond.

Based on some other discussions, it seems like this is an increasingly
common problem, especially with summarization tasks.
- #3512
- #3005

OpenAI's max 600s timeout seems excessive, so I settled on 120, but I do
run into generations that take >240 seconds when using large prompts and
completions with GPT-4, so maybe 240 would be a better compromise?
@Binb1
Copy link

Binb1 commented May 2, 2023

+1

@shreyabhadwal Experiencing the exact same behaviour. Local works well but it timeouts on Azure.

@shreyabhadwal
Copy link
Author

@Binb1 do the timeouts happen every time for you or occasionally? Also, are you using websockets or SSE?

@Binb1
Copy link

Binb1 commented May 3, 2023

@shreyabhadwal Strangely enough, every time I deploy a new version of my app it seems to work well. But after a few minutes I get timeouts and I can't really understand why so far. I'm using SSE.
I've tested a lot of different options and I have the same problem doing an Openai python SDK call or Langchain.

@shreyabhadwal
Copy link
Author

@Binb1 I experience the exact same behavior. It works well if I restart the app, and then after a few minutes when I try again I get timeouts. Very weird.

Interestingly, I have tried doing it without streaming and it seems to be working well. I don't quite understand it.

@Binb1
Copy link

Binb1 commented May 3, 2023

@shreyabhadwal This makes me think that it is more Azure than langchain/openai related then 😕

I have not tried streaming yet as I don't really need it but it fails for me even without it. So strange.

It feels like the webapp needs a "warmup" before being able to make the calls.

@gabacode
Copy link

gabacode commented May 3, 2023

Increasing the timeout fixes it for me! Thanks @timothyasp !

@firezym
Copy link

firezym commented May 5, 2023

+1
I set the timeout to 300s, but each time after 3 to 5 requests, It still fails as timeout...

@timothyasp
Copy link
Contributor

timothyasp commented May 5, 2023 via email

@ColinTitahi
Copy link

@shreyabhadwal @Binb1 any luck with Azure?

Same issue local fine and fast, on Azure issues.
Something seems to fall asleep after 4-10 minutes
For me "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry" seems to get called before the call for chat etc.
After it times out it returns and is good until idle for 4-10 minutes
So Increasing the timeout just increases the wait until it does timeout and calls again.

Driving me nuts and suspect there is a simple configuration I'm missing.

@shreyabhadwal
Copy link
Author

Nope nothing yet
@Binb1 @ColinTitahi are y'all using async calls to OpenAI?

@ColinTitahi
Copy link

ColinTitahi commented May 10, 2023

@shreyabhadwal Not explicitly so I don't think so. I'm using generate on the ChatOpenAI so I can get the llm_output token etc and another run call to a chat-conversational-react-description agent with some additional tools.
These endpoints in my flask app are being called from the client JavaScript which uses async to wait for the response.
It's like something gets set up when the flask app initially starts up and then falls asleep or disconnects or something after say 4-5 minutes and then has to wait for the timeout to occur to reconnect when the user calls it. Hence upping the timeout just increases that initial wait.

I'm using the OpenAI Chat model and hosting on an Azure web service.

@sagardspeed2
Copy link

I am getting same error with model gpt-4-0314 and max_token = 2048 with request_timeout = 240 in local and live server.
yesterday this was working fine

@DennisSchwartz
Copy link

DennisSchwartz commented May 22, 2023

Same issue here. Running it in a Kubernetes Pod deployed to an AWS cluster and using async calls.
Works perfectly locally but times out as soon as it's in the cluster.

Weirdly, calling the OpenAI LLM directly works, but running the Agent it gets stuck.

This works:

agent_executor = get_agent(user_token)
driver = agent_executor.agent.llm_chain.llm
cl = driver.client()
print(cl.create(model=driver.model_name, prompt='Tell me a poem'))

But this does not:

await agent_executor.arun(query)

@DennisSchwartz
Copy link

DennisSchwartz commented May 22, 2023

Ok so from the comments above I realised I was testing async in one case and blocking in the other.

print(await cl.acreate(model=driver.model_name, prompt='Tell me a poem'))

Does indeed also time out and fail to run!
So there definitely seems to be an issue with the Async running of OpenAI. I'm going to try Anthropic for now. :)


UPDATE

I still can't make it run, neither for OpenAI nor Anthropic - but I think I know what's going on.

Our Kubernetes cluster running the application is blocking access to the internet using Squid Proxy. The OpenAI API is allowed, but only for HTTP requests.
I think the OpenAI client is probably using web sockets to stream the responses and this is blocked by our proxy/firewall.
Have resorted to using the sync application for now until we can figure out how to fix our proxy.

@jpsmartbots
Copy link

jpsmartbots commented Jun 4, 2023

I have the same issue. I am trying to hit completion api on text-davinci-003 engine. I am unable to replicate the issue on my local as it works always. When I containerize and deploy it in AWS Lambda, I get the following error sometimes (dont know when).
Request timed out: HTTPSConnectionPool(host='instanceid.openai.azure.com', port=443): Max retries exceeded with url: //openai/deployments/textdavinci003/completions?api-version=2022-12-01 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at XXXX>, 'Connection to instanceid.openai.azure.com timed out. (connect timeout=5)')

Any resoultion?

@maxmarkov
Copy link

It could be a problem with the SSL key. Set it up as a system environment variable.
os.environ["REQUESTS_CA_BUNDLE"] = "PATH_TO_YOUR_CERTIFICATE/YOUR_CERTIFICATE.crt"

@bigrig2212
Copy link

bigrig2212 commented Jun 14, 2023

Same issue here. Works for a bit and then starts timing out.
I just can't nail down when it happens and why. There doesn't seem to be a rhyme or reason. Seems to happen a lot more on production (gcp) than locally. Although it happens on both. Seems to happen with short sentences more than long ones. Although not exclusively. It happens a LOT though. Like 1 out of 4 requests.

@flake9
Copy link

flake9 commented Aug 8, 2023

+1

@HaochenQ
Copy link

I have the same issue. Works well locally but faces timeout issues when the app is deployed to Azure App Service for Linux Python or Custom Container.

@jpsmartbots
Copy link

Hi HaochenQ

May be deploying your solution in a virtual machine might solve your problem. When I moved from AWS Lambda to EC2, the problem got resolved

@HaochenQ
Copy link

HaochenQ commented Aug 31, 2023

Hi HaochenQ

May be deploying your solution in a virtual machine might solve your problem. When I moved from AWS Lambda to EC2, the problem got resolved

Thank you@jpsmartbots, I tried to deploy my container with an Azure VM, but the issue persists.

For those of you who are facing 504 gateway timeout issues Retrying langchain.embeddings.openai.embed_with_retry.<locals>._embed_with_retry in 4.0 seconds as it raised Timeout: Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=600). with Azure App Services, the issue is because the default HTTP timeout of Azure App Service 230/240 seconds while the default timeout of OpenAI APIs is 600 seconds. Before langchian hear back from OpenAI and do a retry, Azure returns an error and our app appears down. You can use request_timeout - OpenAIEmbeddings(request_timeout=30) to avoid time timeout from Azure side and somehow the retry call to OpenAI from langchain can always work.

Not sure why the langchian call to the OpenAI after a period of inactivity will fail and cause a timeout.

@ShantanuNair
Copy link
Contributor

Hey all, I believe this being fixed in the openai-python client should also help with this issue, and with generations:

openai/openai-python#387

The async and sync request_timeouts are NOT identical.

@luoqingming110
Copy link

same problem

@ryoung562
Copy link

I'm running into the same issue. i am running a proxy container that talks to openai API works locally, but not when i deploy it to railway.

@mallapraveen
Copy link

did anyone fix this, running into the same issue when I use summarize map reduce chain from Langhian on AWS lambda?

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label May 3, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale May 10, 2024
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label May 10, 2024
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

No branches or pull requests