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]] = {} additional_details: Optional[Dict[str, str]] = {}
local_cache: Optional[Dict[str, str]] = {} local_cache: Optional[Dict[str, str]] = {}
last_fetched_at = None last_fetched_at = None
last_fetched_at_keys = None
######## Model Response ######################### ######## Model Response #########################
# All liteLLM Model responses will be in this format, Follows the OpenAI Format # All liteLLM Model responses will be in this format, Follows the OpenAI Format
# https://docs.litellm.ai/docs/completion/output # 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): def get_all_keys(llm_provider=None):
try: 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 # 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}") 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") user_email = os.getenv("LITELLM_EMAIL") or litellm.email or litellm.token or os.getenv("LITELLM_TOKEN")
if user_email: if user_email:
time_delta = 0 time_delta = 0
if last_fetched_at != None: if last_fetched_at_keys != None:
current_time = time.time() current_time = time.time()
time_delta = current_time - last_fetched_at time_delta = current_time - last_fetched_at_keys
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 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 # make the api call
last_fetched_at = time.time() last_fetched_at_keys = time.time()
print(f"last_fetched_at: {last_fetched_at}") 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})) 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}") print_verbose(f"get model key response: {response.text}")
data = response.json() data = response.json()
@ -1174,7 +1175,6 @@ def get_model_list():
data = response.json() data = response.json()
# update model list # update model list
model_list = data["model_list"] model_list = data["model_list"]
get_all_keys()
return model_list return model_list
return [] # return empty list by default return [] # return empty list by default
except: except:

View file

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "litellm" name = "litellm"
version = "0.1.480" version = "0.1.481"
description = "Library to easily interface with LLM API providers" description = "Library to easily interface with LLM API providers"
authors = ["BerriAI"] authors = ["BerriAI"]
license = "MIT License" license = "MIT License"