openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.8.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/test_runs.py

651lines · modeblame

baa9f07fRobert Craigie2 years ago1# File generated from our OpenAPI spec by Stainless.
2
3from __future__ import annotations
4
5import os
86379b44Stainless Bot2 years ago6from typing import Any, cast
baa9f07fRobert Craigie2 years ago7
8import pytest
9
10from openai import OpenAI, AsyncOpenAI
11from tests.utils import assert_matches_type
12from openai._client import OpenAI, AsyncOpenAI
13from openai.pagination import SyncCursorPage, AsyncCursorPage
a47375b7Stainless Bot2 years ago14from openai.types.beta.threads import (
15Run,
16)
baa9f07fRobert Craigie2 years ago17
18base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
19api_key = "My API Key"
20
21
22class TestRuns:
23strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
24loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
25parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
26
27@parametrize
28def test_method_create(self, client: OpenAI) -> None:
29run = client.beta.threads.runs.create(
30"string",
31assistant_id="string",
32)
33assert_matches_type(Run, run, path=["response"])
34
35@parametrize
36def test_method_create_with_all_params(self, client: OpenAI) -> None:
37run = client.beta.threads.runs.create(
38"string",
39assistant_id="string",
53bca49eStainless Bot2 years ago40additional_instructions="string",
baa9f07fRobert Craigie2 years ago41instructions="string",
42metadata={},
43model="string",
44tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
45)
46assert_matches_type(Run, run, path=["response"])
47
48@parametrize
49def test_raw_response_create(self, client: OpenAI) -> None:
50response = client.beta.threads.runs.with_raw_response.create(
51"string",
52assistant_id="string",
53)
86379b44Stainless Bot2 years ago54
55assert response.is_closed is True
baa9f07fRobert Craigie2 years ago56assert response.http_request.headers.get("X-Stainless-Lang") == "python"
57run = response.parse()
58assert_matches_type(Run, run, path=["response"])
59
86379b44Stainless Bot2 years ago60@parametrize
61def test_streaming_response_create(self, client: OpenAI) -> None:
62with client.beta.threads.runs.with_streaming_response.create(
63"string",
64assistant_id="string",
65) as response:
66assert not response.is_closed
67assert response.http_request.headers.get("X-Stainless-Lang") == "python"
68
69run = response.parse()
70assert_matches_type(Run, run, path=["response"])
71
72assert cast(Any, response.is_closed) is True
73
023a4e66Stainless Bot2 years ago74@parametrize
75def test_path_params_create(self, client: OpenAI) -> None:
76with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
77client.beta.threads.runs.with_raw_response.create(
78"",
79assistant_id="string",
80)
81
baa9f07fRobert Craigie2 years ago82@parametrize
83def test_method_retrieve(self, client: OpenAI) -> None:
84run = client.beta.threads.runs.retrieve(
85"string",
86thread_id="string",
87)
88assert_matches_type(Run, run, path=["response"])
89
90@parametrize
91def test_raw_response_retrieve(self, client: OpenAI) -> None:
92response = client.beta.threads.runs.with_raw_response.retrieve(
93"string",
94thread_id="string",
95)
86379b44Stainless Bot2 years ago96
97assert response.is_closed is True
baa9f07fRobert Craigie2 years ago98assert response.http_request.headers.get("X-Stainless-Lang") == "python"
99run = response.parse()
100assert_matches_type(Run, run, path=["response"])
101
86379b44Stainless Bot2 years ago102@parametrize
103def test_streaming_response_retrieve(self, client: OpenAI) -> None:
104with client.beta.threads.runs.with_streaming_response.retrieve(
105"string",
106thread_id="string",
107) as response:
108assert not response.is_closed
109assert response.http_request.headers.get("X-Stainless-Lang") == "python"
110
111run = response.parse()
112assert_matches_type(Run, run, path=["response"])
113
114assert cast(Any, response.is_closed) is True
115
023a4e66Stainless Bot2 years ago116@parametrize
117def test_path_params_retrieve(self, client: OpenAI) -> None:
118with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
119client.beta.threads.runs.with_raw_response.retrieve(
120"string",
121thread_id="",
122)
123
124with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
125client.beta.threads.runs.with_raw_response.retrieve(
126"",
127thread_id="string",
128)
129
baa9f07fRobert Craigie2 years ago130@parametrize
131def test_method_update(self, client: OpenAI) -> None:
132run = client.beta.threads.runs.update(
133"string",
134thread_id="string",
135)
136assert_matches_type(Run, run, path=["response"])
137
138@parametrize
139def test_method_update_with_all_params(self, client: OpenAI) -> None:
140run = client.beta.threads.runs.update(
141"string",
142thread_id="string",
143metadata={},
144)
145assert_matches_type(Run, run, path=["response"])
146
147@parametrize
148def test_raw_response_update(self, client: OpenAI) -> None:
149response = client.beta.threads.runs.with_raw_response.update(
150"string",
151thread_id="string",
152)
86379b44Stainless Bot2 years ago153
154assert response.is_closed is True
baa9f07fRobert Craigie2 years ago155assert response.http_request.headers.get("X-Stainless-Lang") == "python"
156run = response.parse()
157assert_matches_type(Run, run, path=["response"])
158
86379b44Stainless Bot2 years ago159@parametrize
160def test_streaming_response_update(self, client: OpenAI) -> None:
161with client.beta.threads.runs.with_streaming_response.update(
162"string",
163thread_id="string",
164) as response:
165assert not response.is_closed
166assert response.http_request.headers.get("X-Stainless-Lang") == "python"
167
168run = response.parse()
169assert_matches_type(Run, run, path=["response"])
170
171assert cast(Any, response.is_closed) is True
172
023a4e66Stainless Bot2 years ago173@parametrize
174def test_path_params_update(self, client: OpenAI) -> None:
175with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
176client.beta.threads.runs.with_raw_response.update(
177"string",
178thread_id="",
179)
180
181with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
182client.beta.threads.runs.with_raw_response.update(
183"",
184thread_id="string",
185)
186
baa9f07fRobert Craigie2 years ago187@parametrize
188def test_method_list(self, client: OpenAI) -> None:
189run = client.beta.threads.runs.list(
190"string",
191)
192assert_matches_type(SyncCursorPage[Run], run, path=["response"])
193
194@parametrize
195def test_method_list_with_all_params(self, client: OpenAI) -> None:
196run = client.beta.threads.runs.list(
197"string",
198after="string",
199before="string",
200limit=0,
201order="asc",
202)
203assert_matches_type(SyncCursorPage[Run], run, path=["response"])
204
205@parametrize
206def test_raw_response_list(self, client: OpenAI) -> None:
207response = client.beta.threads.runs.with_raw_response.list(
208"string",
209)
86379b44Stainless Bot2 years ago210
211assert response.is_closed is True
baa9f07fRobert Craigie2 years ago212assert response.http_request.headers.get("X-Stainless-Lang") == "python"
213run = response.parse()
214assert_matches_type(SyncCursorPage[Run], run, path=["response"])
215
86379b44Stainless Bot2 years ago216@parametrize
217def test_streaming_response_list(self, client: OpenAI) -> None:
218with client.beta.threads.runs.with_streaming_response.list(
219"string",
220) as response:
221assert not response.is_closed
222assert response.http_request.headers.get("X-Stainless-Lang") == "python"
223
224run = response.parse()
225assert_matches_type(SyncCursorPage[Run], run, path=["response"])
226
227assert cast(Any, response.is_closed) is True
228
023a4e66Stainless Bot2 years ago229@parametrize
230def test_path_params_list(self, client: OpenAI) -> None:
231with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
232client.beta.threads.runs.with_raw_response.list(
233"",
234)
235
baa9f07fRobert Craigie2 years ago236@parametrize
237def test_method_cancel(self, client: OpenAI) -> None:
238run = client.beta.threads.runs.cancel(
239"string",
240thread_id="string",
241)
242assert_matches_type(Run, run, path=["response"])
243
244@parametrize
245def test_raw_response_cancel(self, client: OpenAI) -> None:
246response = client.beta.threads.runs.with_raw_response.cancel(
247"string",
248thread_id="string",
249)
86379b44Stainless Bot2 years ago250
251assert response.is_closed is True
baa9f07fRobert Craigie2 years ago252assert response.http_request.headers.get("X-Stainless-Lang") == "python"
253run = response.parse()
254assert_matches_type(Run, run, path=["response"])
255
86379b44Stainless Bot2 years ago256@parametrize
257def test_streaming_response_cancel(self, client: OpenAI) -> None:
258with client.beta.threads.runs.with_streaming_response.cancel(
259"string",
260thread_id="string",
261) as response:
262assert not response.is_closed
263assert response.http_request.headers.get("X-Stainless-Lang") == "python"
264
265run = response.parse()
266assert_matches_type(Run, run, path=["response"])
267
268assert cast(Any, response.is_closed) is True
269
023a4e66Stainless Bot2 years ago270@parametrize
271def test_path_params_cancel(self, client: OpenAI) -> None:
272with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
273client.beta.threads.runs.with_raw_response.cancel(
274"string",
275thread_id="",
276)
277
278with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
279client.beta.threads.runs.with_raw_response.cancel(
280"",
281thread_id="string",
282)
283
baa9f07fRobert Craigie2 years ago284@parametrize
285def test_method_submit_tool_outputs(self, client: OpenAI) -> None:
286run = client.beta.threads.runs.submit_tool_outputs(
287"string",
288thread_id="string",
289tool_outputs=[{}, {}, {}],
290)
291assert_matches_type(Run, run, path=["response"])
292
293@parametrize
294def test_raw_response_submit_tool_outputs(self, client: OpenAI) -> None:
295response = client.beta.threads.runs.with_raw_response.submit_tool_outputs(
296"string",
297thread_id="string",
298tool_outputs=[{}, {}, {}],
299)
86379b44Stainless Bot2 years ago300
301assert response.is_closed is True
baa9f07fRobert Craigie2 years ago302assert response.http_request.headers.get("X-Stainless-Lang") == "python"
303run = response.parse()
304assert_matches_type(Run, run, path=["response"])
305
86379b44Stainless Bot2 years ago306@parametrize
307def test_streaming_response_submit_tool_outputs(self, client: OpenAI) -> None:
308with client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
309"string",
310thread_id="string",
311tool_outputs=[{}, {}, {}],
312) as response:
313assert not response.is_closed
314assert response.http_request.headers.get("X-Stainless-Lang") == "python"
315
316run = response.parse()
317assert_matches_type(Run, run, path=["response"])
318
319assert cast(Any, response.is_closed) is True
320
023a4e66Stainless Bot2 years ago321@parametrize
322def test_path_params_submit_tool_outputs(self, client: OpenAI) -> None:
323with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
324client.beta.threads.runs.with_raw_response.submit_tool_outputs(
325"string",
326thread_id="",
327tool_outputs=[{}, {}, {}],
328)
329
330with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
331client.beta.threads.runs.with_raw_response.submit_tool_outputs(
332"",
333thread_id="string",
334tool_outputs=[{}, {}, {}],
335)
336
baa9f07fRobert Craigie2 years ago337
338class TestAsyncRuns:
339strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
340loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
341parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
342
343@parametrize
344async def test_method_create(self, client: AsyncOpenAI) -> None:
345run = await client.beta.threads.runs.create(
346"string",
347assistant_id="string",
348)
349assert_matches_type(Run, run, path=["response"])
350
351@parametrize
352async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None:
353run = await client.beta.threads.runs.create(
354"string",
355assistant_id="string",
53bca49eStainless Bot2 years ago356additional_instructions="string",
baa9f07fRobert Craigie2 years ago357instructions="string",
358metadata={},
359model="string",
360tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
361)
362assert_matches_type(Run, run, path=["response"])
363
364@parametrize
365async def test_raw_response_create(self, client: AsyncOpenAI) -> None:
366response = await client.beta.threads.runs.with_raw_response.create(
367"string",
368assistant_id="string",
369)
86379b44Stainless Bot2 years ago370
371assert response.is_closed is True
baa9f07fRobert Craigie2 years ago372assert response.http_request.headers.get("X-Stainless-Lang") == "python"
373run = response.parse()
374assert_matches_type(Run, run, path=["response"])
375
86379b44Stainless Bot2 years ago376@parametrize
377async def test_streaming_response_create(self, client: AsyncOpenAI) -> None:
378async with client.beta.threads.runs.with_streaming_response.create(
379"string",
380assistant_id="string",
381) as response:
382assert not response.is_closed
383assert response.http_request.headers.get("X-Stainless-Lang") == "python"
384
385run = await response.parse()
386assert_matches_type(Run, run, path=["response"])
387
388assert cast(Any, response.is_closed) is True
389
023a4e66Stainless Bot2 years ago390@parametrize
391async def test_path_params_create(self, client: AsyncOpenAI) -> None:
392with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
393await client.beta.threads.runs.with_raw_response.create(
394"",
395assistant_id="string",
396)
397
baa9f07fRobert Craigie2 years ago398@parametrize
399async def test_method_retrieve(self, client: AsyncOpenAI) -> None:
400run = await client.beta.threads.runs.retrieve(
401"string",
402thread_id="string",
403)
404assert_matches_type(Run, run, path=["response"])
405
406@parametrize
407async def test_raw_response_retrieve(self, client: AsyncOpenAI) -> None:
408response = await client.beta.threads.runs.with_raw_response.retrieve(
409"string",
410thread_id="string",
411)
86379b44Stainless Bot2 years ago412
413assert response.is_closed is True
baa9f07fRobert Craigie2 years ago414assert response.http_request.headers.get("X-Stainless-Lang") == "python"
415run = response.parse()
416assert_matches_type(Run, run, path=["response"])
417
86379b44Stainless Bot2 years ago418@parametrize
419async def test_streaming_response_retrieve(self, client: AsyncOpenAI) -> None:
420async with client.beta.threads.runs.with_streaming_response.retrieve(
421"string",
422thread_id="string",
423) as response:
424assert not response.is_closed
425assert response.http_request.headers.get("X-Stainless-Lang") == "python"
426
427run = await response.parse()
428assert_matches_type(Run, run, path=["response"])
429
430assert cast(Any, response.is_closed) is True
431
023a4e66Stainless Bot2 years ago432@parametrize
433async def test_path_params_retrieve(self, client: AsyncOpenAI) -> None:
434with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
435await client.beta.threads.runs.with_raw_response.retrieve(
436"string",
437thread_id="",
438)
439
440with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
441await client.beta.threads.runs.with_raw_response.retrieve(
442"",
443thread_id="string",
444)
445
baa9f07fRobert Craigie2 years ago446@parametrize
447async def test_method_update(self, client: AsyncOpenAI) -> None:
448run = await client.beta.threads.runs.update(
449"string",
450thread_id="string",
451)
452assert_matches_type(Run, run, path=["response"])
453
454@parametrize
455async def test_method_update_with_all_params(self, client: AsyncOpenAI) -> None:
456run = await client.beta.threads.runs.update(
457"string",
458thread_id="string",
459metadata={},
460)
461assert_matches_type(Run, run, path=["response"])
462
463@parametrize
464async def test_raw_response_update(self, client: AsyncOpenAI) -> None:
465response = await client.beta.threads.runs.with_raw_response.update(
466"string",
467thread_id="string",
468)
86379b44Stainless Bot2 years ago469
470assert response.is_closed is True
baa9f07fRobert Craigie2 years ago471assert response.http_request.headers.get("X-Stainless-Lang") == "python"
472run = response.parse()
473assert_matches_type(Run, run, path=["response"])
474
86379b44Stainless Bot2 years ago475@parametrize
476async def test_streaming_response_update(self, client: AsyncOpenAI) -> None:
477async with client.beta.threads.runs.with_streaming_response.update(
478"string",
479thread_id="string",
480) as response:
481assert not response.is_closed
482assert response.http_request.headers.get("X-Stainless-Lang") == "python"
483
484run = await response.parse()
485assert_matches_type(Run, run, path=["response"])
486
487assert cast(Any, response.is_closed) is True
488
023a4e66Stainless Bot2 years ago489@parametrize
490async def test_path_params_update(self, client: AsyncOpenAI) -> None:
491with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
492await client.beta.threads.runs.with_raw_response.update(
493"string",
494thread_id="",
495)
496
497with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
498await client.beta.threads.runs.with_raw_response.update(
499"",
500thread_id="string",
501)
502
baa9f07fRobert Craigie2 years ago503@parametrize
504async def test_method_list(self, client: AsyncOpenAI) -> None:
505run = await client.beta.threads.runs.list(
506"string",
507)
508assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
509
510@parametrize
511async def test_method_list_with_all_params(self, client: AsyncOpenAI) -> None:
512run = await client.beta.threads.runs.list(
513"string",
514after="string",
515before="string",
516limit=0,
517order="asc",
518)
519assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
520
521@parametrize
522async def test_raw_response_list(self, client: AsyncOpenAI) -> None:
523response = await client.beta.threads.runs.with_raw_response.list(
524"string",
525)
86379b44Stainless Bot2 years ago526
527assert response.is_closed is True
baa9f07fRobert Craigie2 years ago528assert response.http_request.headers.get("X-Stainless-Lang") == "python"
529run = response.parse()
530assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
531
86379b44Stainless Bot2 years ago532@parametrize
533async def test_streaming_response_list(self, client: AsyncOpenAI) -> None:
534async with client.beta.threads.runs.with_streaming_response.list(
535"string",
536) as response:
537assert not response.is_closed
538assert response.http_request.headers.get("X-Stainless-Lang") == "python"
539
540run = await response.parse()
541assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
542
543assert cast(Any, response.is_closed) is True
544
023a4e66Stainless Bot2 years ago545@parametrize
546async def test_path_params_list(self, client: AsyncOpenAI) -> None:
547with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
548await client.beta.threads.runs.with_raw_response.list(
549"",
550)
551
baa9f07fRobert Craigie2 years ago552@parametrize
553async def test_method_cancel(self, client: AsyncOpenAI) -> None:
554run = await client.beta.threads.runs.cancel(
555"string",
556thread_id="string",
557)
558assert_matches_type(Run, run, path=["response"])
559
560@parametrize
561async def test_raw_response_cancel(self, client: AsyncOpenAI) -> None:
562response = await client.beta.threads.runs.with_raw_response.cancel(
563"string",
564thread_id="string",
565)
86379b44Stainless Bot2 years ago566
567assert response.is_closed is True
baa9f07fRobert Craigie2 years ago568assert response.http_request.headers.get("X-Stainless-Lang") == "python"
569run = response.parse()
570assert_matches_type(Run, run, path=["response"])
571
86379b44Stainless Bot2 years ago572@parametrize
573async def test_streaming_response_cancel(self, client: AsyncOpenAI) -> None:
574async with client.beta.threads.runs.with_streaming_response.cancel(
575"string",
576thread_id="string",
577) as response:
578assert not response.is_closed
579assert response.http_request.headers.get("X-Stainless-Lang") == "python"
580
581run = await response.parse()
582assert_matches_type(Run, run, path=["response"])
583
584assert cast(Any, response.is_closed) is True
585
023a4e66Stainless Bot2 years ago586@parametrize
587async def test_path_params_cancel(self, client: AsyncOpenAI) -> None:
588with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
589await client.beta.threads.runs.with_raw_response.cancel(
590"string",
591thread_id="",
592)
593
594with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
595await client.beta.threads.runs.with_raw_response.cancel(
596"",
597thread_id="string",
598)
599
baa9f07fRobert Craigie2 years ago600@parametrize
601async def test_method_submit_tool_outputs(self, client: AsyncOpenAI) -> None:
602run = await client.beta.threads.runs.submit_tool_outputs(
603"string",
604thread_id="string",
605tool_outputs=[{}, {}, {}],
606)
607assert_matches_type(Run, run, path=["response"])
608
609@parametrize
610async def test_raw_response_submit_tool_outputs(self, client: AsyncOpenAI) -> None:
611response = await client.beta.threads.runs.with_raw_response.submit_tool_outputs(
612"string",
613thread_id="string",
614tool_outputs=[{}, {}, {}],
615)
86379b44Stainless Bot2 years ago616
617assert response.is_closed is True
baa9f07fRobert Craigie2 years ago618assert response.http_request.headers.get("X-Stainless-Lang") == "python"
619run = response.parse()
620assert_matches_type(Run, run, path=["response"])
86379b44Stainless Bot2 years ago621
622@parametrize
623async def test_streaming_response_submit_tool_outputs(self, client: AsyncOpenAI) -> None:
624async with client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
625"string",
626thread_id="string",
627tool_outputs=[{}, {}, {}],
628) as response:
629assert not response.is_closed
630assert response.http_request.headers.get("X-Stainless-Lang") == "python"
631
632run = await response.parse()
633assert_matches_type(Run, run, path=["response"])
634
635assert cast(Any, response.is_closed) is True
023a4e66Stainless Bot2 years ago636
637@parametrize
638async def test_path_params_submit_tool_outputs(self, client: AsyncOpenAI) -> None:
639with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
640await client.beta.threads.runs.with_raw_response.submit_tool_outputs(
641"string",
642thread_id="",
643tool_outputs=[{}, {}, {}],
644)
645
646with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
647await client.beta.threads.runs.with_raw_response.submit_tool_outputs(
648"",
649thread_id="string",
650tool_outputs=[{}, {}, {}],
651)