fix(anthropic.py): fix pr for anthropic headers

This commit is contained in:
Krrish Dholakia 2024-01-19 17:06:24 -08:00
parent 1be4f7d2d1
commit 1ec5083542

View file

@ -78,7 +78,7 @@ class AnthropicConfig:
# makes headers for API call
def validate_environment(api_key):
def validate_environment(api_key, user_headers):
if api_key is None:
raise ValueError(
"Missing Anthropic API Key - A call is being made to anthropic but no key is set either in the environment variables or via params"
@ -89,6 +89,8 @@ def validate_environment(api_key):
"content-type": "application/json",
"x-api-key": api_key,
}
if user_headers is not None and isinstance(user_headers, dict):
headers = {**headers, **user_headers}
return headers
@ -107,7 +109,7 @@ def completion(
logger_fn=None,
headers={},
):
headers = { **validate_environment(api_key), **headers }
headers = validate_environment(api_key, headers)
if model in custom_prompt_dict:
# check if the model has a registered custom prompt
model_prompt_details = custom_prompt_dict[model]