You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Record timestamp for rate limiting (one timestamp per batch item)
253
254
ifself.rpm_limitisnotNone:
254
-
self._request_timestamps.append(time.monotonic())
255
+
current_time=time.monotonic()
256
+
for_inrange(len(batch_to_send)):
257
+
self._request_timestamps.append(current_time)
255
258
256
259
# Extract content from each response
257
260
results= []
@@ -280,7 +283,15 @@ def generate(
280
283
281
284
282
285
classOpenAIProvider(LLMProvider):
283
-
"""OpenAI provider using litellm."""
286
+
"""OpenAI provider using litellm.responses endpoint.
287
+
288
+
Note: This provider uses the new responses endpoint which has different
289
+
parameter support compared to the standard completion endpoint:
290
+
- temperature, top_p, and frequency_penalty are not supported
291
+
- Uses text_format instead of response_format
292
+
- Supports reasoning parameter for controlling reasoning effort
293
+
- Does not support batch operations (will process sequentially with warning)
294
+
"""
284
295
285
296
@property
286
297
defprovider_name(self) ->str:
@@ -294,29 +305,187 @@ def __init__(
294
305
self,
295
306
model_id: str="gpt-5-mini-2025-08-07",
296
307
api_key: str|None=None,
297
-
temperature: float|None=None,
298
308
max_completion_tokens: int|None=None,
309
+
reasoning_effort: str="low",
310
+
temperature: float|None=None,
299
311
top_p: float|None=None,
300
312
frequency_penalty: float|None=None,
301
313
):
302
314
"""Initialize the OpenAI provider.
303
315
304
316
Args:
305
-
model_id: The model ID (defaults to gpt-5-mini-2025-08-07)
317
+
model_id: The model ID (defaults to gpt-5-mini)
306
318
api_key: API key (if None, will get from environment)
307
-
temperature: The sampling temperature to be used, between 0 and 2. Higher values like 0.8 produce more random outputs, while lower values like 0.2 make outputs more focused and deterministic
308
319
max_completion_tokens: An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.
309
-
top_p: Nucleus sampling parameter (0.0 to 1.0)
310
-
frequency_penalty: Penalty for token frequency (-2.0 to 2.0)
320
+
reasoning_effort: Reasoning effort level - "low", "medium", or "high" (defaults to "low")
321
+
temperature: DEPRECATED - Not supported by responses endpoint
322
+
top_p: DEPRECATED - Not supported by responses endpoint
323
+
frequency_penalty: DEPRECATED - Not supported by responses endpoint
311
324
"""
325
+
# Warn about deprecated parameters
326
+
iftemperatureisnotNone:
327
+
warnings.warn(
328
+
"temperature parameter is not supported by OpenAI responses endpoint and will be ignored",
329
+
UserWarning,
330
+
stacklevel=2
331
+
)
332
+
iftop_pisnotNone:
333
+
warnings.warn(
334
+
"top_p parameter is not supported by OpenAI responses endpoint and will be ignored",
335
+
UserWarning,
336
+
stacklevel=2
337
+
)
338
+
iffrequency_penaltyisnotNone:
339
+
warnings.warn(
340
+
"frequency_penalty parameter is not supported by OpenAI responses endpoint and will be ignored",
341
+
UserWarning,
342
+
stacklevel=2
343
+
)
344
+
345
+
# Store reasoning effort
346
+
self.reasoning_effort=reasoning_effort
347
+
348
+
# Call parent init with None for unsupported params
312
349
super().__init__(
313
350
model_id=model_id,
314
351
api_key=api_key,
315
-
temperature=temperature,
352
+
temperature=None,
316
353
max_completion_tokens=max_completion_tokens,
317
-
top_p=top_p,
318
-
frequency_penalty=frequency_penalty,
354
+
top_p=None,
355
+
frequency_penalty=None,
319
356
)
357
+
358
+
defgenerate(
359
+
self,
360
+
prompt: str|list[str] |None=None,
361
+
messages: list[Messages] |Messages|None=None,
362
+
response_format: Type[T] |None=None,
363
+
) ->str|list[str] |T|list[T]:
364
+
"""
365
+
Generate responses from the LLM using the responses endpoint.
366
+
367
+
Note: Batch operations are processed sequentially as the responses endpoint
368
+
does not support native batching.
369
+
370
+
Args:
371
+
prompt: Single text prompt (str) or list of text prompts for batch processing
372
+
messages: Single message list or list of message lists for batch processing
373
+
response_format: Optional Pydantic model class for structured output
374
+
375
+
Returns:
376
+
Single string/model or list of strings/models depending on input type.
377
+
378
+
Raises:
379
+
ValueError: If neither prompt nor messages is provided, or if both are provided.
380
+
RuntimeError: If there's an error during generation.
381
+
"""
382
+
# Validate inputs
383
+
ifpromptisNoneandmessagesisNone:
384
+
raiseValueError("Either prompts or messages must be provided")
385
+
ifpromptisnotNoneandmessagesisnotNone:
386
+
raiseValueError("Provide either prompts or messages, not both")
387
+
388
+
# Determine if this is a single input or batch input
389
+
single_input=False
390
+
batch_prompts=None
391
+
batch_messages=None
392
+
393
+
ifpromptisnotNone:
394
+
ifisinstance(prompt, str):
395
+
# Single prompt - convert to batch
396
+
batch_prompts= [prompt]
397
+
single_input=True
398
+
elifisinstance(prompt, list):
399
+
# Already a list of prompts
400
+
batch_prompts=prompt
401
+
single_input=False
402
+
else:
403
+
raiseValueError("prompt must be a string or list of strings")
0 commit comments