Skip to content

481 strip frequency penalty#482

Open
Omarhus01 wants to merge 2 commits into
SylphAI-Inc:mainfrom
Omarhus01:481_strip-frequency-penalty
Open

481 strip frequency penalty#482
Omarhus01 wants to merge 2 commits into
SylphAI-Inc:mainfrom
Omarhus01:481_strip-frequency-penalty

Conversation

@Omarhus01

Copy link
Copy Markdown

What does this PR do?

Fixes #481

Problem

When AdalFlow is used with OpenAI reasoning models (o1, o3, o3-mini, o4, gpt-5 family), every API call fails with:

Responses.create() got an unexpected keyword argument 'frequency_penalty'

This breaks the official quickstart Colab notebook and any user code that passes frequency_penalty (a common default) when using a reasoning model. OpenAI's Responses API rejects frequency_penalty for reasoning models, but AdalFlow forwards all kwargs unconditionally.

Fix

Adds a _strip_unsupported_reasoning_kwargs helper on OpenAIClient that:

  • Detects reasoning models by model-name prefix (o1, o3, o4, gpt-5).
  • Removes a configurable allowlist of unsupported kwargs (_UNSUPPORTED_REASONING_KWARGS).
  • Returns a copy — never mutates the caller's dict.
  • Logs stripped kwargs at debug level.

The helper is invoked at the top of the LLM/LLM_REASONING branch in both call and acall, so both sync and async paths are covered.

Scope

Conservative on purpose: only frequency_penalty is stripped right now, since that is the parameter confirmed broken in #481. The constant _UNSUPPORTED_REASONING_KWARGS is a tuple so additional params (presence_penalty, top_p, logit_bias, etc.) can be added in follow-up PRs as they are independently confirmed.

Tests

Added four unit tests in adalflow/tests/test_openai_client.py:

  1. frequency_penalty is stripped for each reasoning prefix (o1, o3-mini, o4-turbo, gpt-5).
  2. frequency_penalty is preserved for non-reasoning models (e.g. gpt-4o).
  3. Unrelated kwargs (temperature, max_tokens) are left intact.
  4. The helper does not mutate the input dict.

Before submitting

  • Did you read the contributor guideline?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you write any new necessary tests?
  • Did you verify new and existing tests pass locally with your changes?

@Omarhus01

Copy link
Copy Markdown
Author

For context on why I picked this fix: I was running through the AdalFlow quickstart while reading the LLM-AutoDiff paper, and the breakage in the Object Count training loop blocks exactly the demonstration the paper builds on — selective gradient computation on a teacher generator, which is o3-mini in this notebook.

Happy to extend this to other params (presence_penalty, top_p) in a follow-up if you'd like a broader sweep, but kept this PR scoped to the one parameter the traceback proved was rejected.

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.

Quickstart Colab fails with frequency_penalty error on OpenAI Responses API (o3-mini teacher model)

1 participant