Litellm dev 12 25 2024 p1 (#7411)

* test(test_watsonx.py): e2e unit test for watsonx custom header

covers https://github.com/BerriAI/litellm/issues/7408

* fix(common_utils.py): handle auth token already present in headers (watsonx + openai-like base handler)

Fixes https://github.com/BerriAI/litellm/issues/7408

* fix(watsonx/chat): fix chat route

Fixes https://github.com/BerriAI/litellm/issues/7408

* fix(huggingface/chat/handler.py): fix huggingface async completion calls

* Correct handling of max_retries=0 to disable AzureOpenAI retries (#7379)

* test: fix test

---------

Co-authored-by: Minh Duc <phamminhduc0711@gmail.com>
This commit is contained in:
Krish Dholakia 2024-12-25 17:36:30 -08:00 committed by GitHub
parent 157810fcbf
commit 9237357bcc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 299 additions and 14 deletions

View file

@ -53,7 +53,9 @@ def generate_iam_token(api_key=None, **params) -> str:
headers,
data,
)
response = httpx.post(iam_token_url, data=data, headers=headers)
response = litellm.module_level_client.post(
url=iam_token_url, data=data, headers=headers
)
response.raise_for_status()
json_data = response.json()
@ -165,10 +167,13 @@ class IBMWatsonXMixin:
optional_params: Dict,
api_key: Optional[str] = None,
) -> Dict:
headers = {
default_headers = {
"Content-Type": "application/json",
"Accept": "application/json",
}
if "Authorization" in headers:
return {**default_headers, **headers}
token = cast(Optional[str], optional_params.get("token"))
if token:
headers["Authorization"] = f"Bearer {token}"
@ -176,7 +181,7 @@ class IBMWatsonXMixin:
token = _generate_watsonx_token(api_key=api_key, token=token)
# build auth headers
headers["Authorization"] = f"Bearer {token}"
return headers
return {**default_headers, **headers}
def _get_base_url(self, api_base: Optional[str]) -> str:
url = (