Skip to content

Commit ee9099c

Browse files
committed
refac
1 parent ee901fc commit ee9099c

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

backend/open_webui/routers/openai.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import hashlib
33
import json
44
import logging
5+
import re
56
from typing import Optional
67
from urllib.parse import urlparse
78

@@ -739,8 +740,16 @@ def get_azure_allowed_params(api_version: str) -> set[str]:
739740
return allowed_params
740741

741742

742-
def is_openai_reasoning_model(model: str) -> bool:
743-
return model.lower().startswith(('o1', 'o3', 'o4', 'gpt-5'))
743+
def is_openai_new_model(model: str) -> bool:
744+
model_lower = model.lower()
745+
# o-series models (o1, o3, o4, o5, ...)
746+
if re.match(r'^o\d+', model_lower):
747+
return True
748+
# gpt-N where N >= 5 (gpt-5, gpt-5.2, gpt-6, ...)
749+
m = re.match(r'^gpt-(\d+)', model_lower)
750+
if m and int(m.group(1)) >= 5:
751+
return True
752+
return False
744753

745754

746755
def convert_to_azure_payload(url, payload: dict, api_version: str):
@@ -750,7 +759,7 @@ def convert_to_azure_payload(url, payload: dict, api_version: str):
750759
allowed_params = get_azure_allowed_params(api_version)
751760

752761
# Special handling for o-series models
753-
if is_openai_reasoning_model(model):
762+
if is_openai_new_model(model):
754763
# Convert max_tokens to max_completion_tokens for o-series models
755764
if 'max_tokens' in payload:
756765
payload['max_completion_tokens'] = payload['max_tokens']
@@ -1040,7 +1049,7 @@ async def generate_chat_completion(
10401049
key = request.app.state.config.OPENAI_API_KEYS[idx]
10411050

10421051
# Check if model is a reasoning model that needs special handling
1043-
if is_openai_reasoning_model(payload['model']):
1052+
if is_openai_new_model(payload['model']):
10441053
payload = openai_reasoning_model_handler(payload)
10451054
elif 'api.openai.com' not in url:
10461055
# Remove "max_completion_tokens" from the payload for backward compatibility

0 commit comments

Comments
 (0)