From 06a2a8b40f6fc75e7f5140bc3f952d9a4bb8e0f8 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 28 Feb 2024 16:52:47 -0800 Subject: [PATCH 01/10] (feat) track OpenAI models support function calling --- ...odel_prices_and_context_window_backup.json | 32 +++++++++++++------ model_prices_and_context_window.json | 32 +++++++++++++------ 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index c4aa8169fd4..bf82bb2b1f1 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -6,7 +6,8 @@ "input_cost_per_token": 0.00003, "output_cost_per_token": 0.00006, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "gpt-4-turbo-preview": { "max_tokens": 8192, @@ -15,7 +16,9 @@ "input_cost_per_token": 0.00001, "output_cost_per_token": 0.00003, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "gpt-4-0314": { "max_tokens": 8192, @@ -33,7 +36,8 @@ "input_cost_per_token": 0.00003, "output_cost_per_token": 0.00006, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "gpt-4-32k": { "max_tokens": 32768, @@ -69,7 +73,9 @@ "input_cost_per_token": 0.00001, "output_cost_per_token": 0.00003, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "gpt-4-0125-preview": { "max_tokens": 128000, @@ -78,7 +84,9 @@ "input_cost_per_token": 0.00001, "output_cost_per_token": 0.00003, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "gpt-4-vision-preview": { "max_tokens": 128000, @@ -105,7 +113,8 @@ "input_cost_per_token": 0.0000015, "output_cost_per_token": 0.000002, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "gpt-3.5-turbo-0301": { "max_tokens": 4097, @@ -123,7 +132,8 @@ "input_cost_per_token": 0.0000015, "output_cost_per_token": 0.000002, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "gpt-3.5-turbo-1106": { "max_tokens": 16385, @@ -132,7 +142,9 @@ "input_cost_per_token": 0.0000010, "output_cost_per_token": 0.0000020, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "gpt-3.5-turbo-0125": { "max_tokens": 16385, @@ -141,7 +153,9 @@ "input_cost_per_token": 0.0000005, "output_cost_per_token": 0.0000015, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "gpt-3.5-turbo-16k": { "max_tokens": 16385, diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index c4aa8169fd4..bf82bb2b1f1 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -6,7 +6,8 @@ "input_cost_per_token": 0.00003, "output_cost_per_token": 0.00006, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "gpt-4-turbo-preview": { "max_tokens": 8192, @@ -15,7 +16,9 @@ "input_cost_per_token": 0.00001, "output_cost_per_token": 0.00003, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "gpt-4-0314": { "max_tokens": 8192, @@ -33,7 +36,8 @@ "input_cost_per_token": 0.00003, "output_cost_per_token": 0.00006, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "gpt-4-32k": { "max_tokens": 32768, @@ -69,7 +73,9 @@ "input_cost_per_token": 0.00001, "output_cost_per_token": 0.00003, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "gpt-4-0125-preview": { "max_tokens": 128000, @@ -78,7 +84,9 @@ "input_cost_per_token": 0.00001, "output_cost_per_token": 0.00003, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "gpt-4-vision-preview": { "max_tokens": 128000, @@ -105,7 +113,8 @@ "input_cost_per_token": 0.0000015, "output_cost_per_token": 0.000002, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "gpt-3.5-turbo-0301": { "max_tokens": 4097, @@ -123,7 +132,8 @@ "input_cost_per_token": 0.0000015, "output_cost_per_token": 0.000002, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "gpt-3.5-turbo-1106": { "max_tokens": 16385, @@ -132,7 +142,9 @@ "input_cost_per_token": 0.0000010, "output_cost_per_token": 0.0000020, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "gpt-3.5-turbo-0125": { "max_tokens": 16385, @@ -141,7 +153,9 @@ "input_cost_per_token": 0.0000005, "output_cost_per_token": 0.0000015, "litellm_provider": "openai", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "gpt-3.5-turbo-16k": { "max_tokens": 16385, From e16c204003b4c593cacefa61c6aa0da18f00586d Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 28 Feb 2024 17:00:03 -0800 Subject: [PATCH 02/10] (feat) track azure models that support function calling --- ...odel_prices_and_context_window_backup.json | 39 +++++++++++++++---- model_prices_and_context_window.json | 39 +++++++++++++++---- 2 files changed, 62 insertions(+), 16 deletions(-) diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index bf82bb2b1f1..352a5410047 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -300,7 +300,9 @@ "input_cost_per_token": 0.00001, "output_cost_per_token": 0.00003, "litellm_provider": "azure", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "azure/gpt-4-1106-preview": { "max_tokens": 128000, @@ -309,7 +311,9 @@ "input_cost_per_token": 0.00001, "output_cost_per_token": 0.00003, "litellm_provider": "azure", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "azure/gpt-4-0613": { "max_tokens": 8192, @@ -318,7 +322,8 @@ "input_cost_per_token": 0.00003, "output_cost_per_token": 0.00006, "litellm_provider": "azure", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "azure/gpt-4-32k-0613": { "max_tokens": 32768, @@ -345,7 +350,8 @@ "input_cost_per_token": 0.00003, "output_cost_per_token": 0.00006, "litellm_provider": "azure", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "azure/gpt-4-turbo": { "max_tokens": 128000, @@ -354,7 +360,9 @@ "input_cost_per_token": 0.00001, "output_cost_per_token": 0.00003, "litellm_provider": "azure", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "azure/gpt-4-turbo-vision-preview": { "max_tokens": 128000, @@ -372,7 +380,8 @@ "input_cost_per_token": 0.000003, "output_cost_per_token": 0.000004, "litellm_provider": "azure", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "azure/gpt-35-turbo-1106": { "max_tokens": 16384, @@ -381,7 +390,20 @@ "input_cost_per_token": 0.0000015, "output_cost_per_token": 0.000002, "litellm_provider": "azure", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true + }, + "azure/gpt-35-turbo-0125": { + "max_tokens": 16384, + "max_input_tokens": 16384, + "max_output_tokens": 4096, + "input_cost_per_token": 0.0000005, + "output_cost_per_token": 0.0000015, + "litellm_provider": "azure", + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "azure/gpt-35-turbo-16k": { "max_tokens": 16385, @@ -399,7 +421,8 @@ "input_cost_per_token": 0.0000015, "output_cost_per_token": 0.000002, "litellm_provider": "azure", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "azure/ada": { "max_tokens": 8191, diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index bf82bb2b1f1..352a5410047 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -300,7 +300,9 @@ "input_cost_per_token": 0.00001, "output_cost_per_token": 0.00003, "litellm_provider": "azure", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "azure/gpt-4-1106-preview": { "max_tokens": 128000, @@ -309,7 +311,9 @@ "input_cost_per_token": 0.00001, "output_cost_per_token": 0.00003, "litellm_provider": "azure", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "azure/gpt-4-0613": { "max_tokens": 8192, @@ -318,7 +322,8 @@ "input_cost_per_token": 0.00003, "output_cost_per_token": 0.00006, "litellm_provider": "azure", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "azure/gpt-4-32k-0613": { "max_tokens": 32768, @@ -345,7 +350,8 @@ "input_cost_per_token": 0.00003, "output_cost_per_token": 0.00006, "litellm_provider": "azure", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "azure/gpt-4-turbo": { "max_tokens": 128000, @@ -354,7 +360,9 @@ "input_cost_per_token": 0.00001, "output_cost_per_token": 0.00003, "litellm_provider": "azure", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "azure/gpt-4-turbo-vision-preview": { "max_tokens": 128000, @@ -372,7 +380,8 @@ "input_cost_per_token": 0.000003, "output_cost_per_token": 0.000004, "litellm_provider": "azure", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "azure/gpt-35-turbo-1106": { "max_tokens": 16384, @@ -381,7 +390,20 @@ "input_cost_per_token": 0.0000015, "output_cost_per_token": 0.000002, "litellm_provider": "azure", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true + }, + "azure/gpt-35-turbo-0125": { + "max_tokens": 16384, + "max_input_tokens": 16384, + "max_output_tokens": 4096, + "input_cost_per_token": 0.0000005, + "output_cost_per_token": 0.0000015, + "litellm_provider": "azure", + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true }, "azure/gpt-35-turbo-16k": { "max_tokens": 16385, @@ -399,7 +421,8 @@ "input_cost_per_token": 0.0000015, "output_cost_per_token": 0.000002, "litellm_provider": "azure", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "azure/ada": { "max_tokens": 8191, From fae08830a403c1e688e421039107266ef35e1890 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 28 Feb 2024 17:09:04 -0800 Subject: [PATCH 03/10] (feat) tg ai track if the model supports function calling --- .../model_prices_and_context_window_backup.json | 17 +++++++++++++++++ model_prices_and_context_window.json | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index 352a5410047..ad934b39fee 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -1775,6 +1775,23 @@ "output_cost_per_token": 0.0000009, "litellm_provider": "together_ai" }, + "together_ai/mistralai/Mixtral-8x7B-Instruct-v0.1": { + "input_cost_per_token": 0.0000006, + "output_cost_per_token": 0.0000006, + "litellm_provider": "together_ai", + "supports_function_calling": true, + "supports_parallel_function_calling": true + }, + "together_ai/mistralai/Mistral-7B-Instruct-v0.1": { + "litellm_provider": "together_ai", + "supports_function_calling": true, + "supports_parallel_function_calling": true + }, + "together_ai/togethercomputer/CodeLlama-34b-Instruct": { + "litellm_provider": "together_ai", + "supports_function_calling": true, + "supports_parallel_function_calling": true + }, "ollama/llama2": { "max_tokens": 4096, "input_cost_per_token": 0.0, diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index 352a5410047..ad934b39fee 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -1775,6 +1775,23 @@ "output_cost_per_token": 0.0000009, "litellm_provider": "together_ai" }, + "together_ai/mistralai/Mixtral-8x7B-Instruct-v0.1": { + "input_cost_per_token": 0.0000006, + "output_cost_per_token": 0.0000006, + "litellm_provider": "together_ai", + "supports_function_calling": true, + "supports_parallel_function_calling": true + }, + "together_ai/mistralai/Mistral-7B-Instruct-v0.1": { + "litellm_provider": "together_ai", + "supports_function_calling": true, + "supports_parallel_function_calling": true + }, + "together_ai/togethercomputer/CodeLlama-34b-Instruct": { + "litellm_provider": "together_ai", + "supports_function_calling": true, + "supports_parallel_function_calling": true + }, "ollama/llama2": { "max_tokens": 4096, "input_cost_per_token": 0.0, From 13040a97a74155a53d0aaaaddb3c86b9a1f9732a Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 28 Feb 2024 17:13:04 -0800 Subject: [PATCH 04/10] (feat) support mistral function calling --- litellm/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/litellm/utils.py b/litellm/utils.py index 18307eebc85..e658ad2e7c0 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -4048,6 +4048,7 @@ def get_optional_params( and custom_llm_provider != "vertex_ai" and custom_llm_provider != "anyscale" and custom_llm_provider != "together_ai" + and custom_llm_provider != "mistral" ): if custom_llm_provider == "ollama" or custom_llm_provider == "ollama_chat": # ollama actually supports json output From 2601600b33f9d73d0f9c267a3e884c77a80d679e Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 28 Feb 2024 17:15:50 -0800 Subject: [PATCH 05/10] (feat) track mistral model supports function calling --- litellm/model_prices_and_context_window_backup.json | 3 ++- litellm/tests/test_function_calling.py | 2 +- model_prices_and_context_window.json | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index ad934b39fee..ae25001f46e 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -555,7 +555,8 @@ "input_cost_per_token": 0.000008, "output_cost_per_token": 0.000024, "litellm_provider": "mistral", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "mistral/mistral-embed": { "max_tokens": 8192, diff --git a/litellm/tests/test_function_calling.py b/litellm/tests/test_function_calling.py index ffef8f6594f..44cf9d8c675 100644 --- a/litellm/tests/test_function_calling.py +++ b/litellm/tests/test_function_calling.py @@ -71,7 +71,7 @@ def test_parallel_function_call(): } ] response = litellm.completion( - model="gpt-3.5-turbo-1106", + model="mistral/mistral-medium-latest", messages=messages, tools=tools, tool_choice="auto", # auto is default, but we'll be explicit diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index ad934b39fee..ae25001f46e 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -555,7 +555,8 @@ "input_cost_per_token": 0.000008, "output_cost_per_token": 0.000024, "litellm_provider": "mistral", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "mistral/mistral-embed": { "max_tokens": 8192, From 070a2a044840e805928f3c4faf11d681d3f84178 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 28 Feb 2024 17:21:43 -0800 Subject: [PATCH 06/10] (feat) track if mode supports function calling --- litellm/model_prices_and_context_window_backup.json | 3 ++- model_prices_and_context_window.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index ae25001f46e..7faa3b2753a 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -714,7 +714,8 @@ "input_cost_per_token": 0.00000025, "output_cost_per_token": 0.0000005, "litellm_provider": "vertex_ai-language-models", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "gemini-1.5-pro": { "max_tokens": 8192, diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index ae25001f46e..7faa3b2753a 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -714,7 +714,8 @@ "input_cost_per_token": 0.00000025, "output_cost_per_token": 0.0000005, "litellm_provider": "vertex_ai-language-models", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true }, "gemini-1.5-pro": { "max_tokens": 8192, From 97d9b98ce3ab9ab76338198cd6ba1a3ea57e3e7e Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 28 Feb 2024 17:23:48 -0800 Subject: [PATCH 07/10] (feat) track anyscale function calling models --- litellm/model_prices_and_context_window_backup.json | 11 ++++++++++- model_prices_and_context_window.json | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index 7faa3b2753a..c3649ac4f21 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -2046,7 +2046,16 @@ "input_cost_per_token": 0.00000015, "output_cost_per_token": 0.00000015, "litellm_provider": "anyscale", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true + }, + "anyscale/Mixtral-8x7B-Instruct-v0.1": { + "max_tokens": 16384, + "input_cost_per_token": 0.00000015, + "output_cost_per_token": 0.00000015, + "litellm_provider": "anyscale", + "mode": "chat", + "supports_function_calling": true }, "anyscale/HuggingFaceH4/zephyr-7b-beta": { "max_tokens": 16384, diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index 7faa3b2753a..c3649ac4f21 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -2046,7 +2046,16 @@ "input_cost_per_token": 0.00000015, "output_cost_per_token": 0.00000015, "litellm_provider": "anyscale", - "mode": "chat" + "mode": "chat", + "supports_function_calling": true + }, + "anyscale/Mixtral-8x7B-Instruct-v0.1": { + "max_tokens": 16384, + "input_cost_per_token": 0.00000015, + "output_cost_per_token": 0.00000015, + "litellm_provider": "anyscale", + "mode": "chat", + "supports_function_calling": true }, "anyscale/HuggingFaceH4/zephyr-7b-beta": { "max_tokens": 16384, From 32f72335ab4028ddf68553b54c931beabbf1dd62 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 28 Feb 2024 17:32:01 -0800 Subject: [PATCH 08/10] (feat) helpers for supports_function_calling --- litellm/utils.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/litellm/utils.py b/litellm/utils.py index e658ad2e7c0..2e16aee61c5 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -3720,6 +3720,54 @@ def completion_cost( raise e +def supports_function_calling(model: str): + """ + Check if the given model supports function calling and return a boolean value. + + Parameters: + model (str): The model name to be checked. + + Returns: + bool: True if the model supports function calling, False otherwise. + + Raises: + Exception: If the given model is not found in model_prices_and_context_window.json. + """ + if model in litellm.model_cost: + model_info = litellm.model_cost[model] + if model_info.get("supports_function_calling", False): + return True + return False + else: + raise Exception( + f"Model not in model_prices_and_context_window.json. You passed model={model}." + ) + + +def supports_parallel_function_calling(model: str): + """ + Check if the given model supports parallel function calling and return True if it does, False otherwise. + + Parameters: + model (str): The model to check for support of parallel function calling. + + Returns: + bool: True if the model supports parallel function calling, False otherwise. + + Raises: + Exception: If the model is not found in the model_cost dictionary. + """ + if model in litellm.model_cost: + model_info = litellm.model_cost[model] + if model_info.get("supports_parallel_function_calling", False): + return True + return False + else: + raise Exception( + f"Model not in model_prices_and_context_window.json. You passed model={model}." + ) + + ####### HELPER FUNCTIONS ################ def register_model(model_cost: Union[str, dict]): """ From 56d20cd0737e9c6facfb9ce75bde99d765b0dfb4 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 28 Feb 2024 17:36:15 -0800 Subject: [PATCH 09/10] (test) supports_function_calling --- litellm/__init__.py | 2 ++ litellm/tests/test_utils.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/litellm/__init__.py b/litellm/__init__.py index 3ba33741581..cd639ddb9b7 100644 --- a/litellm/__init__.py +++ b/litellm/__init__.py @@ -549,6 +549,8 @@ from .utils import ( token_counter, cost_per_token, completion_cost, + supports_function_calling, + supports_parallel_function_calling, get_litellm_params, Logging, acreate, diff --git a/litellm/tests/test_utils.py b/litellm/tests/test_utils.py index a9e1c75fe12..e094afee6d6 100644 --- a/litellm/tests/test_utils.py +++ b/litellm/tests/test_utils.py @@ -317,3 +317,27 @@ def test_token_counter(): # test_token_counter() + + +def test_supports_function_calling(): + try: + assert litellm.supports_function_calling(model="gpt-3.5-turbo") == True + assert ( + litellm.supports_function_calling(model="azure/gpt-4-1106-preview") == True + ) + assert ( + litellm.supports_function_calling( + model="bedrock/anthropic.claude-instant-v1" + ) + == False + ) + assert litellm.supports_function_calling(model="palm/chat-bison") == False + assert litellm.supports_function_calling(model="ollama/llama2") == False + assert ( + litellm.supports_function_calling(model="anthropic.claude-instant-v1") + == False + ) + assert litellm.supports_function_calling(model="claude-2") == False + + except Exception as e: + pytest.fail(f"Error occurred: {e}") From 76e7f8831f8a1e2bf86eeb423955f1692a5f4dcc Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 28 Feb 2024 17:41:54 -0800 Subject: [PATCH 10/10] (docs) check if supports function calling --- .../docs/completion/function_call.md | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/docs/my-website/docs/completion/function_call.md b/docs/my-website/docs/completion/function_call.md index 8004a55d12b..5daccf72321 100644 --- a/docs/my-website/docs/completion/function_call.md +++ b/docs/my-website/docs/completion/function_call.md @@ -1,18 +1,25 @@ # Function Calling -Function calling is supported with the following models on OpenAI, Azure OpenAI -- gpt-4 -- gpt-4-1106-preview -- gpt-4-0613 -- gpt-3.5-turbo -- gpt-3.5-turbo-1106 -- gpt-3.5-turbo-0613 -- Non OpenAI LLMs (litellm adds the function call to the prompt for these llms) +## Checking if a model supports function calling -In addition, parallel function calls is supported on the following models: -- gpt-4-1106-preview -- gpt-3.5-turbo-1106 +Use `litellm.supports_function_calling(model="")` -> returns `True` if model supports Function calling, `False` if not +```python +assert litellm.supports_function_calling(model="gpt-3.5-turbo") == True +assert litellm.supports_function_calling(model="azure/gpt-4-1106-preview") == True +assert litellm.supports_function_calling(model="palm/chat-bison") == False +assert litellm.supports_function_calling(model="ollama/llama2") == False +``` + + +## Checking if a model supports parallel function calling + +Use `litellm.supports_parallel_function_calling(model="")` -> returns `True` if model supports parallel function calling, `False` if not + +```python +assert litellm.supports_parallel_function_calling(model="gpt-4-turbo-preview") == True +assert litellm.supports_parallel_function_calling(model="gpt-4") == False +``` ## Parallel Function calling Parallel function calling is the model's ability to perform multiple function calls together, allowing the effects and results of these function calls to be resolved in parallel