55
66import httpx
77import pytest
8- from openai import NOT_GIVEN
8+ from openai import NOT_GIVEN , AsyncOpenAI
99from openai .types .chat .chat_completion import ChatCompletion , Choice
1010from openai .types .chat .chat_completion_chunk import ChatCompletionChunk
1111from openai .types .chat .chat_completion_message import ChatCompletionMessage
3131 generation_span ,
3232)
3333from agents .models .fake_id import FAKE_RESPONSES_ID
34+ from agents .models .openai_chatcompletions import _Converter
3435
3536
3637@pytest .mark .allow_call_model_methods
@@ -226,7 +227,7 @@ def __init__(self, completions: DummyCompletions) -> None:
226227 # Ensure expected args were passed through to OpenAI client.
227228 kwargs = completions .kwargs
228229 assert kwargs ["stream" ] is False
229- assert kwargs ["store" ] is True
230+ assert kwargs ["store" ] is NOT_GIVEN
230231 assert kwargs ["model" ] == "gpt-4"
231232 assert kwargs ["messages" ][0 ]["role" ] == "system"
232233 assert kwargs ["messages" ][0 ]["content" ] == "sys"
@@ -280,7 +281,7 @@ def __init__(self, completions: DummyCompletions) -> None:
280281 )
281282 # Check OpenAI client was called for streaming
282283 assert completions .kwargs ["stream" ] is True
283- assert completions .kwargs ["store" ] is True
284+ assert completions .kwargs ["store" ] is NOT_GIVEN
284285 assert completions .kwargs ["stream_options" ] == {"include_usage" : True }
285286 # Response is a proper openai Response
286287 assert isinstance (response , Response )
@@ -290,3 +291,39 @@ def __init__(self, completions: DummyCompletions) -> None:
290291 assert response .output == []
291292 # We returned the async iterator produced by our dummy.
292293 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