openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.65.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/test_runs.py

1015lines · modeblame

5cfb125aStainless Bot2 years ago1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
baa9f07fRobert Craigie2 years ago2
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.pagination import SyncCursorPage, AsyncCursorPage
4a0f0fa0Stainless Bot2 years ago13from openai.types.beta.threads import (
14Run,
15)
baa9f07fRobert Craigie2 years ago16
595f3b36Stainless Bot2 years ago17# pyright: reportDeprecated=false
18
baa9f07fRobert Craigie2 years ago19base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
20
21
22class TestRuns:
98d779fbStainless Bot2 years ago23parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
baa9f07fRobert Craigie2 years ago24
25@parametrize
5429f696Stainless Bot2 years ago26def test_method_create_overload_1(self, client: OpenAI) -> None:
baa9f07fRobert Craigie2 years ago27run = client.beta.threads.runs.create(
28"string",
29assistant_id="string",
30)
31assert_matches_type(Run, run, path=["response"])
32
33@parametrize
5429f696Stainless Bot2 years ago34def test_method_create_with_all_params_overload_1(self, client: OpenAI) -> None:
baa9f07fRobert Craigie2 years ago35run = client.beta.threads.runs.create(
5d3111a8Stainless Bot1 years ago36thread_id="thread_id",
37assistant_id="assistant_id",
38include=["step_details.tool_calls[*].file_search.results[*].content"],
39additional_instructions="additional_instructions",
e2d65bf7Stainless Bot2 years ago40additional_messages=[
41{
79a0b401Stainless Bot2 years ago42"content": "string",
092a8df7Stainless Bot1 years ago43"role": "user",
5b20698dStainless Bot2 years ago44"attachments": [
45{
dd19d4f9Stainless Bot1 years ago46"file_id": "file_id",
47"tools": [{"type": "code_interpreter"}],
48}
5b20698dStainless Bot2 years ago49],
fdd52476stainless-app[bot]1 years ago50"metadata": {"foo": "string"},
dd19d4f9Stainless Bot1 years ago51}
e2d65bf7Stainless Bot2 years ago52],
baa9f07fRobert Craigie2 years ago53instructions="string",
f5247e30Stainless Bot2 years ago54max_completion_tokens=256,
55max_prompt_tokens=256,
fdd52476stainless-app[bot]1 years ago56metadata={"foo": "string"},
bf1ca86cRobert Craigie1 years ago57model="gpt-4o",
7399ffc8Stainless Bot2 years ago58parallel_tool_calls=True,
8640fd83stainless-app[bot]1 years ago59reasoning_effort="low",
bf1ca86cRobert Craigie1 years ago60response_format="auto",
5429f696Stainless Bot2 years ago61stream=False,
27a4626aStainless Bot2 years ago62temperature=1,
f5247e30Stainless Bot2 years ago63tool_choice="none",
dd19d4f9Stainless Bot1 years ago64tools=[{"type": "code_interpreter"}],
5b20698dStainless Bot2 years ago65top_p=1,
f5247e30Stainless Bot2 years ago66truncation_strategy={
67"type": "auto",
68"last_messages": 1,
69},
baa9f07fRobert Craigie2 years ago70)
71assert_matches_type(Run, run, path=["response"])
72
73@parametrize
5429f696Stainless Bot2 years ago74def test_raw_response_create_overload_1(self, client: OpenAI) -> None:
baa9f07fRobert Craigie2 years ago75response = client.beta.threads.runs.with_raw_response.create(
76"string",
77assistant_id="string",
78)
86379b44Stainless Bot2 years ago79
80assert response.is_closed is True
baa9f07fRobert Craigie2 years ago81assert response.http_request.headers.get("X-Stainless-Lang") == "python"
82run = response.parse()
83assert_matches_type(Run, run, path=["response"])
84
86379b44Stainless Bot2 years ago85@parametrize
5429f696Stainless Bot2 years ago86def test_streaming_response_create_overload_1(self, client: OpenAI) -> None:
86379b44Stainless Bot2 years ago87with client.beta.threads.runs.with_streaming_response.create(
88"string",
89assistant_id="string",
90) as response:
91assert not response.is_closed
92assert response.http_request.headers.get("X-Stainless-Lang") == "python"
93
94run = response.parse()
95assert_matches_type(Run, run, path=["response"])
96
97assert cast(Any, response.is_closed) is True
98
023a4e66Stainless Bot2 years ago99@parametrize
5429f696Stainless Bot2 years ago100def test_path_params_create_overload_1(self, client: OpenAI) -> None:
023a4e66Stainless Bot2 years ago101with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
102client.beta.threads.runs.with_raw_response.create(
103"",
104assistant_id="string",
105)
106
5429f696Stainless Bot2 years ago107@parametrize
108def test_method_create_overload_2(self, client: OpenAI) -> None:
109run_stream = client.beta.threads.runs.create(
110"string",
111assistant_id="string",
112stream=True,
113)
114run_stream.response.close()
115
116@parametrize
117def test_method_create_with_all_params_overload_2(self, client: OpenAI) -> None:
118run_stream = client.beta.threads.runs.create(
119"string",
120assistant_id="string",
121stream=True,
5d3111a8Stainless Bot1 years ago122include=["step_details.tool_calls[*].file_search.results[*].content"],
123additional_instructions="additional_instructions",
e2d65bf7Stainless Bot2 years ago124additional_messages=[
125{
79a0b401Stainless Bot2 years ago126"content": "string",
092a8df7Stainless Bot1 years ago127"role": "user",
5b20698dStainless Bot2 years ago128"attachments": [
129{
dd19d4f9Stainless Bot1 years ago130"file_id": "file_id",
131"tools": [{"type": "code_interpreter"}],
132}
5b20698dStainless Bot2 years ago133],
fdd52476stainless-app[bot]1 years ago134"metadata": {"foo": "string"},
dd19d4f9Stainless Bot1 years ago135}
e2d65bf7Stainless Bot2 years ago136],
5429f696Stainless Bot2 years ago137instructions="string",
f5247e30Stainless Bot2 years ago138max_completion_tokens=256,
139max_prompt_tokens=256,
fdd52476stainless-app[bot]1 years ago140metadata={"foo": "string"},
bf1ca86cRobert Craigie1 years ago141model="gpt-4o",
7399ffc8Stainless Bot2 years ago142parallel_tool_calls=True,
8640fd83stainless-app[bot]1 years ago143reasoning_effort="low",
bf1ca86cRobert Craigie1 years ago144response_format="auto",
27a4626aStainless Bot2 years ago145temperature=1,
f5247e30Stainless Bot2 years ago146tool_choice="none",
dd19d4f9Stainless Bot1 years ago147tools=[{"type": "code_interpreter"}],
5b20698dStainless Bot2 years ago148top_p=1,
f5247e30Stainless Bot2 years ago149truncation_strategy={
150"type": "auto",
151"last_messages": 1,
152},
5429f696Stainless Bot2 years ago153)
154run_stream.response.close()
155
156@parametrize
157def test_raw_response_create_overload_2(self, client: OpenAI) -> None:
158response = client.beta.threads.runs.with_raw_response.create(
159"string",
160assistant_id="string",
161stream=True,
162)
163
164assert response.http_request.headers.get("X-Stainless-Lang") == "python"
165stream = response.parse()
166stream.close()
167
168@parametrize
169def test_streaming_response_create_overload_2(self, client: OpenAI) -> None:
170with client.beta.threads.runs.with_streaming_response.create(
171"string",
172assistant_id="string",
173stream=True,
174) as response:
175assert not response.is_closed
176assert response.http_request.headers.get("X-Stainless-Lang") == "python"
177
178stream = response.parse()
179stream.close()
180
181assert cast(Any, response.is_closed) is True
182
183@parametrize
184def test_path_params_create_overload_2(self, client: OpenAI) -> None:
185with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
186client.beta.threads.runs.with_raw_response.create(
187"",
188assistant_id="string",
189stream=True,
190)
191
baa9f07fRobert Craigie2 years ago192@parametrize
193def test_method_retrieve(self, client: OpenAI) -> None:
194run = client.beta.threads.runs.retrieve(
195"string",
196thread_id="string",
197)
198assert_matches_type(Run, run, path=["response"])
199
200@parametrize
201def test_raw_response_retrieve(self, client: OpenAI) -> None:
202response = client.beta.threads.runs.with_raw_response.retrieve(
203"string",
204thread_id="string",
205)
86379b44Stainless Bot2 years ago206
207assert response.is_closed is True
baa9f07fRobert Craigie2 years ago208assert response.http_request.headers.get("X-Stainless-Lang") == "python"
209run = response.parse()
210assert_matches_type(Run, run, path=["response"])
211
86379b44Stainless Bot2 years ago212@parametrize
213def test_streaming_response_retrieve(self, client: OpenAI) -> None:
214with client.beta.threads.runs.with_streaming_response.retrieve(
215"string",
216thread_id="string",
217) as response:
218assert not response.is_closed
219assert response.http_request.headers.get("X-Stainless-Lang") == "python"
220
221run = response.parse()
222assert_matches_type(Run, run, path=["response"])
223
224assert cast(Any, response.is_closed) is True
225
023a4e66Stainless Bot2 years ago226@parametrize
227def test_path_params_retrieve(self, client: OpenAI) -> None:
228with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
229client.beta.threads.runs.with_raw_response.retrieve(
230"string",
231thread_id="",
232)
233
234with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
235client.beta.threads.runs.with_raw_response.retrieve(
236"",
237thread_id="string",
238)
239
baa9f07fRobert Craigie2 years ago240@parametrize
241def test_method_update(self, client: OpenAI) -> None:
242run = client.beta.threads.runs.update(
243"string",
244thread_id="string",
245)
246assert_matches_type(Run, run, path=["response"])
247
248@parametrize
249def test_method_update_with_all_params(self, client: OpenAI) -> None:
250run = client.beta.threads.runs.update(
fdd52476stainless-app[bot]1 years ago251run_id="run_id",
252thread_id="thread_id",
253metadata={"foo": "string"},
baa9f07fRobert Craigie2 years ago254)
255assert_matches_type(Run, run, path=["response"])
256
257@parametrize
258def test_raw_response_update(self, client: OpenAI) -> None:
259response = client.beta.threads.runs.with_raw_response.update(
260"string",
261thread_id="string",
262)
86379b44Stainless Bot2 years ago263
264assert response.is_closed is True
baa9f07fRobert Craigie2 years ago265assert response.http_request.headers.get("X-Stainless-Lang") == "python"
266run = response.parse()
267assert_matches_type(Run, run, path=["response"])
268
86379b44Stainless Bot2 years ago269@parametrize
270def test_streaming_response_update(self, client: OpenAI) -> None:
271with client.beta.threads.runs.with_streaming_response.update(
272"string",
273thread_id="string",
274) as response:
275assert not response.is_closed
276assert response.http_request.headers.get("X-Stainless-Lang") == "python"
277
278run = response.parse()
279assert_matches_type(Run, run, path=["response"])
280
281assert cast(Any, response.is_closed) is True
282
023a4e66Stainless Bot2 years ago283@parametrize
284def test_path_params_update(self, client: OpenAI) -> None:
285with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
286client.beta.threads.runs.with_raw_response.update(
287"string",
288thread_id="",
289)
290
291with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
292client.beta.threads.runs.with_raw_response.update(
293"",
294thread_id="string",
295)
296
baa9f07fRobert Craigie2 years ago297@parametrize
298def test_method_list(self, client: OpenAI) -> None:
299run = client.beta.threads.runs.list(
300"string",
301)
302assert_matches_type(SyncCursorPage[Run], run, path=["response"])
303
304@parametrize
305def test_method_list_with_all_params(self, client: OpenAI) -> None:
306run = client.beta.threads.runs.list(
307"string",
308after="string",
309before="string",
310limit=0,
311order="asc",
312)
313assert_matches_type(SyncCursorPage[Run], run, path=["response"])
314
315@parametrize
316def test_raw_response_list(self, client: OpenAI) -> None:
317response = client.beta.threads.runs.with_raw_response.list(
318"string",
319)
86379b44Stainless Bot2 years ago320
321assert response.is_closed is True
baa9f07fRobert Craigie2 years ago322assert response.http_request.headers.get("X-Stainless-Lang") == "python"
323run = response.parse()
324assert_matches_type(SyncCursorPage[Run], run, path=["response"])
325
86379b44Stainless Bot2 years ago326@parametrize
327def test_streaming_response_list(self, client: OpenAI) -> None:
328with client.beta.threads.runs.with_streaming_response.list(
329"string",
330) as response:
331assert not response.is_closed
332assert response.http_request.headers.get("X-Stainless-Lang") == "python"
333
334run = response.parse()
335assert_matches_type(SyncCursorPage[Run], run, path=["response"])
336
337assert cast(Any, response.is_closed) is True
338
023a4e66Stainless Bot2 years ago339@parametrize
340def test_path_params_list(self, client: OpenAI) -> None:
341with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
342client.beta.threads.runs.with_raw_response.list(
343"",
344)
345
baa9f07fRobert Craigie2 years ago346@parametrize
347def test_method_cancel(self, client: OpenAI) -> None:
348run = client.beta.threads.runs.cancel(
349"string",
350thread_id="string",
351)
352assert_matches_type(Run, run, path=["response"])
353
354@parametrize
355def test_raw_response_cancel(self, client: OpenAI) -> None:
356response = client.beta.threads.runs.with_raw_response.cancel(
357"string",
358thread_id="string",
359)
86379b44Stainless Bot2 years ago360
361assert response.is_closed is True
baa9f07fRobert Craigie2 years ago362assert response.http_request.headers.get("X-Stainless-Lang") == "python"
363run = response.parse()
364assert_matches_type(Run, run, path=["response"])
365
86379b44Stainless Bot2 years ago366@parametrize
367def test_streaming_response_cancel(self, client: OpenAI) -> None:
368with client.beta.threads.runs.with_streaming_response.cancel(
369"string",
370thread_id="string",
371) as response:
372assert not response.is_closed
373assert response.http_request.headers.get("X-Stainless-Lang") == "python"
374
375run = response.parse()
376assert_matches_type(Run, run, path=["response"])
377
378assert cast(Any, response.is_closed) is True
379
023a4e66Stainless Bot2 years ago380@parametrize
381def test_path_params_cancel(self, client: OpenAI) -> None:
382with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
383client.beta.threads.runs.with_raw_response.cancel(
384"string",
385thread_id="",
386)
387
388with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
389client.beta.threads.runs.with_raw_response.cancel(
390"",
391thread_id="string",
392)
393
baa9f07fRobert Craigie2 years ago394@parametrize
5429f696Stainless Bot2 years ago395def test_method_submit_tool_outputs_overload_1(self, client: OpenAI) -> None:
baa9f07fRobert Craigie2 years ago396run = client.beta.threads.runs.submit_tool_outputs(
dd19d4f9Stainless Bot1 years ago397run_id="run_id",
398thread_id="thread_id",
399tool_outputs=[{}],
baa9f07fRobert Craigie2 years ago400)
401assert_matches_type(Run, run, path=["response"])
402
403@parametrize
5429f696Stainless Bot2 years ago404def test_method_submit_tool_outputs_with_all_params_overload_1(self, client: OpenAI) -> None:
405run = client.beta.threads.runs.submit_tool_outputs(
406"string",
407thread_id="string",
408tool_outputs=[
409{
092a8df7Stainless Bot1 years ago410"output": "output",
411"tool_call_id": "tool_call_id",
dd19d4f9Stainless Bot1 years ago412}
5429f696Stainless Bot2 years ago413],
414stream=False,
415)
416assert_matches_type(Run, run, path=["response"])
417
418@parametrize
419def test_raw_response_submit_tool_outputs_overload_1(self, client: OpenAI) -> None:
baa9f07fRobert Craigie2 years ago420response = client.beta.threads.runs.with_raw_response.submit_tool_outputs(
dd19d4f9Stainless Bot1 years ago421run_id="run_id",
422thread_id="thread_id",
423tool_outputs=[{}],
baa9f07fRobert Craigie2 years ago424)
86379b44Stainless Bot2 years ago425
426assert response.is_closed is True
baa9f07fRobert Craigie2 years ago427assert response.http_request.headers.get("X-Stainless-Lang") == "python"
428run = response.parse()
429assert_matches_type(Run, run, path=["response"])
430
86379b44Stainless Bot2 years ago431@parametrize
5429f696Stainless Bot2 years ago432def test_streaming_response_submit_tool_outputs_overload_1(self, client: OpenAI) -> None:
86379b44Stainless Bot2 years ago433with client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
dd19d4f9Stainless Bot1 years ago434run_id="run_id",
435thread_id="thread_id",
436tool_outputs=[{}],
86379b44Stainless Bot2 years ago437) as response:
438assert not response.is_closed
439assert response.http_request.headers.get("X-Stainless-Lang") == "python"
440
441run = response.parse()
442assert_matches_type(Run, run, path=["response"])
443
444assert cast(Any, response.is_closed) is True
445
023a4e66Stainless Bot2 years ago446@parametrize
5429f696Stainless Bot2 years ago447def test_path_params_submit_tool_outputs_overload_1(self, client: OpenAI) -> None:
448with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
449client.beta.threads.runs.with_raw_response.submit_tool_outputs(
450"string",
451thread_id="",
dd19d4f9Stainless Bot1 years ago452tool_outputs=[{}],
5429f696Stainless Bot2 years ago453)
454
455with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
456client.beta.threads.runs.with_raw_response.submit_tool_outputs(
dd19d4f9Stainless Bot1 years ago457run_id="",
458thread_id="thread_id",
459tool_outputs=[{}],
5429f696Stainless Bot2 years ago460)
461
462@parametrize
463def test_method_submit_tool_outputs_overload_2(self, client: OpenAI) -> None:
464run_stream = client.beta.threads.runs.submit_tool_outputs(
465"string",
466thread_id="string",
467stream=True,
dd19d4f9Stainless Bot1 years ago468tool_outputs=[{}],
5429f696Stainless Bot2 years ago469)
470run_stream.response.close()
471
472@parametrize
473def test_raw_response_submit_tool_outputs_overload_2(self, client: OpenAI) -> None:
474response = client.beta.threads.runs.with_raw_response.submit_tool_outputs(
475"string",
476thread_id="string",
477stream=True,
dd19d4f9Stainless Bot1 years ago478tool_outputs=[{}],
5429f696Stainless Bot2 years ago479)
480
481assert response.http_request.headers.get("X-Stainless-Lang") == "python"
482stream = response.parse()
483stream.close()
484
485@parametrize
486def test_streaming_response_submit_tool_outputs_overload_2(self, client: OpenAI) -> None:
487with client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
488"string",
489thread_id="string",
490stream=True,
dd19d4f9Stainless Bot1 years ago491tool_outputs=[{}],
5429f696Stainless Bot2 years ago492) as response:
493assert not response.is_closed
494assert response.http_request.headers.get("X-Stainless-Lang") == "python"
495
496stream = response.parse()
497stream.close()
498
499assert cast(Any, response.is_closed) is True
500
501@parametrize
502def test_path_params_submit_tool_outputs_overload_2(self, client: OpenAI) -> None:
023a4e66Stainless Bot2 years ago503with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
504client.beta.threads.runs.with_raw_response.submit_tool_outputs(
505"string",
506thread_id="",
5429f696Stainless Bot2 years ago507stream=True,
dd19d4f9Stainless Bot1 years ago508tool_outputs=[{}],
023a4e66Stainless Bot2 years ago509)
510
511with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
512client.beta.threads.runs.with_raw_response.submit_tool_outputs(
513"",
514thread_id="string",
5429f696Stainless Bot2 years ago515stream=True,
dd19d4f9Stainless Bot1 years ago516tool_outputs=[{}],
023a4e66Stainless Bot2 years ago517)
518
baa9f07fRobert Craigie2 years ago519
520class TestAsyncRuns:
98d779fbStainless Bot2 years ago521parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
baa9f07fRobert Craigie2 years ago522
523@parametrize
5429f696Stainless Bot2 years ago524async def test_method_create_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago525run = await async_client.beta.threads.runs.create(
baa9f07fRobert Craigie2 years ago526"string",
527assistant_id="string",
528)
529assert_matches_type(Run, run, path=["response"])
530
531@parametrize
5429f696Stainless Bot2 years ago532async def test_method_create_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago533run = await async_client.beta.threads.runs.create(
5d3111a8Stainless Bot1 years ago534thread_id="thread_id",
535assistant_id="assistant_id",
536include=["step_details.tool_calls[*].file_search.results[*].content"],
537additional_instructions="additional_instructions",
e2d65bf7Stainless Bot2 years ago538additional_messages=[
539{
79a0b401Stainless Bot2 years ago540"content": "string",
092a8df7Stainless Bot1 years ago541"role": "user",
5b20698dStainless Bot2 years ago542"attachments": [
543{
dd19d4f9Stainless Bot1 years ago544"file_id": "file_id",
545"tools": [{"type": "code_interpreter"}],
546}
5b20698dStainless Bot2 years ago547],
fdd52476stainless-app[bot]1 years ago548"metadata": {"foo": "string"},
dd19d4f9Stainless Bot1 years ago549}
e2d65bf7Stainless Bot2 years ago550],
baa9f07fRobert Craigie2 years ago551instructions="string",
f5247e30Stainless Bot2 years ago552max_completion_tokens=256,
553max_prompt_tokens=256,
fdd52476stainless-app[bot]1 years ago554metadata={"foo": "string"},
bf1ca86cRobert Craigie1 years ago555model="gpt-4o",
7399ffc8Stainless Bot2 years ago556parallel_tool_calls=True,
8640fd83stainless-app[bot]1 years ago557reasoning_effort="low",
bf1ca86cRobert Craigie1 years ago558response_format="auto",
5429f696Stainless Bot2 years ago559stream=False,
27a4626aStainless Bot2 years ago560temperature=1,
f5247e30Stainless Bot2 years ago561tool_choice="none",
dd19d4f9Stainless Bot1 years ago562tools=[{"type": "code_interpreter"}],
5b20698dStainless Bot2 years ago563top_p=1,
f5247e30Stainless Bot2 years ago564truncation_strategy={
565"type": "auto",
566"last_messages": 1,
567},
baa9f07fRobert Craigie2 years ago568)
569assert_matches_type(Run, run, path=["response"])
570
571@parametrize
5429f696Stainless Bot2 years ago572async def test_raw_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago573response = await async_client.beta.threads.runs.with_raw_response.create(
baa9f07fRobert Craigie2 years ago574"string",
575assistant_id="string",
576)
86379b44Stainless Bot2 years ago577
578assert response.is_closed is True
baa9f07fRobert Craigie2 years ago579assert response.http_request.headers.get("X-Stainless-Lang") == "python"
580run = response.parse()
581assert_matches_type(Run, run, path=["response"])
582
86379b44Stainless Bot2 years ago583@parametrize
5429f696Stainless Bot2 years ago584async def test_streaming_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago585async with async_client.beta.threads.runs.with_streaming_response.create(
86379b44Stainless Bot2 years ago586"string",
587assistant_id="string",
588) as response:
589assert not response.is_closed
590assert response.http_request.headers.get("X-Stainless-Lang") == "python"
591
592run = await response.parse()
593assert_matches_type(Run, run, path=["response"])
594
595assert cast(Any, response.is_closed) is True
596
023a4e66Stainless Bot2 years ago597@parametrize
5429f696Stainless Bot2 years ago598async def test_path_params_create_overload_1(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago599with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago600await async_client.beta.threads.runs.with_raw_response.create(
023a4e66Stainless Bot2 years ago601"",
602assistant_id="string",
603)
604
5429f696Stainless Bot2 years ago605@parametrize
606async def test_method_create_overload_2(self, async_client: AsyncOpenAI) -> None:
607run_stream = await async_client.beta.threads.runs.create(
608"string",
609assistant_id="string",
610stream=True,
611)
612await run_stream.response.aclose()
613
614@parametrize
615async def test_method_create_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None:
616run_stream = await async_client.beta.threads.runs.create(
617"string",
618assistant_id="string",
619stream=True,
5d3111a8Stainless Bot1 years ago620include=["step_details.tool_calls[*].file_search.results[*].content"],
621additional_instructions="additional_instructions",
e2d65bf7Stainless Bot2 years ago622additional_messages=[
623{
79a0b401Stainless Bot2 years ago624"content": "string",
092a8df7Stainless Bot1 years ago625"role": "user",
5b20698dStainless Bot2 years ago626"attachments": [
627{
dd19d4f9Stainless Bot1 years ago628"file_id": "file_id",
629"tools": [{"type": "code_interpreter"}],
630}
5b20698dStainless Bot2 years ago631],
fdd52476stainless-app[bot]1 years ago632"metadata": {"foo": "string"},
dd19d4f9Stainless Bot1 years ago633}
e2d65bf7Stainless Bot2 years ago634],
5429f696Stainless Bot2 years ago635instructions="string",
f5247e30Stainless Bot2 years ago636max_completion_tokens=256,
637max_prompt_tokens=256,
fdd52476stainless-app[bot]1 years ago638metadata={"foo": "string"},
bf1ca86cRobert Craigie1 years ago639model="gpt-4o",
7399ffc8Stainless Bot2 years ago640parallel_tool_calls=True,
8640fd83stainless-app[bot]1 years ago641reasoning_effort="low",
bf1ca86cRobert Craigie1 years ago642response_format="auto",
27a4626aStainless Bot2 years ago643temperature=1,
f5247e30Stainless Bot2 years ago644tool_choice="none",
dd19d4f9Stainless Bot1 years ago645tools=[{"type": "code_interpreter"}],
5b20698dStainless Bot2 years ago646top_p=1,
f5247e30Stainless Bot2 years ago647truncation_strategy={
648"type": "auto",
649"last_messages": 1,
650},
5429f696Stainless Bot2 years ago651)
652await run_stream.response.aclose()
653
654@parametrize
655async def test_raw_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
656response = await async_client.beta.threads.runs.with_raw_response.create(
657"string",
658assistant_id="string",
659stream=True,
660)
661
662assert response.http_request.headers.get("X-Stainless-Lang") == "python"
663stream = response.parse()
664await stream.close()
665
666@parametrize
667async def test_streaming_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
668async with async_client.beta.threads.runs.with_streaming_response.create(
669"string",
670assistant_id="string",
671stream=True,
672) as response:
673assert not response.is_closed
674assert response.http_request.headers.get("X-Stainless-Lang") == "python"
675
676stream = await response.parse()
677await stream.close()
678
679assert cast(Any, response.is_closed) is True
680
681@parametrize
682async def test_path_params_create_overload_2(self, async_client: AsyncOpenAI) -> None:
683with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
684await async_client.beta.threads.runs.with_raw_response.create(
685"",
686assistant_id="string",
687stream=True,
688)
689
baa9f07fRobert Craigie2 years ago690@parametrize
98d779fbStainless Bot2 years ago691async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
692run = await async_client.beta.threads.runs.retrieve(
baa9f07fRobert Craigie2 years ago693"string",
694thread_id="string",
695)
696assert_matches_type(Run, run, path=["response"])
697
698@parametrize
98d779fbStainless Bot2 years ago699async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
700response = await async_client.beta.threads.runs.with_raw_response.retrieve(
baa9f07fRobert Craigie2 years ago701"string",
702thread_id="string",
703)
86379b44Stainless Bot2 years ago704
705assert response.is_closed is True
baa9f07fRobert Craigie2 years ago706assert response.http_request.headers.get("X-Stainless-Lang") == "python"
707run = response.parse()
708assert_matches_type(Run, run, path=["response"])
709
86379b44Stainless Bot2 years ago710@parametrize
98d779fbStainless Bot2 years ago711async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
712async with async_client.beta.threads.runs.with_streaming_response.retrieve(
86379b44Stainless Bot2 years ago713"string",
714thread_id="string",
715) as response:
716assert not response.is_closed
717assert response.http_request.headers.get("X-Stainless-Lang") == "python"
718
719run = await response.parse()
720assert_matches_type(Run, run, path=["response"])
721
722assert cast(Any, response.is_closed) is True
723
023a4e66Stainless Bot2 years ago724@parametrize
98d779fbStainless Bot2 years ago725async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago726with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago727await async_client.beta.threads.runs.with_raw_response.retrieve(
023a4e66Stainless Bot2 years ago728"string",
729thread_id="",
730)
731
732with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
98d779fbStainless Bot2 years ago733await async_client.beta.threads.runs.with_raw_response.retrieve(
023a4e66Stainless Bot2 years ago734"",
735thread_id="string",
736)
737
baa9f07fRobert Craigie2 years ago738@parametrize
98d779fbStainless Bot2 years ago739async def test_method_update(self, async_client: AsyncOpenAI) -> None:
740run = await async_client.beta.threads.runs.update(
baa9f07fRobert Craigie2 years ago741"string",
742thread_id="string",
743)
744assert_matches_type(Run, run, path=["response"])
745
746@parametrize
98d779fbStainless Bot2 years ago747async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None:
748run = await async_client.beta.threads.runs.update(
fdd52476stainless-app[bot]1 years ago749run_id="run_id",
750thread_id="thread_id",
751metadata={"foo": "string"},
baa9f07fRobert Craigie2 years ago752)
753assert_matches_type(Run, run, path=["response"])
754
755@parametrize
98d779fbStainless Bot2 years ago756async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
757response = await async_client.beta.threads.runs.with_raw_response.update(
baa9f07fRobert Craigie2 years ago758"string",
759thread_id="string",
760)
86379b44Stainless Bot2 years ago761
762assert response.is_closed is True
baa9f07fRobert Craigie2 years ago763assert response.http_request.headers.get("X-Stainless-Lang") == "python"
764run = response.parse()
765assert_matches_type(Run, run, path=["response"])
766
86379b44Stainless Bot2 years ago767@parametrize
98d779fbStainless Bot2 years ago768async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
769async with async_client.beta.threads.runs.with_streaming_response.update(
86379b44Stainless Bot2 years ago770"string",
771thread_id="string",
772) as response:
773assert not response.is_closed
774assert response.http_request.headers.get("X-Stainless-Lang") == "python"
775
776run = await response.parse()
777assert_matches_type(Run, run, path=["response"])
778
779assert cast(Any, response.is_closed) is True
780
023a4e66Stainless Bot2 years ago781@parametrize
98d779fbStainless Bot2 years ago782async def test_path_params_update(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago783with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago784await async_client.beta.threads.runs.with_raw_response.update(
023a4e66Stainless Bot2 years ago785"string",
786thread_id="",
787)
788
789with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
98d779fbStainless Bot2 years ago790await async_client.beta.threads.runs.with_raw_response.update(
023a4e66Stainless Bot2 years ago791"",
792thread_id="string",
793)
794
baa9f07fRobert Craigie2 years ago795@parametrize
98d779fbStainless Bot2 years ago796async def test_method_list(self, async_client: AsyncOpenAI) -> None:
797run = await async_client.beta.threads.runs.list(
baa9f07fRobert Craigie2 years ago798"string",
799)
800assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
801
802@parametrize
98d779fbStainless Bot2 years ago803async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
804run = await async_client.beta.threads.runs.list(
baa9f07fRobert Craigie2 years ago805"string",
806after="string",
807before="string",
808limit=0,
809order="asc",
810)
811assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
812
813@parametrize
98d779fbStainless Bot2 years ago814async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
815response = await async_client.beta.threads.runs.with_raw_response.list(
baa9f07fRobert Craigie2 years ago816"string",
817)
86379b44Stainless Bot2 years ago818
819assert response.is_closed is True
baa9f07fRobert Craigie2 years ago820assert response.http_request.headers.get("X-Stainless-Lang") == "python"
821run = response.parse()
822assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
823
86379b44Stainless Bot2 years ago824@parametrize
98d779fbStainless Bot2 years ago825async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
826async with async_client.beta.threads.runs.with_streaming_response.list(
86379b44Stainless Bot2 years ago827"string",
828) as response:
829assert not response.is_closed
830assert response.http_request.headers.get("X-Stainless-Lang") == "python"
831
832run = await response.parse()
833assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
834
835assert cast(Any, response.is_closed) is True
836
023a4e66Stainless Bot2 years ago837@parametrize
98d779fbStainless Bot2 years ago838async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago839with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago840await async_client.beta.threads.runs.with_raw_response.list(
023a4e66Stainless Bot2 years ago841"",
842)
843
baa9f07fRobert Craigie2 years ago844@parametrize
98d779fbStainless Bot2 years ago845async def test_method_cancel(self, async_client: AsyncOpenAI) -> None:
846run = await async_client.beta.threads.runs.cancel(
baa9f07fRobert Craigie2 years ago847"string",
848thread_id="string",
849)
850assert_matches_type(Run, run, path=["response"])
851
852@parametrize
98d779fbStainless Bot2 years ago853async def test_raw_response_cancel(self, async_client: AsyncOpenAI) -> None:
854response = await async_client.beta.threads.runs.with_raw_response.cancel(
baa9f07fRobert Craigie2 years ago855"string",
856thread_id="string",
857)
86379b44Stainless Bot2 years ago858
859assert response.is_closed is True
baa9f07fRobert Craigie2 years ago860assert response.http_request.headers.get("X-Stainless-Lang") == "python"
861run = response.parse()
862assert_matches_type(Run, run, path=["response"])
863
86379b44Stainless Bot2 years ago864@parametrize
98d779fbStainless Bot2 years ago865async def test_streaming_response_cancel(self, async_client: AsyncOpenAI) -> None:
866async with async_client.beta.threads.runs.with_streaming_response.cancel(
86379b44Stainless Bot2 years ago867"string",
868thread_id="string",
869) as response:
870assert not response.is_closed
871assert response.http_request.headers.get("X-Stainless-Lang") == "python"
872
873run = await response.parse()
874assert_matches_type(Run, run, path=["response"])
875
876assert cast(Any, response.is_closed) is True
877
023a4e66Stainless Bot2 years ago878@parametrize
98d779fbStainless Bot2 years ago879async def test_path_params_cancel(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago880with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago881await async_client.beta.threads.runs.with_raw_response.cancel(
023a4e66Stainless Bot2 years ago882"string",
883thread_id="",
884)
885
886with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
98d779fbStainless Bot2 years ago887await async_client.beta.threads.runs.with_raw_response.cancel(
023a4e66Stainless Bot2 years ago888"",
889thread_id="string",
890)
891
baa9f07fRobert Craigie2 years ago892@parametrize
5429f696Stainless Bot2 years ago893async def test_method_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago894run = await async_client.beta.threads.runs.submit_tool_outputs(
dd19d4f9Stainless Bot1 years ago895run_id="run_id",
896thread_id="thread_id",
897tool_outputs=[{}],
baa9f07fRobert Craigie2 years ago898)
899assert_matches_type(Run, run, path=["response"])
900
901@parametrize
5429f696Stainless Bot2 years ago902async def test_method_submit_tool_outputs_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
903run = await async_client.beta.threads.runs.submit_tool_outputs(
904"string",
905thread_id="string",
906tool_outputs=[
907{
092a8df7Stainless Bot1 years ago908"output": "output",
909"tool_call_id": "tool_call_id",
dd19d4f9Stainless Bot1 years ago910}
5429f696Stainless Bot2 years ago911],
912stream=False,
913)
914assert_matches_type(Run, run, path=["response"])
915
916@parametrize
917async def test_raw_response_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago918response = await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
dd19d4f9Stainless Bot1 years ago919run_id="run_id",
920thread_id="thread_id",
921tool_outputs=[{}],
baa9f07fRobert Craigie2 years ago922)
86379b44Stainless Bot2 years ago923
924assert response.is_closed is True
baa9f07fRobert Craigie2 years ago925assert response.http_request.headers.get("X-Stainless-Lang") == "python"
926run = response.parse()
927assert_matches_type(Run, run, path=["response"])
86379b44Stainless Bot2 years ago928
929@parametrize
5429f696Stainless Bot2 years ago930async def test_streaming_response_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago931async with async_client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
dd19d4f9Stainless Bot1 years ago932run_id="run_id",
933thread_id="thread_id",
934tool_outputs=[{}],
86379b44Stainless Bot2 years ago935) as response:
936assert not response.is_closed
937assert response.http_request.headers.get("X-Stainless-Lang") == "python"
938
939run = await response.parse()
940assert_matches_type(Run, run, path=["response"])
941
942assert cast(Any, response.is_closed) is True
023a4e66Stainless Bot2 years ago943
944@parametrize
5429f696Stainless Bot2 years ago945async def test_path_params_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
946with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
947await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
948"string",
949thread_id="",
dd19d4f9Stainless Bot1 years ago950tool_outputs=[{}],
5429f696Stainless Bot2 years ago951)
952
953with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
954await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
dd19d4f9Stainless Bot1 years ago955run_id="",
956thread_id="thread_id",
957tool_outputs=[{}],
5429f696Stainless Bot2 years ago958)
959
960@parametrize
961async def test_method_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
962run_stream = await async_client.beta.threads.runs.submit_tool_outputs(
963"string",
964thread_id="string",
965stream=True,
dd19d4f9Stainless Bot1 years ago966tool_outputs=[{}],
5429f696Stainless Bot2 years ago967)
968await run_stream.response.aclose()
969
970@parametrize
971async def test_raw_response_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
972response = await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
973"string",
974thread_id="string",
975stream=True,
dd19d4f9Stainless Bot1 years ago976tool_outputs=[{}],
5429f696Stainless Bot2 years ago977)
978
979assert response.http_request.headers.get("X-Stainless-Lang") == "python"
980stream = response.parse()
981await stream.close()
982
983@parametrize
984async def test_streaming_response_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
985async with async_client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
986"string",
987thread_id="string",
988stream=True,
dd19d4f9Stainless Bot1 years ago989tool_outputs=[{}],
5429f696Stainless Bot2 years ago990) as response:
991assert not response.is_closed
992assert response.http_request.headers.get("X-Stainless-Lang") == "python"
993
994stream = await response.parse()
995await stream.close()
996
997assert cast(Any, response.is_closed) is True
998
999@parametrize
1000async def test_path_params_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago1001with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago1002await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
023a4e66Stainless Bot2 years ago1003"string",
1004thread_id="",
5429f696Stainless Bot2 years ago1005stream=True,
dd19d4f9Stainless Bot1 years ago1006tool_outputs=[{}],
023a4e66Stainless Bot2 years ago1007)
1008
1009with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
98d779fbStainless Bot2 years ago1010await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
023a4e66Stainless Bot2 years ago1011"",
1012thread_id="string",
5429f696Stainless Bot2 years ago1013stream=True,
dd19d4f9Stainless Bot1 years ago1014tool_outputs=[{}],
023a4e66Stainless Bot2 years ago1015)