diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index 9c980aa3a1..f0eebfe1e8 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -191,6 +191,29 @@ def cost_per_token( * completion_tokens ) return prompt_tokens_cost_usd_dollar, completion_tokens_cost_usd_dollar + elif "ft:gpt-4-0613" in model: + print_verbose(f"Cost Tracking: {model} is an OpenAI FinteTuned LLM") + # fuzzy match ft:gpt-4-0613:abcd-id-cool-litellm + prompt_tokens_cost_usd_dollar = ( + model_cost_ref["ft:gpt-4-0613"]["input_cost_per_token"] * prompt_tokens + ) + completion_tokens_cost_usd_dollar = ( + model_cost_ref["ft:gpt-4-0613"]["output_cost_per_token"] * completion_tokens + ) + return prompt_tokens_cost_usd_dollar, completion_tokens_cost_usd_dollar + elif "ft:gpt-4o-2024-05-13" in model: + print_verbose(f"Cost Tracking: {model} is an OpenAI FinteTuned LLM") + # fuzzy match ft:gpt-4o-2024-05-13:abcd-id-cool-litellm + prompt_tokens_cost_usd_dollar = ( + model_cost_ref["ft:gpt-4o-2024-05-13"]["input_cost_per_token"] + * prompt_tokens + ) + completion_tokens_cost_usd_dollar = ( + model_cost_ref["ft:gpt-4o-2024-05-13"]["output_cost_per_token"] + * completion_tokens + ) + return prompt_tokens_cost_usd_dollar, completion_tokens_cost_usd_dollar + elif "ft:davinci-002" in model: print_verbose(f"Cost Tracking: {model} is an OpenAI FinteTuned LLM") # fuzzy match ft:davinci-002:abcd-id-cool-litellm diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index 473f3d3fe4..437dd48f26 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -234,6 +234,30 @@ "litellm_provider": "openai", "mode": "chat" }, + "ft:gpt-4-0613": { + "max_tokens": 4096, + "max_input_tokens": 8192, + "max_output_tokens": 4096, + "input_cost_per_token": 0.00003, + "output_cost_per_token": 0.00006, + "litellm_provider": "openai", + "mode": "chat", + "supports_function_calling": true, + "source": "OpenAI needs to add pricing for this ft model, will be updated when added by OpenAI. Defaulting to base model pricing" + }, + "ft:gpt-4o-2024-05-13": { + "max_tokens": 4096, + "max_input_tokens": 128000, + "max_output_tokens": 4096, + "input_cost_per_token": 0.000005, + "output_cost_per_token": 0.000015, + "litellm_provider": "openai", + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true, + "supports_vision": true, + "source": "OpenAI needs to add pricing for this ft model, will be updated when added by OpenAI. Defaulting to base model pricing" + }, "ft:davinci-002": { "max_tokens": 16384, "max_input_tokens": 16384, diff --git a/litellm/tests/test_utils.py b/litellm/tests/test_utils.py index 70213c42d5..e958a3a656 100644 --- a/litellm/tests/test_utils.py +++ b/litellm/tests/test_utils.py @@ -24,6 +24,7 @@ from litellm.utils import ( create_pretrained_tokenizer, create_tokenizer, function_to_dict, + get_llm_provider, get_max_tokens, get_supported_openai_params, get_token_count, @@ -517,3 +518,33 @@ def test_duration_in_seconds(): value = _duration_in_seconds(duration="1mo") assert value - expected_duration < 2 + + +def test_get_llm_provider_ft_models(): + """ + All ft prefixed models should map to OpenAI + gpt-3.5-turbo-0125 (recommended), + gpt-3.5-turbo-1106, + gpt-3.5-turbo-0613, + gpt-4-0613 (experimental) + gpt-4o-2024-05-13. + babbage-002, davinci-002, + + """ + model, custom_llm_provider, _, _ = get_llm_provider(model="ft:gpt-3.5-turbo-0125") + assert custom_llm_provider == "openai" + + model, custom_llm_provider, _, _ = get_llm_provider(model="ft:gpt-3.5-turbo-1106") + assert custom_llm_provider == "openai" + + model, custom_llm_provider, _, _ = get_llm_provider(model="ft:gpt-3.5-turbo-0613") + assert custom_llm_provider == "openai" + + model, custom_llm_provider, _, _ = get_llm_provider(model="ft:gpt-4-0613") + assert custom_llm_provider == "openai" + + model, custom_llm_provider, _, _ = get_llm_provider(model="ft:gpt-3.5-turbo-0613") + assert custom_llm_provider == "openai" + + model, custom_llm_provider, _, _ = get_llm_provider(model="ft:gpt-4o-2024-05-13") + assert custom_llm_provider == "openai" diff --git a/litellm/utils.py b/litellm/utils.py index 8b207d26e2..65896f0cd3 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -4050,6 +4050,7 @@ def get_llm_provider( if ( model in litellm.open_ai_chat_completion_models or "ft:gpt-3.5-turbo" in model + or "ft:gpt-4" in model # catches ft:gpt-4-0613, ft:gpt-4o or model in litellm.openai_image_generation_models ): custom_llm_provider = "openai" diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index 473f3d3fe4..437dd48f26 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -234,6 +234,30 @@ "litellm_provider": "openai", "mode": "chat" }, + "ft:gpt-4-0613": { + "max_tokens": 4096, + "max_input_tokens": 8192, + "max_output_tokens": 4096, + "input_cost_per_token": 0.00003, + "output_cost_per_token": 0.00006, + "litellm_provider": "openai", + "mode": "chat", + "supports_function_calling": true, + "source": "OpenAI needs to add pricing for this ft model, will be updated when added by OpenAI. Defaulting to base model pricing" + }, + "ft:gpt-4o-2024-05-13": { + "max_tokens": 4096, + "max_input_tokens": 128000, + "max_output_tokens": 4096, + "input_cost_per_token": 0.000005, + "output_cost_per_token": 0.000015, + "litellm_provider": "openai", + "mode": "chat", + "supports_function_calling": true, + "supports_parallel_function_calling": true, + "supports_vision": true, + "source": "OpenAI needs to add pricing for this ft model, will be updated when added by OpenAI. Defaulting to base model pricing" + }, "ft:davinci-002": { "max_tokens": 16384, "max_input_tokens": 16384,