11"""
22Test OpenAI reasoning model detection logic
3+
4+ Updated to use the extracted is_reasoning_model() function instead of
5+ duplicating detection logic locally.
36"""
47
58import unittest
6- from unittest .mock import MagicMock
9+
10+ from openevolve .llm .openai import OPENAI_REASONING_MODEL_PREFIXES , is_reasoning_model
711
812
913class TestOpenAIReasoningModelDetection (unittest .TestCase ):
10- """Test that OpenAI reasoning models are correctly identified"""
14+ """Test that OpenAI reasoning models are correctly identified via auto-detection """
1115
1216 def test_reasoning_model_detection (self ):
1317 """Test various model names to ensure correct reasoning model detection"""
14-
15- # Define the same constants as in the code
16- OPENAI_REASONING_MODEL_PREFIXES = (
17- # O-series reasoning models
18- "o1-" ,
19- "o1" , # o1, o1-mini, o1-preview
20- "o3-" ,
21- "o3" , # o3, o3-mini, o3-pro
22- "o4-" , # o4-mini
23- # GPT-5 series are also reasoning models
24- "gpt-5-" ,
25- "gpt-5" , # gpt-5, gpt-5-mini, gpt-5-nano
26- )
27-
28- def is_reasoning_model (model_name , api_base = "https://api.openai.com/v1" ):
29- """Test function that mimics the logic in openai.py"""
30- model_lower = str (model_name ).lower ()
31- return api_base == "https://api.openai.com/v1" and model_lower .startswith (
32- OPENAI_REASONING_MODEL_PREFIXES
33- )
34-
35- # Test cases: (model_name, expected_result, description)
3618 test_cases = [
37- # Reasoning models - should return True
19+ # Reasoning models - should return True (auto-detect)
3820 ("o1" , True , "Base o1 model" ),
3921 ("o1-mini" , True , "o1-mini model" ),
4022 ("o1-preview" , True , "o1-preview model" ),
@@ -46,14 +28,16 @@ def is_reasoning_model(model_name, api_base="https://api.openai.com/v1"):
4628 ("gpt-5" , True , "Base gpt-5 model" ),
4729 ("gpt-5-mini" , True , "gpt-5-mini model" ),
4830 ("gpt-5-nano" , True , "gpt-5-nano model" ),
49- # Non-reasoning models - should return False
31+ ("gpt-oss-120b" , True , "gpt-oss-120b model" ),
32+ ("gpt-oss-20b" , True , "gpt-oss-20b model" ),
33+ # Non-reasoning models - should return False (auto-detect)
5034 ("gpt-4o-mini" , False , "gpt-4o-mini (not reasoning)" ),
5135 ("gpt-4o" , False , "gpt-4o (not reasoning)" ),
5236 ("gpt-4" , False , "gpt-4 (not reasoning)" ),
5337 ("gpt-3.5-turbo" , False , "gpt-3.5-turbo (not reasoning)" ),
5438 ("claude-3" , False , "Non-OpenAI model" ),
5539 ("gemini-pro" , False , "Non-OpenAI model" ),
56- # Edge cases
40+ # Case insensitivity
5741 ("O1-MINI" , True , "Uppercase o1-mini" ),
5842 ("GPT-5-MINI" , True , "Uppercase gpt-5-mini" ),
5943 ]
@@ -67,32 +51,29 @@ def is_reasoning_model(model_name, api_base="https://api.openai.com/v1"):
6751 f"Model '{ model_name } ' ({ description } ): expected { expected } , got { result } " ,
6852 )
6953
70- def test_non_openai_api_base (self ):
71- """Test that non-OpenAI API bases don't trigger reasoning model logic"""
72- OPENAI_REASONING_MODEL_PREFIXES = ("o1-" , "o1" , "o3-" , "o3" , "o4-" , "gpt-5-" , "gpt-5" )
73-
74- def is_reasoning_model (model_name , api_base ):
75- model_lower = str (model_name ).lower ()
76- return api_base == "https://api.openai.com/v1" and model_lower .startswith (
77- OPENAI_REASONING_MODEL_PREFIXES
78- )
79-
80- # Even reasoning model names should return False for non-OpenAI APIs
81- test_cases = [
82- ("o1-mini" , "https://api.anthropic.com/v1" , False ),
83- ("gpt-5" , "https://generativelanguage.googleapis.com/v1beta/openai/" , False ),
84- ("o3-mini" , "https://api.deepseek.com/v1" , False ),
54+ def test_non_openai_models_not_auto_detected (self ):
55+ """Non-OpenAI models should not be auto-detected as reasoning models"""
56+ non_openai_models = [
57+ "gemini-2.5-pro" ,
58+ "gemini-2.5-flash" ,
59+ "claude-sonnet-4-5-20250929" ,
60+ "claude-opus-4-5-20251101" ,
61+ "deepseek-r1" ,
8562 ]
86-
87- for model_name , api_base , expected in test_cases :
88- with self .subTest (model = model_name , api = api_base ):
89- result = is_reasoning_model (model_name , api_base )
90- self .assertEqual (
91- result ,
92- expected ,
93- f"Model '{ model_name } ' with API '{ api_base } ' should return { expected } " ,
63+ for model_name in non_openai_models :
64+ with self .subTest (model = model_name ):
65+ self .assertFalse (
66+ is_reasoning_model (model_name ),
67+ f"Non-OpenAI model '{ model_name } ' should not be auto-detected" ,
9468 )
9569
70+ def test_explicit_override_ignores_api_base (self ):
71+ """Explicit config_flag overrides auto-detection regardless of model origin"""
72+ # Even non-OpenAI models can be forced to reasoning mode
73+ self .assertTrue (is_reasoning_model ("gemini-2.5-flash" , config_flag = True ))
74+ # Even OpenAI reasoning models can be forced to standard mode
75+ self .assertFalse (is_reasoning_model ("o3-mini" , config_flag = False ))
76+
9677
9778if __name__ == "__main__" :
9879 unittest .main ()
0 commit comments