openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.66.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/test_threads.py

746lines · 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
4a0f0fa0Stainless Bot2 years ago12from openai.types.beta import (
13Thread,
14ThreadDeleted,
15)
16from openai.types.beta.threads import Run
baa9f07fRobert Craigie2 years ago17
18base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
19
20
21class TestThreads:
98d779fbStainless Bot2 years ago22parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
baa9f07fRobert Craigie2 years ago23
24@parametrize
25def test_method_create(self, client: OpenAI) -> None:
26thread = client.beta.threads.create()
27assert_matches_type(Thread, thread, path=["response"])
28
29@parametrize
30def test_method_create_with_all_params(self, client: OpenAI) -> None:
31thread = client.beta.threads.create(
32messages=[
33{
79a0b401Stainless Bot2 years ago34"content": "string",
092a8df7Stainless Bot1 years ago35"role": "user",
5b20698dStainless Bot2 years ago36"attachments": [
37{
dd19d4f9Stainless Bot1 years ago38"file_id": "file_id",
39"tools": [{"type": "code_interpreter"}],
40}
5b20698dStainless Bot2 years ago41],
fdd52476stainless-app[bot]1 years ago42"metadata": {"foo": "string"},
dd19d4f9Stainless Bot1 years ago43}
baa9f07fRobert Craigie2 years ago44],
fdd52476stainless-app[bot]1 years ago45metadata={"foo": "string"},
5b20698dStainless Bot2 years ago46tool_resources={
dd19d4f9Stainless Bot1 years ago47"code_interpreter": {"file_ids": ["string"]},
5b20698dStainless Bot2 years ago48"file_search": {
49"vector_store_ids": ["string"],
50"vector_stores": [
51{
1ff30bf5Stainless Bot2 years ago52"chunking_strategy": {"type": "auto"},
dd19d4f9Stainless Bot1 years ago53"file_ids": ["string"],
fdd52476stainless-app[bot]1 years ago54"metadata": {"foo": "string"},
5b20698dStainless Bot2 years ago55}
56],
57},
58},
baa9f07fRobert Craigie2 years ago59)
60assert_matches_type(Thread, thread, path=["response"])
61
62@parametrize
63def test_raw_response_create(self, client: OpenAI) -> None:
64response = client.beta.threads.with_raw_response.create()
86379b44Stainless Bot2 years ago65
66assert response.is_closed is True
baa9f07fRobert Craigie2 years ago67assert response.http_request.headers.get("X-Stainless-Lang") == "python"
68thread = response.parse()
69assert_matches_type(Thread, thread, path=["response"])
70
86379b44Stainless Bot2 years ago71@parametrize
72def test_streaming_response_create(self, client: OpenAI) -> None:
73with client.beta.threads.with_streaming_response.create() as response:
74assert not response.is_closed
75assert response.http_request.headers.get("X-Stainless-Lang") == "python"
76
77thread = response.parse()
78assert_matches_type(Thread, thread, path=["response"])
79
80assert cast(Any, response.is_closed) is True
81
baa9f07fRobert Craigie2 years ago82@parametrize
83def test_method_retrieve(self, client: OpenAI) -> None:
84thread = client.beta.threads.retrieve(
85"string",
86)
87assert_matches_type(Thread, thread, path=["response"])
88
89@parametrize
90def test_raw_response_retrieve(self, client: OpenAI) -> None:
91response = client.beta.threads.with_raw_response.retrieve(
92"string",
93)
86379b44Stainless Bot2 years ago94
95assert response.is_closed is True
baa9f07fRobert Craigie2 years ago96assert response.http_request.headers.get("X-Stainless-Lang") == "python"
97thread = response.parse()
98assert_matches_type(Thread, thread, path=["response"])
99
86379b44Stainless Bot2 years ago100@parametrize
101def test_streaming_response_retrieve(self, client: OpenAI) -> None:
102with client.beta.threads.with_streaming_response.retrieve(
103"string",
104) as response:
105assert not response.is_closed
106assert response.http_request.headers.get("X-Stainless-Lang") == "python"
107
108thread = response.parse()
109assert_matches_type(Thread, thread, path=["response"])
110
111assert cast(Any, response.is_closed) is True
112
023a4e66Stainless Bot2 years ago113@parametrize
114def test_path_params_retrieve(self, client: OpenAI) -> None:
115with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
116client.beta.threads.with_raw_response.retrieve(
117"",
118)
119
baa9f07fRobert Craigie2 years ago120@parametrize
121def test_method_update(self, client: OpenAI) -> None:
122thread = client.beta.threads.update(
123"string",
124)
125assert_matches_type(Thread, thread, path=["response"])
126
127@parametrize
128def test_method_update_with_all_params(self, client: OpenAI) -> None:
129thread = client.beta.threads.update(
fdd52476stainless-app[bot]1 years ago130thread_id="thread_id",
131metadata={"foo": "string"},
5b20698dStainless Bot2 years ago132tool_resources={
dd19d4f9Stainless Bot1 years ago133"code_interpreter": {"file_ids": ["string"]},
5b20698dStainless Bot2 years ago134"file_search": {"vector_store_ids": ["string"]},
135},
baa9f07fRobert Craigie2 years ago136)
137assert_matches_type(Thread, thread, path=["response"])
138
139@parametrize
140def test_raw_response_update(self, client: OpenAI) -> None:
141response = client.beta.threads.with_raw_response.update(
142"string",
143)
86379b44Stainless Bot2 years ago144
145assert response.is_closed is True
baa9f07fRobert Craigie2 years ago146assert response.http_request.headers.get("X-Stainless-Lang") == "python"
147thread = response.parse()
148assert_matches_type(Thread, thread, path=["response"])
149
86379b44Stainless Bot2 years ago150@parametrize
151def test_streaming_response_update(self, client: OpenAI) -> None:
152with client.beta.threads.with_streaming_response.update(
153"string",
154) as response:
155assert not response.is_closed
156assert response.http_request.headers.get("X-Stainless-Lang") == "python"
157
158thread = response.parse()
159assert_matches_type(Thread, thread, path=["response"])
160
161assert cast(Any, response.is_closed) is True
162
023a4e66Stainless Bot2 years ago163@parametrize
164def test_path_params_update(self, client: OpenAI) -> None:
165with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
166client.beta.threads.with_raw_response.update(
167"",
168)
169
baa9f07fRobert Craigie2 years ago170@parametrize
171def test_method_delete(self, client: OpenAI) -> None:
172thread = client.beta.threads.delete(
173"string",
174)
175assert_matches_type(ThreadDeleted, thread, path=["response"])
176
177@parametrize
178def test_raw_response_delete(self, client: OpenAI) -> None:
179response = client.beta.threads.with_raw_response.delete(
180"string",
181)
86379b44Stainless Bot2 years ago182
183assert response.is_closed is True
baa9f07fRobert Craigie2 years ago184assert response.http_request.headers.get("X-Stainless-Lang") == "python"
185thread = response.parse()
186assert_matches_type(ThreadDeleted, thread, path=["response"])
187
86379b44Stainless Bot2 years ago188@parametrize
189def test_streaming_response_delete(self, client: OpenAI) -> None:
190with client.beta.threads.with_streaming_response.delete(
191"string",
192) as response:
193assert not response.is_closed
194assert response.http_request.headers.get("X-Stainless-Lang") == "python"
195
196thread = response.parse()
197assert_matches_type(ThreadDeleted, thread, path=["response"])
198
199assert cast(Any, response.is_closed) is True
200
023a4e66Stainless Bot2 years ago201@parametrize
202def test_path_params_delete(self, client: OpenAI) -> None:
203with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
204client.beta.threads.with_raw_response.delete(
205"",
206)
207
baa9f07fRobert Craigie2 years ago208@parametrize
5429f696Stainless Bot2 years ago209def test_method_create_and_run_overload_1(self, client: OpenAI) -> None:
baa9f07fRobert Craigie2 years ago210thread = client.beta.threads.create_and_run(
211assistant_id="string",
212)
213assert_matches_type(Run, thread, path=["response"])
214
215@parametrize
5429f696Stainless Bot2 years ago216def test_method_create_and_run_with_all_params_overload_1(self, client: OpenAI) -> None:
baa9f07fRobert Craigie2 years ago217thread = client.beta.threads.create_and_run(
218assistant_id="string",
219instructions="string",
f5247e30Stainless Bot2 years ago220max_completion_tokens=256,
221max_prompt_tokens=256,
fdd52476stainless-app[bot]1 years ago222metadata={"foo": "string"},
bf1ca86cRobert Craigie1 years ago223model="gpt-4o",
7399ffc8Stainless Bot2 years ago224parallel_tool_calls=True,
bf1ca86cRobert Craigie1 years ago225response_format="auto",
5429f696Stainless Bot2 years ago226stream=False,
27a4626aStainless Bot2 years ago227temperature=1,
baa9f07fRobert Craigie2 years ago228thread={
229"messages": [
230{
79a0b401Stainless Bot2 years ago231"content": "string",
092a8df7Stainless Bot1 years ago232"role": "user",
5b20698dStainless Bot2 years ago233"attachments": [
234{
dd19d4f9Stainless Bot1 years ago235"file_id": "file_id",
236"tools": [{"type": "code_interpreter"}],
237}
5b20698dStainless Bot2 years ago238],
fdd52476stainless-app[bot]1 years ago239"metadata": {"foo": "string"},
dd19d4f9Stainless Bot1 years ago240}
baa9f07fRobert Craigie2 years ago241],
fdd52476stainless-app[bot]1 years ago242"metadata": {"foo": "string"},
5b20698dStainless Bot2 years ago243"tool_resources": {
dd19d4f9Stainless Bot1 years ago244"code_interpreter": {"file_ids": ["string"]},
5b20698dStainless Bot2 years ago245"file_search": {
246"vector_store_ids": ["string"],
247"vector_stores": [
248{
1ff30bf5Stainless Bot2 years ago249"chunking_strategy": {"type": "auto"},
dd19d4f9Stainless Bot1 years ago250"file_ids": ["string"],
fdd52476stainless-app[bot]1 years ago251"metadata": {"foo": "string"},
5b20698dStainless Bot2 years ago252}
253],
254},
255},
baa9f07fRobert Craigie2 years ago256},
f5247e30Stainless Bot2 years ago257tool_choice="none",
5b20698dStainless Bot2 years ago258tool_resources={
dd19d4f9Stainless Bot1 years ago259"code_interpreter": {"file_ids": ["string"]},
5b20698dStainless Bot2 years ago260"file_search": {"vector_store_ids": ["string"]},
261},
dd19d4f9Stainless Bot1 years ago262tools=[{"type": "code_interpreter"}],
5b20698dStainless Bot2 years ago263top_p=1,
f5247e30Stainless Bot2 years ago264truncation_strategy={
265"type": "auto",
266"last_messages": 1,
267},
baa9f07fRobert Craigie2 years ago268)
269assert_matches_type(Run, thread, path=["response"])
270
271@parametrize
5429f696Stainless Bot2 years ago272def test_raw_response_create_and_run_overload_1(self, client: OpenAI) -> None:
baa9f07fRobert Craigie2 years ago273response = client.beta.threads.with_raw_response.create_and_run(
274assistant_id="string",
275)
86379b44Stainless Bot2 years ago276
277assert response.is_closed is True
baa9f07fRobert Craigie2 years ago278assert response.http_request.headers.get("X-Stainless-Lang") == "python"
279thread = response.parse()
280assert_matches_type(Run, thread, path=["response"])
281
86379b44Stainless Bot2 years ago282@parametrize
5429f696Stainless Bot2 years ago283def test_streaming_response_create_and_run_overload_1(self, client: OpenAI) -> None:
86379b44Stainless Bot2 years ago284with client.beta.threads.with_streaming_response.create_and_run(
285assistant_id="string",
286) as response:
287assert not response.is_closed
288assert response.http_request.headers.get("X-Stainless-Lang") == "python"
289
290thread = response.parse()
291assert_matches_type(Run, thread, path=["response"])
292
293assert cast(Any, response.is_closed) is True
294
5429f696Stainless Bot2 years ago295@parametrize
296def test_method_create_and_run_overload_2(self, client: OpenAI) -> None:
297thread_stream = client.beta.threads.create_and_run(
298assistant_id="string",
299stream=True,
300)
301thread_stream.response.close()
302
303@parametrize
304def test_method_create_and_run_with_all_params_overload_2(self, client: OpenAI) -> None:
305thread_stream = client.beta.threads.create_and_run(
306assistant_id="string",
307stream=True,
308instructions="string",
f5247e30Stainless Bot2 years ago309max_completion_tokens=256,
310max_prompt_tokens=256,
fdd52476stainless-app[bot]1 years ago311metadata={"foo": "string"},
bf1ca86cRobert Craigie1 years ago312model="gpt-4o",
7399ffc8Stainless Bot2 years ago313parallel_tool_calls=True,
bf1ca86cRobert Craigie1 years ago314response_format="auto",
27a4626aStainless Bot2 years ago315temperature=1,
5429f696Stainless Bot2 years ago316thread={
317"messages": [
318{
79a0b401Stainless Bot2 years ago319"content": "string",
092a8df7Stainless Bot1 years ago320"role": "user",
5b20698dStainless Bot2 years ago321"attachments": [
322{
dd19d4f9Stainless Bot1 years ago323"file_id": "file_id",
324"tools": [{"type": "code_interpreter"}],
325}
5b20698dStainless Bot2 years ago326],
fdd52476stainless-app[bot]1 years ago327"metadata": {"foo": "string"},
dd19d4f9Stainless Bot1 years ago328}
5429f696Stainless Bot2 years ago329],
fdd52476stainless-app[bot]1 years ago330"metadata": {"foo": "string"},
5b20698dStainless Bot2 years ago331"tool_resources": {
dd19d4f9Stainless Bot1 years ago332"code_interpreter": {"file_ids": ["string"]},
5b20698dStainless Bot2 years ago333"file_search": {
334"vector_store_ids": ["string"],
335"vector_stores": [
336{
1ff30bf5Stainless Bot2 years ago337"chunking_strategy": {"type": "auto"},
dd19d4f9Stainless Bot1 years ago338"file_ids": ["string"],
fdd52476stainless-app[bot]1 years ago339"metadata": {"foo": "string"},
5b20698dStainless Bot2 years ago340}
341],
342},
343},
5429f696Stainless Bot2 years ago344},
f5247e30Stainless Bot2 years ago345tool_choice="none",
5b20698dStainless Bot2 years ago346tool_resources={
dd19d4f9Stainless Bot1 years ago347"code_interpreter": {"file_ids": ["string"]},
5b20698dStainless Bot2 years ago348"file_search": {"vector_store_ids": ["string"]},
349},
dd19d4f9Stainless Bot1 years ago350tools=[{"type": "code_interpreter"}],
5b20698dStainless Bot2 years ago351top_p=1,
f5247e30Stainless Bot2 years ago352truncation_strategy={
353"type": "auto",
354"last_messages": 1,
355},
5429f696Stainless Bot2 years ago356)
357thread_stream.response.close()
358
359@parametrize
360def test_raw_response_create_and_run_overload_2(self, client: OpenAI) -> None:
361response = client.beta.threads.with_raw_response.create_and_run(
362assistant_id="string",
363stream=True,
364)
365
366assert response.http_request.headers.get("X-Stainless-Lang") == "python"
367stream = response.parse()
368stream.close()
369
370@parametrize
371def test_streaming_response_create_and_run_overload_2(self, client: OpenAI) -> None:
372with client.beta.threads.with_streaming_response.create_and_run(
373assistant_id="string",
374stream=True,
375) as response:
376assert not response.is_closed
377assert response.http_request.headers.get("X-Stainless-Lang") == "python"
378
379stream = response.parse()
380stream.close()
381
382assert cast(Any, response.is_closed) is True
383
baa9f07fRobert Craigie2 years ago384
385class TestAsyncThreads:
98d779fbStainless Bot2 years ago386parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
baa9f07fRobert Craigie2 years ago387
388@parametrize
98d779fbStainless Bot2 years ago389async def test_method_create(self, async_client: AsyncOpenAI) -> None:
390thread = await async_client.beta.threads.create()
baa9f07fRobert Craigie2 years ago391assert_matches_type(Thread, thread, path=["response"])
392
393@parametrize
98d779fbStainless Bot2 years ago394async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
395thread = await async_client.beta.threads.create(
baa9f07fRobert Craigie2 years ago396messages=[
397{
79a0b401Stainless Bot2 years ago398"content": "string",
092a8df7Stainless Bot1 years ago399"role": "user",
5b20698dStainless Bot2 years ago400"attachments": [
401{
dd19d4f9Stainless Bot1 years ago402"file_id": "file_id",
403"tools": [{"type": "code_interpreter"}],
404}
5b20698dStainless Bot2 years ago405],
fdd52476stainless-app[bot]1 years ago406"metadata": {"foo": "string"},
dd19d4f9Stainless Bot1 years ago407}
baa9f07fRobert Craigie2 years ago408],
fdd52476stainless-app[bot]1 years ago409metadata={"foo": "string"},
5b20698dStainless Bot2 years ago410tool_resources={
dd19d4f9Stainless Bot1 years ago411"code_interpreter": {"file_ids": ["string"]},
5b20698dStainless Bot2 years ago412"file_search": {
413"vector_store_ids": ["string"],
414"vector_stores": [
415{
1ff30bf5Stainless Bot2 years ago416"chunking_strategy": {"type": "auto"},
dd19d4f9Stainless Bot1 years ago417"file_ids": ["string"],
fdd52476stainless-app[bot]1 years ago418"metadata": {"foo": "string"},
5b20698dStainless Bot2 years ago419}
420],
421},
422},
baa9f07fRobert Craigie2 years ago423)
424assert_matches_type(Thread, thread, path=["response"])
425
426@parametrize
98d779fbStainless Bot2 years ago427async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
428response = await async_client.beta.threads.with_raw_response.create()
86379b44Stainless Bot2 years ago429
430assert response.is_closed is True
baa9f07fRobert Craigie2 years ago431assert response.http_request.headers.get("X-Stainless-Lang") == "python"
432thread = response.parse()
433assert_matches_type(Thread, thread, path=["response"])
434
86379b44Stainless Bot2 years ago435@parametrize
98d779fbStainless Bot2 years ago436async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
437async with async_client.beta.threads.with_streaming_response.create() as response:
86379b44Stainless Bot2 years ago438assert not response.is_closed
439assert response.http_request.headers.get("X-Stainless-Lang") == "python"
440
441thread = await response.parse()
442assert_matches_type(Thread, thread, path=["response"])
443
444assert cast(Any, response.is_closed) is True
445
baa9f07fRobert Craigie2 years ago446@parametrize
98d779fbStainless Bot2 years ago447async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
448thread = await async_client.beta.threads.retrieve(
baa9f07fRobert Craigie2 years ago449"string",
450)
451assert_matches_type(Thread, thread, path=["response"])
452
453@parametrize
98d779fbStainless Bot2 years ago454async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
455response = await async_client.beta.threads.with_raw_response.retrieve(
baa9f07fRobert Craigie2 years ago456"string",
457)
86379b44Stainless Bot2 years ago458
459assert response.is_closed is True
baa9f07fRobert Craigie2 years ago460assert response.http_request.headers.get("X-Stainless-Lang") == "python"
461thread = response.parse()
462assert_matches_type(Thread, thread, path=["response"])
463
86379b44Stainless Bot2 years ago464@parametrize
98d779fbStainless Bot2 years ago465async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
466async with async_client.beta.threads.with_streaming_response.retrieve(
86379b44Stainless Bot2 years ago467"string",
468) as response:
469assert not response.is_closed
470assert response.http_request.headers.get("X-Stainless-Lang") == "python"
471
472thread = await response.parse()
473assert_matches_type(Thread, thread, path=["response"])
474
475assert cast(Any, response.is_closed) is True
476
023a4e66Stainless Bot2 years ago477@parametrize
98d779fbStainless Bot2 years ago478async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago479with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago480await async_client.beta.threads.with_raw_response.retrieve(
023a4e66Stainless Bot2 years ago481"",
482)
483
baa9f07fRobert Craigie2 years ago484@parametrize
98d779fbStainless Bot2 years ago485async def test_method_update(self, async_client: AsyncOpenAI) -> None:
486thread = await async_client.beta.threads.update(
baa9f07fRobert Craigie2 years ago487"string",
488)
489assert_matches_type(Thread, thread, path=["response"])
490
491@parametrize
98d779fbStainless Bot2 years ago492async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None:
493thread = await async_client.beta.threads.update(
fdd52476stainless-app[bot]1 years ago494thread_id="thread_id",
495metadata={"foo": "string"},
5b20698dStainless Bot2 years ago496tool_resources={
dd19d4f9Stainless Bot1 years ago497"code_interpreter": {"file_ids": ["string"]},
5b20698dStainless Bot2 years ago498"file_search": {"vector_store_ids": ["string"]},
499},
baa9f07fRobert Craigie2 years ago500)
501assert_matches_type(Thread, thread, path=["response"])
502
503@parametrize
98d779fbStainless Bot2 years ago504async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
505response = await async_client.beta.threads.with_raw_response.update(
baa9f07fRobert Craigie2 years ago506"string",
507)
86379b44Stainless Bot2 years ago508
509assert response.is_closed is True
baa9f07fRobert Craigie2 years ago510assert response.http_request.headers.get("X-Stainless-Lang") == "python"
511thread = response.parse()
512assert_matches_type(Thread, thread, path=["response"])
513
86379b44Stainless Bot2 years ago514@parametrize
98d779fbStainless Bot2 years ago515async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
516async with async_client.beta.threads.with_streaming_response.update(
86379b44Stainless Bot2 years ago517"string",
518) as response:
519assert not response.is_closed
520assert response.http_request.headers.get("X-Stainless-Lang") == "python"
521
522thread = await response.parse()
523assert_matches_type(Thread, thread, path=["response"])
524
525assert cast(Any, response.is_closed) is True
526
023a4e66Stainless Bot2 years ago527@parametrize
98d779fbStainless Bot2 years ago528async def test_path_params_update(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago529with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago530await async_client.beta.threads.with_raw_response.update(
023a4e66Stainless Bot2 years ago531"",
532)
533
baa9f07fRobert Craigie2 years ago534@parametrize
98d779fbStainless Bot2 years ago535async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
536thread = await async_client.beta.threads.delete(
baa9f07fRobert Craigie2 years ago537"string",
538)
539assert_matches_type(ThreadDeleted, thread, path=["response"])
540
541@parametrize
98d779fbStainless Bot2 years ago542async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
543response = await async_client.beta.threads.with_raw_response.delete(
baa9f07fRobert Craigie2 years ago544"string",
545)
86379b44Stainless Bot2 years ago546
547assert response.is_closed is True
baa9f07fRobert Craigie2 years ago548assert response.http_request.headers.get("X-Stainless-Lang") == "python"
549thread = response.parse()
550assert_matches_type(ThreadDeleted, thread, path=["response"])
551
86379b44Stainless Bot2 years ago552@parametrize
98d779fbStainless Bot2 years ago553async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
554async with async_client.beta.threads.with_streaming_response.delete(
86379b44Stainless Bot2 years ago555"string",
556) as response:
557assert not response.is_closed
558assert response.http_request.headers.get("X-Stainless-Lang") == "python"
559
560thread = await response.parse()
561assert_matches_type(ThreadDeleted, thread, path=["response"])
562
563assert cast(Any, response.is_closed) is True
564
023a4e66Stainless Bot2 years ago565@parametrize
98d779fbStainless Bot2 years ago566async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago567with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago568await async_client.beta.threads.with_raw_response.delete(
023a4e66Stainless Bot2 years ago569"",
570)
571
baa9f07fRobert Craigie2 years ago572@parametrize
5429f696Stainless Bot2 years ago573async def test_method_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago574thread = await async_client.beta.threads.create_and_run(
baa9f07fRobert Craigie2 years ago575assistant_id="string",
576)
577assert_matches_type(Run, thread, path=["response"])
578
579@parametrize
5429f696Stainless Bot2 years ago580async def test_method_create_and_run_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago581thread = await async_client.beta.threads.create_and_run(
baa9f07fRobert Craigie2 years ago582assistant_id="string",
583instructions="string",
f5247e30Stainless Bot2 years ago584max_completion_tokens=256,
585max_prompt_tokens=256,
fdd52476stainless-app[bot]1 years ago586metadata={"foo": "string"},
bf1ca86cRobert Craigie1 years ago587model="gpt-4o",
7399ffc8Stainless Bot2 years ago588parallel_tool_calls=True,
bf1ca86cRobert Craigie1 years ago589response_format="auto",
5429f696Stainless Bot2 years ago590stream=False,
27a4626aStainless Bot2 years ago591temperature=1,
baa9f07fRobert Craigie2 years ago592thread={
593"messages": [
594{
79a0b401Stainless Bot2 years ago595"content": "string",
092a8df7Stainless Bot1 years ago596"role": "user",
5b20698dStainless Bot2 years ago597"attachments": [
598{
dd19d4f9Stainless Bot1 years ago599"file_id": "file_id",
600"tools": [{"type": "code_interpreter"}],
601}
5b20698dStainless Bot2 years ago602],
fdd52476stainless-app[bot]1 years ago603"metadata": {"foo": "string"},
dd19d4f9Stainless Bot1 years ago604}
baa9f07fRobert Craigie2 years ago605],
fdd52476stainless-app[bot]1 years ago606"metadata": {"foo": "string"},
5b20698dStainless Bot2 years ago607"tool_resources": {
dd19d4f9Stainless Bot1 years ago608"code_interpreter": {"file_ids": ["string"]},
5b20698dStainless Bot2 years ago609"file_search": {
610"vector_store_ids": ["string"],
611"vector_stores": [
612{
1ff30bf5Stainless Bot2 years ago613"chunking_strategy": {"type": "auto"},
dd19d4f9Stainless Bot1 years ago614"file_ids": ["string"],
fdd52476stainless-app[bot]1 years ago615"metadata": {"foo": "string"},
5b20698dStainless Bot2 years ago616}
617],
618},
619},
baa9f07fRobert Craigie2 years ago620},
f5247e30Stainless Bot2 years ago621tool_choice="none",
5b20698dStainless Bot2 years ago622tool_resources={
dd19d4f9Stainless Bot1 years ago623"code_interpreter": {"file_ids": ["string"]},
5b20698dStainless Bot2 years ago624"file_search": {"vector_store_ids": ["string"]},
625},
dd19d4f9Stainless Bot1 years ago626tools=[{"type": "code_interpreter"}],
5b20698dStainless Bot2 years ago627top_p=1,
f5247e30Stainless Bot2 years ago628truncation_strategy={
629"type": "auto",
630"last_messages": 1,
631},
baa9f07fRobert Craigie2 years ago632)
633assert_matches_type(Run, thread, path=["response"])
634
635@parametrize
5429f696Stainless Bot2 years ago636async def test_raw_response_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago637response = await async_client.beta.threads.with_raw_response.create_and_run(
baa9f07fRobert Craigie2 years ago638assistant_id="string",
639)
86379b44Stainless Bot2 years ago640
641assert response.is_closed is True
baa9f07fRobert Craigie2 years ago642assert response.http_request.headers.get("X-Stainless-Lang") == "python"
643thread = response.parse()
644assert_matches_type(Run, thread, path=["response"])
86379b44Stainless Bot2 years ago645
646@parametrize
5429f696Stainless Bot2 years ago647async def test_streaming_response_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago648async with async_client.beta.threads.with_streaming_response.create_and_run(
86379b44Stainless Bot2 years ago649assistant_id="string",
650) as response:
651assert not response.is_closed
652assert response.http_request.headers.get("X-Stainless-Lang") == "python"
653
654thread = await response.parse()
655assert_matches_type(Run, thread, path=["response"])
656
657assert cast(Any, response.is_closed) is True
5429f696Stainless Bot2 years ago658
659@parametrize
660async def test_method_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None:
661thread_stream = await async_client.beta.threads.create_and_run(
662assistant_id="string",
663stream=True,
664)
665await thread_stream.response.aclose()
666
667@parametrize
668async def test_method_create_and_run_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None:
669thread_stream = await async_client.beta.threads.create_and_run(
670assistant_id="string",
671stream=True,
672instructions="string",
f5247e30Stainless Bot2 years ago673max_completion_tokens=256,
674max_prompt_tokens=256,
fdd52476stainless-app[bot]1 years ago675metadata={"foo": "string"},
bf1ca86cRobert Craigie1 years ago676model="gpt-4o",
7399ffc8Stainless Bot2 years ago677parallel_tool_calls=True,
bf1ca86cRobert Craigie1 years ago678response_format="auto",
27a4626aStainless Bot2 years ago679temperature=1,
5429f696Stainless Bot2 years ago680thread={
681"messages": [
682{
79a0b401Stainless Bot2 years ago683"content": "string",
092a8df7Stainless Bot1 years ago684"role": "user",
5b20698dStainless Bot2 years ago685"attachments": [
686{
dd19d4f9Stainless Bot1 years ago687"file_id": "file_id",
688"tools": [{"type": "code_interpreter"}],
689}
5b20698dStainless Bot2 years ago690],
fdd52476stainless-app[bot]1 years ago691"metadata": {"foo": "string"},
dd19d4f9Stainless Bot1 years ago692}
5429f696Stainless Bot2 years ago693],
fdd52476stainless-app[bot]1 years ago694"metadata": {"foo": "string"},
5b20698dStainless Bot2 years ago695"tool_resources": {
dd19d4f9Stainless Bot1 years ago696"code_interpreter": {"file_ids": ["string"]},
5b20698dStainless Bot2 years ago697"file_search": {
698"vector_store_ids": ["string"],
699"vector_stores": [
700{
1ff30bf5Stainless Bot2 years ago701"chunking_strategy": {"type": "auto"},
dd19d4f9Stainless Bot1 years ago702"file_ids": ["string"],
fdd52476stainless-app[bot]1 years ago703"metadata": {"foo": "string"},
5b20698dStainless Bot2 years ago704}
705],
706},
707},
5429f696Stainless Bot2 years ago708},
f5247e30Stainless Bot2 years ago709tool_choice="none",
5b20698dStainless Bot2 years ago710tool_resources={
dd19d4f9Stainless Bot1 years ago711"code_interpreter": {"file_ids": ["string"]},
5b20698dStainless Bot2 years ago712"file_search": {"vector_store_ids": ["string"]},
713},
dd19d4f9Stainless Bot1 years ago714tools=[{"type": "code_interpreter"}],
5b20698dStainless Bot2 years ago715top_p=1,
f5247e30Stainless Bot2 years ago716truncation_strategy={
717"type": "auto",
718"last_messages": 1,
719},
5429f696Stainless Bot2 years ago720)
721await thread_stream.response.aclose()
722
723@parametrize
724async def test_raw_response_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None:
725response = await async_client.beta.threads.with_raw_response.create_and_run(
726assistant_id="string",
727stream=True,
728)
729
730assert response.http_request.headers.get("X-Stainless-Lang") == "python"
731stream = response.parse()
732await stream.close()
733
734@parametrize
735async def test_streaming_response_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None:
736async with async_client.beta.threads.with_streaming_response.create_and_run(
737assistant_id="string",
738stream=True,
739) as response:
740assert not response.is_closed
741assert response.http_request.headers.get("X-Stainless-Lang") == "python"
742
743stream = await response.parse()
744await stream.close()
745
746assert cast(Any, response.is_closed) is True