Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/crewai/src/crewai/llms/providers/azure/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ def _prepare_completion_params(
params["tools"] = self._convert_tools_for_interference(tools)
params["tool_choice"] = "auto"

additional_params = self.additional_params
additional_drop_params = additional_params.get('additional_drop_params')
drop_params = additional_params.get('drop_params')

if drop_params and isinstance(additional_drop_params, list):
for drop_params in additional_drop_params:
params.pop(drop_params, None)

return params

def _convert_tools_for_interference(
Expand Down
27 changes: 27 additions & 0 deletions lib/crewai/tests/llms/azure/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ def test_azure_raises_error_when_endpoint_missing():
with pytest.raises(ValueError, match="Azure endpoint is required"):
AzureCompletion(model="gpt-4", api_key="test-key")


def test_azure_raises_error_when_api_key_missing():
"""Test that AzureCompletion raises ValueError when API key is missing"""
from crewai.llms.providers.azure.completion import AzureCompletion
Expand All @@ -389,6 +390,8 @@ def test_azure_raises_error_when_api_key_missing():
with patch.dict(os.environ, {}, clear=True):
with pytest.raises(ValueError, match="Azure API key is required"):
AzureCompletion(model="gpt-4", endpoint="https://test.openai.azure.com")


def test_azure_endpoint_configuration():
"""
Test that Azure endpoint configuration works with multiple environment variable names
Expand Down Expand Up @@ -1086,3 +1089,27 @@ def test_azure_mistral_and_other_models():
)
assert "model" in params
assert params["model"] == model_name


def test_azure_completion_params_preparation_with_drop_params():
"""
Test that completion parameters are properly prepared with drop paramaeters attribute respected
"""
with patch.dict(os.environ, {
"AZURE_API_KEY": "test-key",
"AZURE_ENDPOINT": "https://models.inference.ai.azure.com"
}):
llm = LLM(
model="azure/o4-mini",
drop_params=True,
additional_drop_params=["stop"],
max_tokens=1000
)

from crewai.llms.providers.azure.completion import AzureCompletion
assert isinstance(llm, AzureCompletion)

messages = [{"role": "user", "content": "Hello"}]
params = llm._prepare_completion_params(messages)

assert params.get('stop') == None
Loading