5
5
6
6
import httpx
7
7
import pytest
8
- from openai import NOT_GIVEN
8
+ from openai import NOT_GIVEN , AsyncOpenAI
9
9
from openai .types .chat .chat_completion import ChatCompletion , Choice
10
10
from openai .types .chat .chat_completion_chunk import ChatCompletionChunk
11
11
from openai .types .chat .chat_completion_message import ChatCompletionMessage
31
31
generation_span ,
32
32
)
33
33
from agents .models .fake_id import FAKE_RESPONSES_ID
34
+ from agents .models .openai_chatcompletions import _Converter
34
35
35
36
36
37
@pytest .mark .allow_call_model_methods
@@ -226,7 +227,7 @@ def __init__(self, completions: DummyCompletions) -> None:
226
227
# Ensure expected args were passed through to OpenAI client.
227
228
kwargs = completions .kwargs
228
229
assert kwargs ["stream" ] is False
229
- assert kwargs ["store" ] is True
230
+ assert kwargs ["store" ] is NOT_GIVEN
230
231
assert kwargs ["model" ] == "gpt-4"
231
232
assert kwargs ["messages" ][0 ]["role" ] == "system"
232
233
assert kwargs ["messages" ][0 ]["content" ] == "sys"
@@ -280,7 +281,7 @@ def __init__(self, completions: DummyCompletions) -> None:
280
281
)
281
282
# Check OpenAI client was called for streaming
282
283
assert completions .kwargs ["stream" ] is True
283
- assert completions .kwargs ["store" ] is True
284
+ assert completions .kwargs ["store" ] is NOT_GIVEN
284
285
assert completions .kwargs ["stream_options" ] == {"include_usage" : True }
285
286
# Response is a proper openai Response
286
287
assert isinstance (response , Response )
@@ -290,3 +291,39 @@ def __init__(self, completions: DummyCompletions) -> None:
290
291
assert response .output == []
291
292
# We returned the async iterator produced by our dummy.
292
293
assert hasattr (stream , "__aiter__" )
294
+
295
+
296
+ def test_store_param ():
297
+ """Should default to True for OpenAI API calls, and False otherwise."""
298
+
299
+ model_settings = ModelSettings ()
300
+ client = AsyncOpenAI ()
301
+ assert _Converter .get_store_param (client , model_settings ) is True , (
302
+ "Should default to True for OpenAI API calls"
303
+ )
304
+
305
+ model_settings = ModelSettings (store = False )
306
+ assert _Converter .get_store_param (client , model_settings ) is False , (
307
+ "Should respect explicitly set store=False"
308
+ )
309
+
310
+ model_settings = ModelSettings (store = True )
311
+ assert _Converter .get_store_param (client , model_settings ) is True , (
312
+ "Should respect explicitly set store=True"
313
+ )
314
+
315
+ client = AsyncOpenAI (base_url = "http://www.notopenai.com" )
316
+ model_settings = ModelSettings ()
317
+ assert _Converter .get_store_param (client , model_settings ) is None , (
318
+ "Should default to None for non-OpenAI API calls"
319
+ )
320
+
321
+ model_settings = ModelSettings (store = False )
322
+ assert _Converter .get_store_param (client , model_settings ) is False , (
323
+ "Should respect explicitly set store=False"
324
+ )
325
+
326
+ model_settings = ModelSettings (store = True )
327
+ assert _Converter .get_store_param (client , model_settings ) is True , (
328
+ "Should respect explicitly set store=True"
329
+ )
0 commit comments