MaartenGr / MaartenGr/BERTopic

Thinking models in ollama exit early

Open
#2,481 0 comments 0 reactions 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

### Desribe the bug

Even when passing in 'stop': None to bertopic.OpenAI, "stop": "\n" gets passed into the openai model call, which causes thinking models to exit early in Ollama (in particular, gemma4:e2b)

### Reproduction

```python
from bertopic import BERTopic
import openai
from bertopic.representation import OpenAI

client = openai.OpenAI(
base_url="http://localhost:11435/v1",
api_key="ollama"
)

representation_model = OpenAI(client, model="gemma4:e2b", generator_kwargs={"stop": None})
```

### BERTopic Version

0.17.4

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 by reproducing the example with BERTopic 0.17.4, Ollama, and gemma4:e2b, then trace how bertopic.representation.OpenAI handles generator_kwargs and forwards the stop option to the OpenAI-compatible call. Done means passing stop=None no longer sends a newline stop value and thinking models do not exit early; no file or test is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
ollama, python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.