Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test_databricks_anthropic_function_call_with_no_schema

Ishaan Jaffer964e683c8588
diff --git a/tests/llm_translation/test_databricks.py b/tests/llm_translation/test_databricks.py
index e9e6e67ec1f..386a71ea53c 100644
--- a/tests/llm_translation/test_databricks.py
+++ b/tests/llm_translation/test_databricks.py
@@ -1065,4 +1065,86 @@ def test_completion_with_prompt_caching_nonclaude_model(monkeypatch):
assert response['usage']['prompt_tokens'] == 1638
assert response['usage']['completion_tokens'] == 500
assert response['usage']['total_tokens'] == 2138
-
\ No newline at end of file
+
+
+ "model",
+ [
+ "databricks/databricks-claude-3-7-sonnet"
+ ],
+)
+def test_databricks_anthropic_function_call_with_no_schema(model, monkeypatch):
+ """
+ Test function calling with tools that have no parameters schema using mocked HTTP responses.
+ Relevant Issue: https://github.com/BerriAI/litellm/issues/6012
+ """
+ base_url = "https://my.workspace.cloud.databricks.com/serving-endpoints"
+ api_key = "dapimykey"
+ monkeypatch.setenv("DATABRICKS_API_BASE", base_url)
+ monkeypatch.setenv("DATABRICKS_API_KEY", api_key)
+
+ mock_response_data = {
+ "id": "chatcmpl-abc123",
+ "object": "chat.completion",
+ "created": 1699896916,
+ "model": "databricks-claude-3-7-sonnet",
+ "choices": [
+ {
+ "index": 0,
+ "message": {
+ "role": "assistant",
+ "content": None,
+ "tool_calls": [
+ {
+ "id": "call_abc123",
+ "type": "function",
+ "function": {
+ "name": "get_current_weather",
+ "arguments": "{}",
+ },
+ }
+ ],
+ },
+ "logprobs": None,
+ "finish_reason": "tool_calls",
+ }
+ ],
+ "usage": {
+ "prompt_tokens": 50,
+ "completion_tokens": 10,
+ "total_tokens": 60,
+ },
+ }
+
+ mock_response = Mock(spec=httpx.Response)
+ mock_response.status_code = 200
+ mock_response.json.return_value = mock_response_data
+
+ sync_handler = HTTPHandler()
+
+ tools = [
+ {
+ "type": "function",
+ "function": {
+ "name": "get_current_weather",
+ "description": "Get the current weather in New York",
+ },
+ }
+ ]
+ messages = [
+ {"role": "user", "content": "What is the current temperature in New York?"}
+ ]
+
+ with patch.object(HTTPHandler, "post", return_value=mock_response):
+ response = completion(
+ model=model,
+ messages=messages,
+ tools=tools,
+ tool_choice="auto",
+ client=sync_handler
+ )
+
+ assert response.choices[0].message.tool_calls is not None
+ assert len(response.choices[0].message.tool_calls) == 1
+ assert response.choices[0].message.tool_calls[0].function.name == "get_current_weather"
+
diff --git a/tests/local_testing/test_function_calling.py b/tests/local_testing/test_function_calling.py
index 7aa2584f6ab..296066b2422 100644
--- a/tests/local_testing/test_function_calling.py
+++ b/tests/local_testing/test_function_calling.py
@@ -558,33 +558,6 @@ def test_groq_parallel_function_call():
pytest.fail(f"Error occurred: {e}")
- "model",
- [
- # "anthropic.claude-3-sonnet-20240229-v1:0",
- # "claude-3-haiku-20240307",
- "databricks/databricks-claude-3-7-sonnet"
- ],
-)
-def test_anthropic_function_call_with_no_schema(model):
- """
- Relevant Issue: https://github.com/BerriAI/litellm/issues/6012
- """
- tools = [
- {
- "type": "function",
- "function": {
- "name": "get_current_weather",
- "description": "Get the current weather in New York",
- },
- }
- ]
- messages = [
- {"role": "user", "content": "What is the current temperature in New York?"}
- ]
- completion(model=model, messages=messages, tools=tools, tool_choice="auto")
-
-
@pytest.mark.parametrize(
"model",
[