Skip to content

fix(py/plugins/ollama): preserve chat finish reasons - #180

Open
pcbeingused33 wants to merge 2 commits into
genkit-ai:mainfrom
pcbeingused33:fix/ollama-finish-reason
Open

pcbeingused33 wants to merge 2 commits into
genkit-ai:mainfrom
pcbeingused33:fix/ollama-finish-reason

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

The Python Ollama adapter drops done_reason when building the final ModelResponse. Callers reading finish_reason cannot tell whether the model stopped normally or reached the output token limit.

Map Ollama's stop and length to Genkit's FinishReason.STOP and FinishReason.LENGTH for regular responses and final streaming responses. Missing and unknown reasons leave the field unset.

The mocked Ollama suite covers both response modes and all four input cases. The four regression cases failed before the fix, and all 262 tests pass with it. With a local Ollama server running Qwen3, the final streaming response reported stop for a short reply and length with a one-token output budget. Genkit returned None for both before the fix and reported both reasons afterward.

Disclosure: this change was prepared with AI assistance.

@huangjeff5 huangjeff5 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Pushed a small consistency tweak (0a2df9c) defaulting missing/unrecognized done_reason to FinishReason.UNKNOWN (matching genkit-openai, genkit-anthropic, and genkit-google-genai).

@huangjeff5
huangjeff5 enabled auto-merge (squash) November 30, 2026 19:52
@huangjeff5

Copy link
Copy Markdown
Collaborator

@pcbeingused33 — same cla/google username mismatch here (pcbeingused333 -> pcbeingused33). Once your GitHub username is updated at https://cla.developers.google.com/clas and rescanned in the cla/google check details, auto-merge will land this automatically.

@pcbeingused33

Copy link
Copy Markdown
Contributor Author

@googlebot I fixed it.

@pcbeingused33

Copy link
Copy Markdown
Contributor Author

Thanks @huangjeff5 — I've updated the GitHub username on my Google CLA to pcbeingused33. Could you re-run the cla/google check when you get a chance?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants