From 75a7b397002aea3b9cd6e05915b8392d52f91ca3 Mon Sep 17 00:00:00 2001 From: frankzye1 Date: Sat, 30 Aug 2025 09:27:39 +0800 Subject: [PATCH] pass function tool description for databricks provider Signed-off-by: frankzye1 --- .../llms/databricks/chat/transformation.py | 13 ++++++--- litellm/types/llms/databricks.py | 2 +- .../test_databricks_chat_transformation.py | 28 +++++++++++++++++++ 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/litellm/llms/databricks/chat/transformation.py b/litellm/llms/databricks/chat/transformation.py index 908419f7193..3963dd4505c 100644 --- a/litellm/llms/databricks/chat/transformation.py +++ b/litellm/llms/databricks/chat/transformation.py @@ -170,12 +170,17 @@ class DatabricksConfig(DatabricksBase, OpenAILikeChatConfig, AnthropicConfig): if tool is None: return None + kwags = { + "name":tool["name"], + "parameters":cast(dict, tool.get("input_schema") or {}) + } + + if tool.get("description"): + kwags["description"] = tool.get("description") + return DatabricksTool( type="function", - function=DatabricksFunction( - name=tool["name"], - parameters=cast(dict, tool.get("input_schema") or {}), - ), + function=DatabricksFunction(**kwags), ) def _map_openai_to_dbrx_tool(self, model: str, tools: List) -> List[DatabricksTool]: diff --git a/litellm/types/llms/databricks.py b/litellm/types/llms/databricks.py index bb59b692ef7..e820cede83d 100644 --- a/litellm/types/llms/databricks.py +++ b/litellm/types/llms/databricks.py @@ -49,7 +49,7 @@ AllDatabricksContentValues = Union[str, List[AllDatabricksContentListValues]] class DatabricksFunction(TypedDict, total=False): name: Required[str] - description: dict + description: dict | str parameters: dict strict: bool diff --git a/tests/test_litellm/llms/databricks/chat/test_databricks_chat_transformation.py b/tests/test_litellm/llms/databricks/chat/test_databricks_chat_transformation.py index fc44d44aba9..55ab4428617 100644 --- a/tests/test_litellm/llms/databricks/chat/test_databricks_chat_transformation.py +++ b/tests/test_litellm/llms/databricks/chat/test_databricks_chat_transformation.py @@ -90,3 +90,31 @@ def test_transform_choices_without_signature(): thinking_block = choices[0].message.thinking_blocks[0] assert thinking_block["type"] == "thinking" assert thinking_block["thinking"] == "i'm thinking without signature." + +def test_convert_anthropic_tool_to_databricks_tool_with_description(): + config = DatabricksConfig() + anthropic_tool = { + "name": "test_tool", + "description": "test description", + "input_schema": {"type": "object", "properties": {"test": {"type": "string"}}} + } + + databricks_tool = config.convert_anthropic_tool_to_databricks_tool(anthropic_tool) + + assert databricks_tool is not None + assert databricks_tool["type"] == "function" + assert databricks_tool["function"]["description"] == "test description" + + +def test_convert_anthropic_tool_to_databricks_tool_without_description(): + config = DatabricksConfig() + anthropic_tool = { + "name": "test_tool", + "input_schema": {"type": "object", "properties": {"test": {"type": "string"}}} + } + + databricks_tool = config.convert_anthropic_tool_to_databricks_tool(anthropic_tool) + + assert databricks_tool is not None + assert databricks_tool["type"] == "function" + assert databricks_tool["function"].get("description") is None \ No newline at end of file