Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions litellm/llms/custom_httpx/llm_http_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2511,7 +2511,7 @@ def response_api_handler(

api_base: Final = responses_api_provider_config.get_complete_url(
api_base=litellm_params.api_base,
litellm_params=dict(litellm_params),
litellm_params={**dict(litellm_params), "model": model},
)

data = responses_api_provider_config.transform_responses_api_request(
Expand Down Expand Up @@ -2706,7 +2706,7 @@ async def async_response_api_handler(

api_base: Final = responses_api_provider_config.get_complete_url(
api_base=litellm_params.api_base,
litellm_params=dict(litellm_params),
litellm_params={**dict(litellm_params), "model": model},
)

data = await responses_api_provider_config.async_transform_responses_api_request(
Expand Down Expand Up @@ -4452,7 +4452,7 @@ def compact_response_api_handler(

api_base: Final = responses_api_provider_config.get_complete_url(
api_base=litellm_params.api_base,
litellm_params=dict(litellm_params),
litellm_params={**dict(litellm_params), "model": model},
)

(
Expand Down Expand Up @@ -4544,7 +4544,7 @@ async def async_compact_response_api_handler(

api_base: Final = responses_api_provider_config.get_complete_url(
api_base=litellm_params.api_base,
litellm_params=dict(litellm_params),
litellm_params={**dict(litellm_params), "model": model},
)

(
Expand Down
4 changes: 2 additions & 2 deletions litellm/llms/databricks/chat/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
AnthropicConfig,
)
from ...openai_like.chat.transformation import OpenAILikeChatConfig
from ..common_utils import DatabricksBase, DatabricksException
from ..common_utils import DatabricksBase, DatabricksException, uses_unity_gateway


def _is_bare_assistant_message(message_dict: Mapping[str, object]) -> bool:
Expand Down Expand Up @@ -250,7 +250,7 @@ def get_complete_url(
litellm_params: dict,
stream: bool | None = None,
) -> str:
use_ai_gateway: Final = model.removeprefix("databricks/").count(".") >= 2
use_ai_gateway: Final = uses_unity_gateway(model)
api_base = self._get_api_base(api_base, use_ai_gateway=use_ai_gateway)
url_base: Final = api_base.rstrip("/") if use_ai_gateway else api_base
complete_url: Final = f"{url_base}/chat/completions"
Expand Down
5 changes: 5 additions & 0 deletions litellm/llms/databricks/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class DatabricksException(BaseLLMException):
pass


def uses_unity_gateway(model: str) -> bool:
"""Unity Catalog model services are named catalog.schema.model and are served by the AI Gateway."""
return model.removeprefix("databricks/").count(".") >= 2


class DatabricksBase:
"""
Base class for Databricks integration with authentication,
Expand Down
4 changes: 2 additions & 2 deletions litellm/llms/databricks/embed/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from litellm.utils import EmbeddingResponse

from ...openai_like.embedding.handler import OpenAILikeEmbeddingHandler
from ..common_utils import DatabricksBase
from ..common_utils import DatabricksBase, uses_unity_gateway


class DatabricksEmbeddingHandler(OpenAILikeEmbeddingHandler, DatabricksBase):
Expand Down Expand Up @@ -38,7 +38,7 @@ def embedding(
)

api_base, headers = self.databricks_validate_environment(
api_base=api_base,
api_base=self._get_api_base(api_base, use_ai_gateway=True) if uses_unity_gateway(model) else api_base,
api_key=api_key,
endpoint_type="embeddings",
custom_endpoint=custom_endpoint,
Expand Down
14 changes: 8 additions & 6 deletions litellm/llms/databricks/responses/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"""

import os
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, Final

from litellm.llms.databricks.common_utils import DatabricksBase
from litellm.llms.databricks.common_utils import DatabricksBase, uses_unity_gateway
from litellm.llms.openai.responses.transformation import OpenAIResponsesAPIConfig
from litellm.types.llms.openai import ResponseInputParam
from litellm.types.router import GenericLiteLLMParams
Expand Down Expand Up @@ -66,12 +67,13 @@ def validate_environment(
def get_complete_url(
self,
api_base: str | None,
litellm_params: dict,
litellm_params: Mapping[str, object],
) -> str:
api_base = api_base or os.getenv("DATABRICKS_API_BASE")
api_base = self._get_api_base(api_base)
api_base = api_base.rstrip("/")
return f"{api_base}/responses"
model: Final = str(litellm_params.get("model") or "")
resolved_api_base: Final = self._get_api_base(
api_base or os.getenv("DATABRICKS_API_BASE"), use_ai_gateway=uses_unity_gateway(model)
)
return f"{resolved_api_base.rstrip('/')}/responses"

def transform_responses_api_request(
self,
Expand Down
Loading
Loading