MaartenGr / MaartenGr/BERTopic
BadRequestError: Error code: 400 - {'error': {'message': "Unsupported parameter: 'stop' is not supported with this model.", 'type': 'invalid_request_error', 'param': 'stop', 'code': 'unsupported_parameter'}}
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.8k
- Forks
- 920
- Avg merge
- 22h 24m
- Merged PRs (30d)
- 5
Description
### Have you searched existing issues? 🔎
* [x] I have searched and found no existing issues
### Describe the bug
Using `openai.AzureOpenAI` with BERTopic for fine-tuning topic representations crashes due to an unsupported `stop` parameter being inserted.
### Reproduction
```python
from bertopic import BERTopic
from bertopic.representation import OpenAI
from openai import AzureOpenAI
client = AzureOpenAI(
azure_endpoint="https://super-secret.openai.azure.com/",
azure_deployment="deployment",
api_key="api_key",
api_version="2024-12-01-preview",
)
representation_model = OpenAI(client=client)
labels, _ = BERTopic().fit(docs)
```
This results in an HTTP 400 error from Azure:
```
BadRequestError: Error code: 400 - {
'error': {
'message': "Unsupported parameter: 'stop' is not supported with this model.",
'type': 'invalid_request_error',
'param': 'stop',
'code': 'unsupported_parameter'
}
}
```
### Workaround
I resolved the issue by monkey-patching [bertopic/representation/_openai.py#L220](https://github.com/MaartenGr/BERTopic/blob/master/bertopic/representation/_openai.py#L220) to remove the parameter:
```python
kwargs.pop("stop", None)
```
### BERTopic Version
0.17.3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in bertopic/representation/_openai.py around line 220, where the issue reports that the stop parameter is inserted for the AzureOpenAI request. Reproduce the BERTopic example with AzureOpenAI and verify the request no longer fails with the unsupported-parameter error. Done means the reported configuration works without requiring the monkey-patch workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, python
- Domain
- cloud, machine-learning
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100