build(litellm_server/main.py): fix keys in environment

This commit is contained in:
Krrish Dholakia 2023-10-26 16:54:06 -07:00
parent 89c94cf14f
commit ffa036566b
3 changed files with 8 additions and 7 deletions

View file

@ -1921,12 +1921,12 @@ def validate_environment(model: Optional[str]=None) -> dict:
if model is None:
return {"keys_in_environment": keys_in_environment, "missing_keys": missing_keys}
## EXTRACT LLM PROVIDER - if model name provided
custom_llm_provider = None
# check if llm provider part of model name
if model.split("/",1)[0] in litellm.provider_list:
custom_llm_provider = model.split("/", 1)[0]
model = model.split("/", 1)[1]
custom_llm_provider_passed_in = True
custom_llm_provider = get_llm_provider(model=model)
# # check if llm provider part of model name
# if model.split("/",1)[0] in litellm.provider_list:
# custom_llm_provider = model.split("/", 1)[0]
# model = model.split("/", 1)[1]
# custom_llm_provider_passed_in = True
if custom_llm_provider:
if custom_llm_provider == "openai":

View file

View file

@ -91,7 +91,8 @@ async def chat_completion(request: Request):
try:
data = await request.json()
# default to always using the "ENV" variables, only if AUTH_STRATEGY==DYNAMIC then reads headers
if os.getenv("AUTH_STRATEGY", None) == "DYNAMIC" and "authorization" in request.headers: # if users pass LLM api keys as part of header
keys_in_environment, _ = litellm.validate_environment(model=data["model"])
if (keys_in_environment is False or os.getenv("AUTH_STRATEGY", None) == "DYNAMIC") and "authorization" in request.headers: # if users pass LLM api keys as part of header
api_key = request.headers.get("authorization")
api_key = api_key.replace("Bearer", "").strip()
if len(api_key.strip()) > 0: