fix get all keys problem

This commit is contained in:
ishaan-jaff 2023-08-24 18:54:24 -07:00
parent c23bf54e27
commit 0d24bf9221
2 changed files with 8 additions and 8 deletions

View file

@ -44,6 +44,7 @@ user_logger_fn = None
additional_details: Optional[Dict[str, str]] = {}
local_cache: Optional[Dict[str, str]] = {}
last_fetched_at = None
last_fetched_at_keys = None
######## Model Response #########################
# All liteLLM Model responses will be in this format, Follows the OpenAI Format
# https://docs.litellm.ai/docs/completion/output
@ -1131,19 +1132,19 @@ def modify_integration(integration_name, integration_params):
def get_all_keys(llm_provider=None):
try:
global last_fetched_at
global last_fetched_at_keys
# if user is using hosted product -> instantiate their env with their hosted api keys - refresh every 5 minutes
print_verbose(f"Reaches get all keys, llm_provider: {llm_provider}")
user_email = os.getenv("LITELLM_EMAIL") or litellm.email or litellm.token or os.getenv("LITELLM_TOKEN")
if user_email:
time_delta = 0
if last_fetched_at != None:
if last_fetched_at_keys != None:
current_time = time.time()
time_delta = current_time - last_fetched_at
if time_delta > 300 or last_fetched_at == None or llm_provider: # if the llm provider is passed in , assume this happening due to an AuthError for that provider
time_delta = current_time - last_fetched_at_keys
if time_delta > 300 or last_fetched_at_keys == None or llm_provider: # if the llm provider is passed in , assume this happening due to an AuthError for that provider
# make the api call
last_fetched_at = time.time()
print(f"last_fetched_at: {last_fetched_at}")
last_fetched_at_keys = time.time()
print_verbose(f"last_fetched_at_keys: {last_fetched_at_keys}")
response = requests.post(url="http://api.litellm.ai/get_all_keys", headers={"content-type": "application/json"}, data=json.dumps({"user_email": user_email}))
print_verbose(f"get model key response: {response.text}")
data = response.json()
@ -1174,7 +1175,6 @@ def get_model_list():
data = response.json()
# update model list
model_list = data["model_list"]
get_all_keys()
return model_list
return [] # return empty list by default
except: