MCPcopy
hub / github.com/openai/openai-python / make_snapshot_request

Function make_snapshot_request

tests/lib/snapshots.py:17–57  ·  view source on GitHub ↗
(
    func: Callable[[OpenAI], _T],
    *,
    content_snapshot: Any,
    respx_mock: MockRouter,
    mock_client: OpenAI,
    path: str,
)

Source from the content-addressed store, hash-verified

15
16
17def make_snapshot_request(
18 func: Callable[[OpenAI], _T],
19 *,
20 content_snapshot: Any,
21 respx_mock: MockRouter,
22 mock_client: OpenAI,
23 path: str,
24) -> _T:
25 live = os.environ.get("OPENAI_LIVE") == "1"
26 if live:
27
28 def _on_response(response: httpx.Response) -> None:
29 # update the content snapshot
30 assert json.dumps(json.loads(response.read())) == content_snapshot
31
32 respx_mock.stop()
33
34 client = OpenAI(
35 http_client=httpx.Client(
36 event_hooks={
37 "response": [_on_response],
38 }
39 )
40 )
41 else:
42 respx_mock.post(path).mock(
43 return_value=httpx.Response(
44 200,
45 content=get_snapshot_value(content_snapshot),
46 headers={"content-type": "application/json"},
47 )
48 )
49
50 client = mock_client
51
52 result = func(client)
53
54 if live:
55 client.close()
56
57 return result
58
59
60async def make_async_snapshot_request(

Calls 5

OpenAIClass · 0.90
stopMethod · 0.80
getMethod · 0.45
postMethod · 0.45
closeMethod · 0.45