huggingface / huggingface/smolagents
[BUG] AzureOpenAIServerModel Sends Unsupported 'stop' Parameter for o1-mini
- Dominant language
- Python
- Stars
- 29.3k
- Forks
- 3k
- Avg merge
- 17m
- Merged PRs (30d)
- 2
Description
**Describe the bug**
When using the AzureOpenAIServerModel with the o1-mini deployment, the request being sent includes a "stop" parameter, which is not supported by the model. This results in a 400 error with the message:
“Unsupported parameter: 'stop' is not supported with this model.”
**Code to reproduce the error**
```python
import os
from dotenv import load_dotenv
from smolagents import CodeAgent
from smolagents.models import AzureOpenAIServerModel
load_dotenv(override=True)
if __name__ == "__main__":
model = AzureOpenAIServerModel(
model_id="o1-mini",
api_key=os.environ.get("AZURE_OPENAI_API_KEY"),
api_version=os.environ.get("AZURE_OPENAI_API_VERSION"),
azure_endpoint=os.environ.get("AZURE_OPENAI_API_BASE"),
custom_role_conversions={"system": "assistant", "tool-call": "assistant", "tool-response": "user"}
)
agent = CodeAgent(tools=[], model=model, add_base_tools=True)
agent.run("Could you give me the 118th number in the Fibonacci sequence?")
```
**Error logs (if any)**
```
Error in generating model output:
Error code: 400 - {'error': {'message': "Unsupported parameter: 'stop' is not supported with this model.", 'type': 'invalid_request_error', 'param': 'stop', 'code': 'unsupported_parameter'}}
```
**Expected behavior**
The request to Azure OpenAI should succeed without including a "stop" parameter when using the o1-mini model. The API call should complete successfully and return a valid response without triggering a 400 error.
**Packages version:**
smolagents==1.8.0
**Additional context**
The error appears to be caused by the internal method `_prepare_completion_kwargs` in the `class AzureOpenAIServerModel` class, which adds a "stop" parameter to the API request. A possible workaround is to override this method to remove the "stop" parameter if present. For example:
```python
class PatchedAzureOpenAIServerModel(AzureOpenAIServerModel):
def _prepare_completion_kwargs(self, *args, **kwargs):
completion_kwargs = super()._prepare_completion_kwargs(*args, **kwargs)
if 'stop' in completion_kwargs:
del completion_kwargs['stop']
return completion_kwargs
```
Contributor guide
Assessment
This issue has not been assessed yet.