fix(openai.py): only allow 'user' as optional param if openai model

This commit is contained in:
Krrish Dholakia 2024-05-29 15:15:02 -07:00
parent 8f0019c241
commit 3d32b00821
3 changed files with 23 additions and 1 deletions

View file

@ -349,7 +349,6 @@ class OpenAIConfig:
"top_p",
"tools",
"tool_choice",
"user",
"function_call",
"functions",
"max_retries",
@ -362,6 +361,12 @@ class OpenAIConfig:
): # gpt-4 does not support 'response_format'
model_specific_params.append("response_format")
if (
model in litellm.open_ai_chat_completion_models
) or model in litellm.open_ai_text_completion_models:
model_specific_params.append(
"user"
) # user is not a param supported by all openai-compatible endpoints - e.g. azure ai
return base_params + model_specific_params
def map_openai_params(

View file

@ -52,5 +52,10 @@ model_list:
api_version: '2023-05-15'
model: azure/chatgpt-v-2
model_name: gpt-3.5-turbo
- model_name: mistral
litellm_params:
model: azure/mistral-large-latest
api_base: https://Mistral-large-nmefg-serverless.eastus2.inference.ai.azure.com/v1/
api_key: zEJhgmw1FAKk0XzPWoLEg7WU1cXbWYYn
router_settings:
enable_pre_call_checks: true

View file

@ -97,6 +97,18 @@ def test_databricks_optional_params():
assert "user" not in optional_params
def test_azure_ai_mistral_optional_params():
litellm.drop_params = True
optional_params = get_optional_params(
model="mistral-large-latest",
user="John",
custom_llm_provider="openai",
max_tokens=10,
temperature=0.2,
)
assert "user" not in optional_params
def test_azure_gpt_optional_params_gpt_vision():
# for OpenAI, Azure all extra params need to get passed as extra_body to OpenAI python. We assert we actually set extra_body here
optional_params = litellm.utils.get_optional_params(