From e9947be7b2650d2e94bafde1b0487998dbe74d29 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Mon, 27 Nov 2023 07:49:18 -0800 Subject: [PATCH] (fix) add timeout to __init__ litellm --- litellm/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/litellm/__init__.py b/litellm/__init__.py index 99d7455c53..aeaa97fc3a 100644 --- a/litellm/__init__.py +++ b/litellm/__init__.py @@ -62,11 +62,11 @@ allowed_fails: int = 0 def get_model_cost_map(url: str): try: - response = requests.get(url) - response.raise_for_status() # Raise an exception if request is unsuccessful - content = response.json() - return content - except: + with requests.get(url, timeout=5) as response: # set a 5 second timeout for the get request + response.raise_for_status() # Raise an exception if the request is unsuccessful + content = response.json() + return content + except Exception as e: import importlib.resources import json with importlib.resources.open_text("litellm", "model_prices_and_context_window_backup.json") as f: