Skip to content

Comments

fix: logic for determining reasoning model#7009

Merged
mscolnick merged 1 commit intomainfrom
ms/reasoning-logic
Oct 30, 2025
Merged

fix: logic for determining reasoning model#7009
mscolnick merged 1 commit intomainfrom
ms/reasoning-logic

Conversation

@mscolnick
Copy link
Contributor

@mscolnick mscolnick commented Oct 30, 2025

This fixes the logic for determing if a model is reasoning (e.g. o1, gpt-5)

Fixes #7007

@vercel
Copy link

vercel bot commented Oct 30, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
marimo-docs Ready Ready Preview Comment Oct 30, 2025 5:56pm

Copy link
Collaborator

@manzt manzt left a comment

Choose a reason for hiding this comment

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

looks good to me

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refines the logic for detecting OpenAI reasoning models to avoid adding reasoning_effort parameters to OpenAI-compatible APIs that may not support them. The implementation now uses regex patterns to match reasoning model names (o1, o3, gpt-5 series) and checks if a custom base URL is being used to distinguish between actual OpenAI APIs and compatible proxies.

Key changes:

  • Enhanced _is_reasoning_model() method with regex-based pattern matching and base URL validation
  • Added comprehensive test coverage for reasoning model detection across various scenarios
  • Added tests to verify OpenAI-compatible APIs don't receive reasoning_effort parameters

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
marimo/_server/ai/providers.py Replaced simple string prefix check with robust regex patterns and base URL validation to identify reasoning models
tests/_server/ai/test_providers.py Added parametrized tests for reasoning model detection and OpenAI-compatible API parameter handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

the reasoning_effort parameter even if the model name suggests it's a
reasoning model.
"""
import re
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

The re module is imported inside the method instead of at the module level. Since this method may be called frequently during request processing, moving the import to the top of the file would improve performance by avoiding repeated import overhead.

Copilot uses AI. Check for mistakes.
Comment on lines +454 to +457
r"^openai/o\d", # openai/o1, openai/o3, etc.
r"^o\d", # o1, o3, etc.
r"^openai/gpt-5", # openai/gpt-5*
r"^gpt-5", # gpt-5*
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

The regex patterns use \\d which matches only a single digit, but they don't anchor the pattern or allow for continuation. This means 'o1-mini' or 'o3-mini-2024' won't match because the digit is followed by additional characters. The patterns should be r\"^openai/o\\d\"r\"^openai/o\\d+\" or r\"^openai/o\\d.*\" to match model names like 'o1-mini', 'o1-preview', 'o3-mini', etc. The same fix applies to all four patterns.

Suggested change
r"^openai/o\d", # openai/o1, openai/o3, etc.
r"^o\d", # o1, o3, etc.
r"^openai/gpt-5", # openai/gpt-5*
r"^gpt-5", # gpt-5*
r"^openai/o\d.*", # openai/o1, openai/o3, openai/o1-mini, etc.
r"^o\d.*", # o1, o3, o1-mini, etc.
r"^openai/gpt-5.*", # openai/gpt-5, openai/gpt-5-preview, etc.
r"^gpt-5.*", # gpt-5, gpt-5-preview, etc.

Copilot uses AI. Check for mistakes.
"""Test that _is_reasoning_model correctly identifies reasoning models."""
config = AnyProviderConfig(api_key="test-key", base_url=base_url)
provider = OpenAIProvider(model_name, config)
assert provider._is_reasoning_model(model_name) == expected
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

[nitpick] The test is calling a private method _is_reasoning_model() directly. While this is acceptable for unit testing internal behavior, consider whether this logic should be tested through the public API (e.g., by verifying the parameters passed to the OpenAI client) to avoid coupling tests to implementation details.

Copilot uses AI. Check for mistakes.
@mscolnick mscolnick merged commit 8904377 into main Oct 30, 2025
47 of 65 checks passed
@mscolnick mscolnick deleted the ms/reasoning-logic branch October 30, 2025 19:09
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.

Reasoning effort requested from OpenAI Compatible model when not available

2 participants