mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +00:00
* LiteLLM Minor Fixes & Improvements (09/26/2024) (#5925)
* fix(litellm_logging.py): don't initialize prometheus_logger if non premium user
Prevents bad error messages in logs
Fixes https://github.com/BerriAI/litellm/issues/5897
* Add Support for Custom Providers in Vision and Function Call Utils (#5688)
* Add Support for Custom Providers in Vision and Function Call Utils Lookup
* Remove parallel function call due to missing model info param
* Add Unit Tests for Vision and Function Call Changes
* fix-#5920: set header value to string to fix "'int' object has no att… (#5922)
* LiteLLM Minor Fixes & Improvements (09/24/2024) (#5880)
* LiteLLM Minor Fixes & Improvements (09/23/2024) (#5842)
* feat(auth_utils.py): enable admin to allow client-side credentials to be passed
Makes it easier for devs to experiment with finetuned fireworks ai models
* feat(router.py): allow setting configurable_clientside_auth_params for a model
Closes https://github.com/BerriAI/litellm/issues/5843
* build(model_prices_and_context_window.json): fix anthropic claude-3-5-sonnet max output token limit
Fixes https://github.com/BerriAI/litellm/issues/5850
* fix(azure_ai/): support content list for azure ai
Fixes https://github.com/BerriAI/litellm/issues/4237
* fix(litellm_logging.py): always set saved_cache_cost
Set to 0 by default
* fix(fireworks_ai/cost_calculator.py): add fireworks ai default pricing
handles calling 405b+ size models
* fix(slack_alerting.py): fix error alerting for failed spend tracking
Fixes regression with slack alerting error monitoring
* fix(vertex_and_google_ai_studio_gemini.py): handle gemini no candidates in streaming chunk error
* docs(bedrock.md): add llama3-1 models
* test: fix tests
* fix(azure_ai/chat): fix transformation for azure ai calls
* feat(azure_ai/embed): Add azure ai embeddings support
Closes https://github.com/BerriAI/litellm/issues/5861
* fix(azure_ai/embed): enable async embedding
* feat(azure_ai/embed): support azure ai multimodal embeddings
* fix(azure_ai/embed): support async multi modal embeddings
* feat(together_ai/embed): support together ai embedding calls
* feat(rerank/main.py): log source documents for rerank endpoints to langfuse
improves rerank endpoint logging
* fix(langfuse.py): support logging `/audio/speech` input to langfuse
* test(test_embedding.py): fix test
* test(test_completion_cost.py): fix helper util
* fix-#5920: set header value to string to fix "'int' object has no attribute 'encode'"
---------
Co-authored-by: Krish Dholakia <krrishdholakia@gmail.com>
* Revert "fix-#5920: set header value to string to fix "'int' object has no att…" (#5926)
This reverts commit a554ae2695
.
* build(model_prices_and_context_window.json): add azure ai cohere rerank model pricing
Enables cost tracking for azure ai cohere rerank models
* fix(litellm_logging.py): fix debug log to be clearer
Closes https://github.com/BerriAI/litellm/issues/5909
* test(test_utils.py): fix test name
* fix(azure_ai/cost_calculator.py): support cost tracking for azure ai rerank models
* fix(azure_ai): fix azure ai base model cost tracking for rerank endpoints
* fix(converse_handler.py): support new llama 3-2 models
Fixes https://github.com/BerriAI/litellm/issues/5901
* fix(litellm_logging.py): ensure response is redacted for standard message logging
Fixes https://github.com/BerriAI/litellm/issues/5890#issuecomment-2378242360
* fix(cost_calculator.py): use 'get_model_info' for cohere rerank cost calculation
allows user to set custom cost for model
* fix(config.yml): fix docker hub auht
* build(config.yml): add docker auth to all tests
* fix(db/create_views.py): fix linting error
* fix(main.py): fix circular import
* fix(azure_ai/__init__.py): fix circular import
* fix(main.py): fix import
* fix: fix linting errors
* test: fix test
* fix(proxy_server.py): pass premium user value on startup
used for prometheus init
---------
Co-authored-by: Cole Murray <colemurray.cs@gmail.com>
Co-authored-by: bravomark <62681807+bravomark@users.noreply.github.com>
* handle streaming for azure ai studio error
* [Perf Proxy] parallel request limiter - use one cache update call (#5932)
* fix parallel request limiter - use one cache update call
* ci/cd run again
* run ci/cd again
* use docker username password
* fix config.yml
* fix config
* fix config
* fix config.yml
* ci/cd run again
* use correct typing for batch set cache
* fix async_set_cache_pipeline
* fix only check user id tpm / rpm limits when limits set
* fix test_openai_azure_embedding_with_oidc_and_cf
* test: fix test
* test(test_rerank.py): fix test
---------
Co-authored-by: Cole Murray <colemurray.cs@gmail.com>
Co-authored-by: bravomark <62681807+bravomark@users.noreply.github.com>
Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
125 lines
4.3 KiB
Python
125 lines
4.3 KiB
Python
from typing import Any, Dict, List, Optional, Union
|
|
|
|
import httpx
|
|
|
|
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
|
|
from litellm.llms.cohere.rerank import CohereRerank
|
|
from litellm.rerank_api.types import RerankResponse
|
|
|
|
|
|
class AzureAIRerank(CohereRerank):
|
|
|
|
def get_base_model(self, azure_model_group: Optional[str]) -> Optional[str]:
|
|
if azure_model_group is None:
|
|
return None
|
|
if azure_model_group == "offer-cohere-rerank-mul-paygo":
|
|
return "azure_ai/cohere-rerank-v3-multilingual"
|
|
if azure_model_group == "offer-cohere-rerank-eng-paygo":
|
|
return "azure_ai/cohere-rerank-v3-english"
|
|
return azure_model_group
|
|
|
|
async def async_azure_rerank(
|
|
self,
|
|
model: str,
|
|
api_key: str,
|
|
api_base: str,
|
|
query: str,
|
|
documents: List[Union[str, Dict[str, Any]]],
|
|
headers: Optional[dict],
|
|
litellm_logging_obj: LiteLLMLoggingObj,
|
|
top_n: Optional[int] = None,
|
|
rank_fields: Optional[List[str]] = None,
|
|
return_documents: Optional[bool] = True,
|
|
max_chunks_per_doc: Optional[int] = None,
|
|
):
|
|
returned_response: RerankResponse = await super().rerank( # type: ignore
|
|
model=model,
|
|
api_key=api_key,
|
|
api_base=api_base,
|
|
query=query,
|
|
documents=documents,
|
|
top_n=top_n,
|
|
rank_fields=rank_fields,
|
|
return_documents=return_documents,
|
|
max_chunks_per_doc=max_chunks_per_doc,
|
|
_is_async=True,
|
|
headers=headers,
|
|
litellm_logging_obj=litellm_logging_obj,
|
|
)
|
|
|
|
# get base model
|
|
additional_headers = (
|
|
returned_response._hidden_params.get("additional_headers") or {}
|
|
)
|
|
|
|
base_model = self.get_base_model(
|
|
additional_headers.get("llm_provider-azureml-model-group")
|
|
)
|
|
returned_response._hidden_params["model"] = base_model
|
|
|
|
return returned_response
|
|
|
|
def rerank(
|
|
self,
|
|
model: str,
|
|
api_key: str,
|
|
api_base: str,
|
|
query: str,
|
|
documents: List[Union[str, Dict[str, Any]]],
|
|
headers: Optional[dict],
|
|
litellm_logging_obj: LiteLLMLoggingObj,
|
|
top_n: Optional[int] = None,
|
|
rank_fields: Optional[List[str]] = None,
|
|
return_documents: Optional[bool] = True,
|
|
max_chunks_per_doc: Optional[int] = None,
|
|
_is_async: Optional[bool] = False,
|
|
) -> RerankResponse:
|
|
|
|
if headers is None:
|
|
headers = {"Authorization": "Bearer {}".format(api_key)}
|
|
else:
|
|
headers = {**headers, "Authorization": "Bearer {}".format(api_key)}
|
|
|
|
# Assuming api_base is a string representing the base URL
|
|
api_base_url = httpx.URL(api_base)
|
|
|
|
# Replace the path with '/v1/rerank' if it doesn't already end with it
|
|
if not api_base_url.path.endswith("/v1/rerank"):
|
|
api_base = str(api_base_url.copy_with(path="/v1/rerank"))
|
|
|
|
if _is_async:
|
|
return self.async_azure_rerank( # type: ignore
|
|
model=model,
|
|
api_key=api_key,
|
|
api_base=api_base,
|
|
query=query,
|
|
documents=documents,
|
|
top_n=top_n,
|
|
rank_fields=rank_fields,
|
|
return_documents=return_documents,
|
|
max_chunks_per_doc=max_chunks_per_doc,
|
|
headers=headers,
|
|
litellm_logging_obj=litellm_logging_obj,
|
|
)
|
|
else:
|
|
returned_response = super().rerank(
|
|
model=model,
|
|
api_key=api_key,
|
|
api_base=api_base,
|
|
query=query,
|
|
documents=documents,
|
|
top_n=top_n,
|
|
rank_fields=rank_fields,
|
|
return_documents=return_documents,
|
|
max_chunks_per_doc=max_chunks_per_doc,
|
|
_is_async=_is_async,
|
|
headers=headers,
|
|
litellm_logging_obj=litellm_logging_obj,
|
|
)
|
|
|
|
# get base model
|
|
base_model = self.get_base_model(
|
|
returned_response._hidden_params.get("llm_provider-azureml-model-group")
|
|
)
|
|
returned_response._hidden_params["model"] = base_model
|
|
return returned_response
|