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'}}

Open Beginner friendly
#2,423 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.