1717logger = logging .getLogger ("AutoRAG" )
1818
1919MAX_TOKEN_DICT = { # model name : token limit
20+ "gpt-4.5-preview" : 128_000 ,
21+ "gpt-4.5-preview-2025-02-27" : 128_000 ,
22+ "o1" : 200_000 ,
2023 "o1-preview" : 128_000 ,
2124 "o1-preview-2024-09-12" : 128_000 ,
2225 "o1-mini" : 128_000 ,
2326 "o1-mini-2024-09-12" : 128_000 ,
27+ "o3-mini" : 200_000 ,
2428 "gpt-4o-mini" : 128_000 ,
2529 "gpt-4o-mini-2024-07-18" : 128_000 ,
2630 "gpt-4o" : 128_000 ,
@@ -57,7 +61,7 @@ def __init__(self, project_dir, llm: str, batch: int = 16, *args, **kwargs):
5761 client_init_params = pop_params (AsyncOpenAI .__init__ , kwargs )
5862 self .client = AsyncOpenAI (** client_init_params )
5963
60- if self .llm .startswith ("o1 " ):
64+ if self .llm .startswith ("gpt-4.5 " ):
6165 self .tokenizer = tiktoken .get_encoding ("o200k_base" )
6266 else :
6367 self .tokenizer = tiktoken .encoding_for_model (self .llm )
@@ -112,7 +116,7 @@ def _pure(
112116 kwargs .pop ("n" )
113117 logger .warning ("parameter n does not effective. It always set to 1." )
114118
115- # TODO: fix this after updating tiktoken for the o1 model. It is not yet supported yet.
119+ # TODO: fix this after updating tiktoken for the gpt-4.5 model. It is not yet supported yet.
116120 if truncate :
117121 prompts = list (
118122 map (
@@ -125,7 +129,7 @@ def _pure(
125129
126130 openai_chat_params = pop_params (self .client .chat .completions .create , kwargs )
127131 loop = get_event_loop ()
128- if self .llm .startswith ("o1" ):
132+ if self .llm .startswith ("o1" ) or self . llm . startswith ( "o3" ) :
129133 tasks = [
130134 self .get_result_o1 (prompt , ** openai_chat_params ) for prompt in prompts
131135 ]
@@ -159,7 +163,7 @@ def structured_output(self, prompts: List[str], output_cls, **kwargs):
159163 kwargs .pop ("n" )
160164 logger .warning ("parameter n does not effective. It always set to 1." )
161165
162- # TODO: fix this after updating tiktoken for the o1 model. It is not yet supported yet.
166+ # TODO: fix this after updating tiktoken for the gpt-4.5 model. It is not yet supported yet.
163167 prompts = list (
164168 map (
165169 lambda prompt : truncate_by_token (
@@ -179,6 +183,7 @@ def structured_output(self, prompts: List[str], output_cls, **kwargs):
179183 return result
180184
181185 async def astream (self , prompt : str , ** kwargs ):
186+ # TODO: gpt-4.5-preview does not support logprobs. It should be fixed after the openai update.
182187 if kwargs .get ("logprobs" ) is not None :
183188 kwargs .pop ("logprobs" )
184189 logger .warning (
@@ -212,42 +217,59 @@ def stream(self, prompt: str, **kwargs):
212217 raise NotImplementedError ("stream method is not implemented yet." )
213218
214219 async def get_structured_result (self , prompt : str , output_cls , ** kwargs ):
220+ logprobs = True
221+ if self .llm .startswith ("gpt-4.5" ):
222+ logprobs = False
215223 response = await self .client .beta .chat .completions .parse (
216224 model = self .llm ,
217225 messages = [
218226 {"role" : "user" , "content" : prompt },
219227 ],
220228 response_format = output_cls ,
221- logprobs = False ,
229+ logprobs = logprobs ,
222230 n = 1 ,
223231 ** kwargs ,
224232 )
225233 return response .choices [0 ].message .parsed
226234
227235 async def get_result (self , prompt : str , ** kwargs ):
236+ # TODO: gpt-4.5-preview does not support logprobs. It should be fixed after the openai update.
237+ logprobs = True
238+ if self .llm .startswith ("gpt-4.5" ):
239+ logprobs = False
228240 response = await self .client .chat .completions .create (
229241 model = self .llm ,
230242 messages = [
231243 {"role" : "user" , "content" : prompt },
232244 ],
233- logprobs = True ,
245+ logprobs = logprobs ,
234246 n = 1 ,
235247 ** kwargs ,
236248 )
237249 choice = response .choices [0 ]
238250 answer = choice .message .content
239- logprobs = list (map (lambda x : x .logprob , choice .logprobs .content ))
240- tokens = list (
241- map (
242- lambda x : self .tokenizer .encode (x .token , allowed_special = "all" )[0 ],
243- choice .logprobs .content ,
251+ # TODO: gpt-4.5-preview does not support logprobs. It should be fixed after the openai update.
252+ if self .llm .startswith ("gpt-4.5" ):
253+ tokens = self .tokenizer .encode (answer , allowed_special = "all" )
254+ logprobs = [0.5 ] * len (tokens )
255+ logger .warning ("gpt-4.5-preview does not support logprobs yet." )
256+ else :
257+ logprobs = list (map (lambda x : x .logprob , choice .logprobs .content ))
258+ tokens = list (
259+ map (
260+ lambda x : self .tokenizer .encode (x .token , allowed_special = "all" )[0 ],
261+ choice .logprobs .content ,
262+ )
244263 )
245- )
246- assert len (tokens ) == len (logprobs ), "tokens and logprobs size is different."
264+ assert len (tokens ) == len (
265+ logprobs
266+ ), "tokens and logprobs size is different."
247267 return answer , tokens , logprobs
248268
249269 async def get_result_o1 (self , prompt : str , ** kwargs ):
250- assert self .llm .startswith ("o1" ), "This function only supports o1 model."
270+ assert self .llm .startswith ("o1" ) or self .llm .startswith (
271+ "o3"
272+ ), "This function only supports o1 or o3 model."
251273 # The default temperature for the o1 model is 1. 1 is only supported.
252274 # See https://platform.openai.com/docs/guides/reasoning about beta limitation of o1 models.
253275 kwargs ["temperature" ] = 1
0 commit comments