1+ """
2+ Test the regional endpoint detection logic without requiring API keys
3+ Run this to verify the fix works correctly
4+ """
5+
6+ def test_endpoint_detection ():
7+ """Test that all OpenAI regional endpoints are detected correctly"""
8+
9+ OPENAI_REASONING_MODEL_PREFIXES = (
10+ "o1-" , "o1" , "o3-" , "o3" , "o4-" ,
11+ "gpt-5-" , "gpt-5" , "gpt-oss-120b" , "gpt-oss-20b" ,
12+ )
13+
14+ test_cases = [
15+ # (api_base, model, should_be_reasoning_model, description)
16+ ("https://eu.api.openai.com/v1" , "o1-mini" , True , "EU endpoint with o1-mini" ),
17+ ("https://api.openai.com/v1" , "o1-preview" , True , "US endpoint with o1-preview" ),
18+ ("https://apac.api.openai.com/v1" , "o3-mini" , True , "APAC endpoint with o3-mini" ),
19+ ("https://eu.api.openai.com/v1" , "gpt-4" , False , "EU endpoint with gpt-4" ),
20+ ("https://api.openai.com/v1" , "gpt-3.5-turbo" , False , "US endpoint with gpt-3.5" ),
21+ ("https://azure.openai.com/" , "o1-mini" , False , "Azure endpoint (not OpenAI)" ),
22+ ("https://fake.com/api.openai.com" , "o1-mini" , False , "Fake endpoint with o1" ),
23+ (None , "o1-mini" , False , "None endpoint" ),
24+ ("" , "o1-mini" , False , "Empty endpoint" ),
25+ ("https://eu.api.openai.com/v1" , "O1-MINI" , True , "EU with uppercase model" ),
26+ ("HTTPS://EU.API.OPENAI.COM/v1" , "o1-mini" , True , "Uppercase URL" ),
27+ ]
28+
29+ print ("Testing Regional Endpoint Detection Logic" )
30+ print ("=" * 80 )
31+
32+ passed = 0
33+ failed = 0
34+
35+ for api_base , model , expected_result , description in test_cases :
36+ # This is the exact logic from your fixed code
37+ model_lower = str (model ).lower ()
38+ api_base_lower = (api_base or "" ).lower ()
39+
40+ is_openai_api = (
41+ api_base_lower .startswith ("https://api.openai.com" )
42+ or api_base_lower .startswith ("https://eu.api.openai.com" )
43+ or api_base_lower .startswith ("https://apac.api.openai.com" )
44+ or api_base_lower .startswith ("http://api.openai.com" )
45+ or api_base_lower .startswith ("http://eu.api.openai.com" )
46+ or api_base_lower .startswith ("http://apac.api.openai.com" )
47+ )
48+
49+ is_openai_reasoning_model = (
50+ is_openai_api
51+ and model_lower .startswith (OPENAI_REASONING_MODEL_PREFIXES )
52+ )
53+
54+ # Determine which parameter would be used
55+ param_used = "max_completion_tokens" if is_openai_reasoning_model else "max_tokens"
56+ expected_param = "max_completion_tokens" if expected_result else "max_tokens"
57+
58+ # Check if result matches expectation
59+ if is_openai_reasoning_model == expected_result :
60+ status = "✅ PASS"
61+ passed += 1
62+ else :
63+ status = "❌ FAIL"
64+ failed += 1
65+
66+ print (f"\n { status } | { description } " )
67+ print (f" API Base: { api_base } " )
68+ print (f" Model: { model } " )
69+ print (f" is_openai_api: { is_openai_api } " )
70+ print (f" is_reasoning_model: { is_openai_reasoning_model } " )
71+ print (f" Parameter used: { param_used } " )
72+ print (f" Expected: { expected_param } " )
73+
74+ print ("\n " + "=" * 80 )
75+ print (f"Results: { passed } passed, { failed } failed out of { len (test_cases )} tests" )
76+
77+ if failed == 0 :
78+ print ("🎉 All tests PASSED! The fix is working correctly." )
79+ return True
80+ else :
81+ print ("⚠️ Some tests FAILED! Please review the logic." )
82+ return False
83+
84+ if __name__ == "__main__" :
85+ success = test_endpoint_detection ()
86+ exit (0 if success else 1 )
0 commit comments