Skip to content

Commit

Permalink
feat(proxy_server.py): support maxage cache control
Browse files Browse the repository at this point in the history
  • Loading branch information
krrishdholakia committed Dec 26, 2023
1 parent a5f9983 commit 2355266
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions litellm/proxy/proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,20 @@ def get_litellm_model_info(model: dict = {}):
return {}


def parse_cache_control(cache_control):
cache_dict = {}
directives = cache_control.split(", ")

for directive in directives:
if "=" in directive:
key, value = directive.split("=")
cache_dict[key] = value
else:
cache_dict[directive] = True

return cache_dict


@router.on_event("startup")
async def startup_event():
global prisma_client, master_key, use_background_health_checks
Expand Down Expand Up @@ -1223,6 +1237,14 @@ async def chat_completion(
"body": copy.copy(data), # use copy instead of deepcopy
}

## Cache Controls
headers = request.headers
print("Request Headers:", headers)
cache_control_header = headers.get("Cache-Control", None)
if cache_control_header:
cache_dict = parse_cache_control(cache_control_header)
data["ttl"] = cache_dict.get("s-maxage")

print_verbose(f"receiving data: {data}")
data["model"] = (
general_settings.get("completion_model", None) # server default
Expand Down
2 changes: 1 addition & 1 deletion litellm/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,6 @@ def set_model_list(self, model_list: list):

############ End of initializing Clients for OpenAI/Azure ###################
self.deployment_names.append(model["litellm_params"]["model"])
self.print_verbose(f"\n Initialized Model List {self.model_list}")

############ Users can either pass tpm/rpm as a litellm_param or a router param ###########
# for get_available_deployment, we use the litellm_param["rpm"]
Expand All @@ -1545,6 +1544,7 @@ def set_model_list(self, model_list: list):
):
model["litellm_params"]["tpm"] = model.get("tpm")

self.print_verbose(f"\nInitialized Model List {self.model_list}")
self.model_names = [m["model_name"] for m in model_list]

def get_model_names(self):
Expand Down

0 comments on commit 2355266

Please sign in to comment.