openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.41.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/test_threads.py

1238lines · 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{
38"file_id": "string",
f73996b7Stainless Bot2 years ago39"tools": [
40{"type": "code_interpreter"},
41{"type": "code_interpreter"},
42{"type": "code_interpreter"},
43],
5b20698dStainless Bot2 years ago44},
45{
46"file_id": "string",
f73996b7Stainless Bot2 years ago47"tools": [
48{"type": "code_interpreter"},
49{"type": "code_interpreter"},
50{"type": "code_interpreter"},
51],
5b20698dStainless Bot2 years ago52},
53{
54"file_id": "string",
f73996b7Stainless Bot2 years ago55"tools": [
56{"type": "code_interpreter"},
57{"type": "code_interpreter"},
58{"type": "code_interpreter"},
59],
5b20698dStainless Bot2 years ago60},
61],
baa9f07fRobert Craigie2 years ago62"metadata": {},
63},
64{
79a0b401Stainless Bot2 years ago65"content": "string",
092a8df7Stainless Bot1 years ago66"role": "user",
5b20698dStainless Bot2 years ago67"attachments": [
68{
69"file_id": "string",
f73996b7Stainless Bot2 years ago70"tools": [
71{"type": "code_interpreter"},
72{"type": "code_interpreter"},
73{"type": "code_interpreter"},
74],
5b20698dStainless Bot2 years ago75},
76{
77"file_id": "string",
f73996b7Stainless Bot2 years ago78"tools": [
79{"type": "code_interpreter"},
80{"type": "code_interpreter"},
81{"type": "code_interpreter"},
82],
5b20698dStainless Bot2 years ago83},
84{
85"file_id": "string",
f73996b7Stainless Bot2 years ago86"tools": [
87{"type": "code_interpreter"},
88{"type": "code_interpreter"},
89{"type": "code_interpreter"},
90],
5b20698dStainless Bot2 years ago91},
92],
baa9f07fRobert Craigie2 years ago93"metadata": {},
94},
95{
79a0b401Stainless Bot2 years ago96"content": "string",
092a8df7Stainless Bot1 years ago97"role": "user",
5b20698dStainless Bot2 years ago98"attachments": [
99{
100"file_id": "string",
f73996b7Stainless Bot2 years ago101"tools": [
102{"type": "code_interpreter"},
103{"type": "code_interpreter"},
104{"type": "code_interpreter"},
105],
5b20698dStainless Bot2 years ago106},
107{
108"file_id": "string",
f73996b7Stainless Bot2 years ago109"tools": [
110{"type": "code_interpreter"},
111{"type": "code_interpreter"},
112{"type": "code_interpreter"},
113],
5b20698dStainless Bot2 years ago114},
115{
116"file_id": "string",
f73996b7Stainless Bot2 years ago117"tools": [
118{"type": "code_interpreter"},
119{"type": "code_interpreter"},
120{"type": "code_interpreter"},
121],
5b20698dStainless Bot2 years ago122},
123],
baa9f07fRobert Craigie2 years ago124"metadata": {},
125},
126],
127metadata={},
5b20698dStainless Bot2 years ago128tool_resources={
129"code_interpreter": {"file_ids": ["string", "string", "string"]},
130"file_search": {
131"vector_store_ids": ["string"],
132"vector_stores": [
133{
1ff30bf5Stainless Bot2 years ago134"chunking_strategy": {"type": "auto"},
092a8df7Stainless Bot1 years ago135"file_ids": ["string", "string", "string"],
5b20698dStainless Bot2 years ago136"metadata": {},
137}
138],
139},
140},
baa9f07fRobert Craigie2 years ago141)
142assert_matches_type(Thread, thread, path=["response"])
143
144@parametrize
145def test_raw_response_create(self, client: OpenAI) -> None:
146response = client.beta.threads.with_raw_response.create()
86379b44Stainless Bot2 years ago147
148assert response.is_closed is True
baa9f07fRobert Craigie2 years ago149assert response.http_request.headers.get("X-Stainless-Lang") == "python"
150thread = response.parse()
151assert_matches_type(Thread, thread, path=["response"])
152
86379b44Stainless Bot2 years ago153@parametrize
154def test_streaming_response_create(self, client: OpenAI) -> None:
155with client.beta.threads.with_streaming_response.create() as response:
156assert not response.is_closed
157assert response.http_request.headers.get("X-Stainless-Lang") == "python"
158
159thread = response.parse()
160assert_matches_type(Thread, thread, path=["response"])
161
162assert cast(Any, response.is_closed) is True
163
baa9f07fRobert Craigie2 years ago164@parametrize
165def test_method_retrieve(self, client: OpenAI) -> None:
166thread = client.beta.threads.retrieve(
167"string",
168)
169assert_matches_type(Thread, thread, path=["response"])
170
171@parametrize
172def test_raw_response_retrieve(self, client: OpenAI) -> None:
173response = client.beta.threads.with_raw_response.retrieve(
174"string",
175)
86379b44Stainless Bot2 years ago176
177assert response.is_closed is True
baa9f07fRobert Craigie2 years ago178assert response.http_request.headers.get("X-Stainless-Lang") == "python"
179thread = response.parse()
180assert_matches_type(Thread, thread, path=["response"])
181
86379b44Stainless Bot2 years ago182@parametrize
183def test_streaming_response_retrieve(self, client: OpenAI) -> None:
184with client.beta.threads.with_streaming_response.retrieve(
185"string",
186) as response:
187assert not response.is_closed
188assert response.http_request.headers.get("X-Stainless-Lang") == "python"
189
190thread = response.parse()
191assert_matches_type(Thread, thread, path=["response"])
192
193assert cast(Any, response.is_closed) is True
194
023a4e66Stainless Bot2 years ago195@parametrize
196def test_path_params_retrieve(self, client: OpenAI) -> None:
197with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
198client.beta.threads.with_raw_response.retrieve(
199"",
200)
201
baa9f07fRobert Craigie2 years ago202@parametrize
203def test_method_update(self, client: OpenAI) -> None:
204thread = client.beta.threads.update(
205"string",
206)
207assert_matches_type(Thread, thread, path=["response"])
208
209@parametrize
210def test_method_update_with_all_params(self, client: OpenAI) -> None:
211thread = client.beta.threads.update(
212"string",
213metadata={},
5b20698dStainless Bot2 years ago214tool_resources={
215"code_interpreter": {"file_ids": ["string", "string", "string"]},
216"file_search": {"vector_store_ids": ["string"]},
217},
baa9f07fRobert Craigie2 years ago218)
219assert_matches_type(Thread, thread, path=["response"])
220
221@parametrize
222def test_raw_response_update(self, client: OpenAI) -> None:
223response = client.beta.threads.with_raw_response.update(
224"string",
225)
86379b44Stainless Bot2 years ago226
227assert response.is_closed is True
baa9f07fRobert Craigie2 years ago228assert response.http_request.headers.get("X-Stainless-Lang") == "python"
229thread = response.parse()
230assert_matches_type(Thread, thread, path=["response"])
231
86379b44Stainless Bot2 years ago232@parametrize
233def test_streaming_response_update(self, client: OpenAI) -> None:
234with client.beta.threads.with_streaming_response.update(
235"string",
236) as response:
237assert not response.is_closed
238assert response.http_request.headers.get("X-Stainless-Lang") == "python"
239
240thread = response.parse()
241assert_matches_type(Thread, thread, path=["response"])
242
243assert cast(Any, response.is_closed) is True
244
023a4e66Stainless Bot2 years ago245@parametrize
246def test_path_params_update(self, client: OpenAI) -> None:
247with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
248client.beta.threads.with_raw_response.update(
249"",
250)
251
baa9f07fRobert Craigie2 years ago252@parametrize
253def test_method_delete(self, client: OpenAI) -> None:
254thread = client.beta.threads.delete(
255"string",
256)
257assert_matches_type(ThreadDeleted, thread, path=["response"])
258
259@parametrize
260def test_raw_response_delete(self, client: OpenAI) -> None:
261response = client.beta.threads.with_raw_response.delete(
262"string",
263)
86379b44Stainless Bot2 years ago264
265assert response.is_closed is True
baa9f07fRobert Craigie2 years ago266assert response.http_request.headers.get("X-Stainless-Lang") == "python"
267thread = response.parse()
268assert_matches_type(ThreadDeleted, thread, path=["response"])
269
86379b44Stainless Bot2 years ago270@parametrize
271def test_streaming_response_delete(self, client: OpenAI) -> None:
272with client.beta.threads.with_streaming_response.delete(
273"string",
274) as response:
275assert not response.is_closed
276assert response.http_request.headers.get("X-Stainless-Lang") == "python"
277
278thread = response.parse()
279assert_matches_type(ThreadDeleted, thread, path=["response"])
280
281assert cast(Any, response.is_closed) is True
282
023a4e66Stainless Bot2 years ago283@parametrize
284def test_path_params_delete(self, client: OpenAI) -> None:
285with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
286client.beta.threads.with_raw_response.delete(
287"",
288)
289
baa9f07fRobert Craigie2 years ago290@parametrize
5429f696Stainless Bot2 years ago291def test_method_create_and_run_overload_1(self, client: OpenAI) -> None:
baa9f07fRobert Craigie2 years ago292thread = client.beta.threads.create_and_run(
293assistant_id="string",
294)
295assert_matches_type(Run, thread, path=["response"])
296
297@parametrize
5429f696Stainless Bot2 years ago298def test_method_create_and_run_with_all_params_overload_1(self, client: OpenAI) -> None:
baa9f07fRobert Craigie2 years ago299thread = client.beta.threads.create_and_run(
300assistant_id="string",
301instructions="string",
f5247e30Stainless Bot2 years ago302max_completion_tokens=256,
303max_prompt_tokens=256,
baa9f07fRobert Craigie2 years ago304metadata={},
bf1ca86cRobert Craigie1 years ago305model="gpt-4o",
7399ffc8Stainless Bot2 years ago306parallel_tool_calls=True,
bf1ca86cRobert Craigie1 years ago307response_format="auto",
5429f696Stainless Bot2 years ago308stream=False,
27a4626aStainless Bot2 years ago309temperature=1,
baa9f07fRobert Craigie2 years ago310thread={
311"messages": [
312{
79a0b401Stainless Bot2 years ago313"content": "string",
092a8df7Stainless Bot1 years ago314"role": "user",
5b20698dStainless Bot2 years ago315"attachments": [
316{
317"file_id": "string",
f73996b7Stainless Bot2 years ago318"tools": [
319{"type": "code_interpreter"},
320{"type": "code_interpreter"},
321{"type": "code_interpreter"},
322],
5b20698dStainless Bot2 years ago323},
324{
325"file_id": "string",
f73996b7Stainless Bot2 years ago326"tools": [
327{"type": "code_interpreter"},
328{"type": "code_interpreter"},
329{"type": "code_interpreter"},
330],
5b20698dStainless Bot2 years ago331},
332{
333"file_id": "string",
f73996b7Stainless Bot2 years ago334"tools": [
335{"type": "code_interpreter"},
336{"type": "code_interpreter"},
337{"type": "code_interpreter"},
338],
5b20698dStainless Bot2 years ago339},
340],
baa9f07fRobert Craigie2 years ago341"metadata": {},
342},
343{
79a0b401Stainless Bot2 years ago344"content": "string",
092a8df7Stainless Bot1 years ago345"role": "user",
5b20698dStainless Bot2 years ago346"attachments": [
347{
348"file_id": "string",
f73996b7Stainless Bot2 years ago349"tools": [
350{"type": "code_interpreter"},
351{"type": "code_interpreter"},
352{"type": "code_interpreter"},
353],
5b20698dStainless Bot2 years ago354},
355{
356"file_id": "string",
f73996b7Stainless Bot2 years ago357"tools": [
358{"type": "code_interpreter"},
359{"type": "code_interpreter"},
360{"type": "code_interpreter"},
361],
5b20698dStainless Bot2 years ago362},
363{
364"file_id": "string",
f73996b7Stainless Bot2 years ago365"tools": [
366{"type": "code_interpreter"},
367{"type": "code_interpreter"},
368{"type": "code_interpreter"},
369],
5b20698dStainless Bot2 years ago370},
371],
baa9f07fRobert Craigie2 years ago372"metadata": {},
373},
374{
79a0b401Stainless Bot2 years ago375"content": "string",
092a8df7Stainless Bot1 years ago376"role": "user",
5b20698dStainless Bot2 years ago377"attachments": [
378{
379"file_id": "string",
f73996b7Stainless Bot2 years ago380"tools": [
381{"type": "code_interpreter"},
382{"type": "code_interpreter"},
383{"type": "code_interpreter"},
384],
5b20698dStainless Bot2 years ago385},
386{
387"file_id": "string",
f73996b7Stainless Bot2 years ago388"tools": [
389{"type": "code_interpreter"},
390{"type": "code_interpreter"},
391{"type": "code_interpreter"},
392],
5b20698dStainless Bot2 years ago393},
394{
395"file_id": "string",
f73996b7Stainless Bot2 years ago396"tools": [
397{"type": "code_interpreter"},
398{"type": "code_interpreter"},
399{"type": "code_interpreter"},
400],
5b20698dStainless Bot2 years ago401},
402],
baa9f07fRobert Craigie2 years ago403"metadata": {},
404},
405],
092a8df7Stainless Bot1 years ago406"metadata": {},
5b20698dStainless Bot2 years ago407"tool_resources": {
408"code_interpreter": {"file_ids": ["string", "string", "string"]},
409"file_search": {
410"vector_store_ids": ["string"],
411"vector_stores": [
412{
1ff30bf5Stainless Bot2 years ago413"chunking_strategy": {"type": "auto"},
092a8df7Stainless Bot1 years ago414"file_ids": ["string", "string", "string"],
5b20698dStainless Bot2 years ago415"metadata": {},
416}
417],
418},
419},
baa9f07fRobert Craigie2 years ago420},
f5247e30Stainless Bot2 years ago421tool_choice="none",
5b20698dStainless Bot2 years ago422tool_resources={
423"code_interpreter": {"file_ids": ["string", "string", "string"]},
424"file_search": {"vector_store_ids": ["string"]},
425},
baa9f07fRobert Craigie2 years ago426tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
5b20698dStainless Bot2 years ago427top_p=1,
f5247e30Stainless Bot2 years ago428truncation_strategy={
429"type": "auto",
430"last_messages": 1,
431},
baa9f07fRobert Craigie2 years ago432)
433assert_matches_type(Run, thread, path=["response"])
434
435@parametrize
5429f696Stainless Bot2 years ago436def test_raw_response_create_and_run_overload_1(self, client: OpenAI) -> None:
baa9f07fRobert Craigie2 years ago437response = client.beta.threads.with_raw_response.create_and_run(
438assistant_id="string",
439)
86379b44Stainless Bot2 years ago440
441assert response.is_closed is True
baa9f07fRobert Craigie2 years ago442assert response.http_request.headers.get("X-Stainless-Lang") == "python"
443thread = response.parse()
444assert_matches_type(Run, thread, path=["response"])
445
86379b44Stainless Bot2 years ago446@parametrize
5429f696Stainless Bot2 years ago447def test_streaming_response_create_and_run_overload_1(self, client: OpenAI) -> None:
86379b44Stainless Bot2 years ago448with client.beta.threads.with_streaming_response.create_and_run(
449assistant_id="string",
450) as response:
451assert not response.is_closed
452assert response.http_request.headers.get("X-Stainless-Lang") == "python"
453
454thread = response.parse()
455assert_matches_type(Run, thread, path=["response"])
456
457assert cast(Any, response.is_closed) is True
458
5429f696Stainless Bot2 years ago459@parametrize
460def test_method_create_and_run_overload_2(self, client: OpenAI) -> None:
461thread_stream = client.beta.threads.create_and_run(
462assistant_id="string",
463stream=True,
464)
465thread_stream.response.close()
466
467@parametrize
468def test_method_create_and_run_with_all_params_overload_2(self, client: OpenAI) -> None:
469thread_stream = client.beta.threads.create_and_run(
470assistant_id="string",
471stream=True,
472instructions="string",
f5247e30Stainless Bot2 years ago473max_completion_tokens=256,
474max_prompt_tokens=256,
5429f696Stainless Bot2 years ago475metadata={},
bf1ca86cRobert Craigie1 years ago476model="gpt-4o",
7399ffc8Stainless Bot2 years ago477parallel_tool_calls=True,
bf1ca86cRobert Craigie1 years ago478response_format="auto",
27a4626aStainless Bot2 years ago479temperature=1,
5429f696Stainless Bot2 years ago480thread={
481"messages": [
482{
79a0b401Stainless Bot2 years ago483"content": "string",
092a8df7Stainless Bot1 years ago484"role": "user",
5b20698dStainless Bot2 years ago485"attachments": [
486{
487"file_id": "string",
f73996b7Stainless Bot2 years ago488"tools": [
489{"type": "code_interpreter"},
490{"type": "code_interpreter"},
491{"type": "code_interpreter"},
492],
5b20698dStainless Bot2 years ago493},
494{
495"file_id": "string",
f73996b7Stainless Bot2 years ago496"tools": [
497{"type": "code_interpreter"},
498{"type": "code_interpreter"},
499{"type": "code_interpreter"},
500],
5b20698dStainless Bot2 years ago501},
502{
503"file_id": "string",
f73996b7Stainless Bot2 years ago504"tools": [
505{"type": "code_interpreter"},
506{"type": "code_interpreter"},
507{"type": "code_interpreter"},
508],
5b20698dStainless Bot2 years ago509},
510],
5429f696Stainless Bot2 years ago511"metadata": {},
512},
513{
79a0b401Stainless Bot2 years ago514"content": "string",
092a8df7Stainless Bot1 years ago515"role": "user",
5b20698dStainless Bot2 years ago516"attachments": [
517{
518"file_id": "string",
f73996b7Stainless Bot2 years ago519"tools": [
520{"type": "code_interpreter"},
521{"type": "code_interpreter"},
522{"type": "code_interpreter"},
523],
5b20698dStainless Bot2 years ago524},
525{
526"file_id": "string",
f73996b7Stainless Bot2 years ago527"tools": [
528{"type": "code_interpreter"},
529{"type": "code_interpreter"},
530{"type": "code_interpreter"},
531],
5b20698dStainless Bot2 years ago532},
533{
534"file_id": "string",
f73996b7Stainless Bot2 years ago535"tools": [
536{"type": "code_interpreter"},
537{"type": "code_interpreter"},
538{"type": "code_interpreter"},
539],
5b20698dStainless Bot2 years ago540},
541],
5429f696Stainless Bot2 years ago542"metadata": {},
543},
544{
79a0b401Stainless Bot2 years ago545"content": "string",
092a8df7Stainless Bot1 years ago546"role": "user",
5b20698dStainless Bot2 years ago547"attachments": [
548{
549"file_id": "string",
f73996b7Stainless Bot2 years ago550"tools": [
551{"type": "code_interpreter"},
552{"type": "code_interpreter"},
553{"type": "code_interpreter"},
554],
5b20698dStainless Bot2 years ago555},
556{
557"file_id": "string",
f73996b7Stainless Bot2 years ago558"tools": [
559{"type": "code_interpreter"},
560{"type": "code_interpreter"},
561{"type": "code_interpreter"},
562],
5b20698dStainless Bot2 years ago563},
564{
565"file_id": "string",
f73996b7Stainless Bot2 years ago566"tools": [
567{"type": "code_interpreter"},
568{"type": "code_interpreter"},
569{"type": "code_interpreter"},
570],
5b20698dStainless Bot2 years ago571},
572],
5429f696Stainless Bot2 years ago573"metadata": {},
574},
575],
092a8df7Stainless Bot1 years ago576"metadata": {},
5b20698dStainless Bot2 years ago577"tool_resources": {
578"code_interpreter": {"file_ids": ["string", "string", "string"]},
579"file_search": {
580"vector_store_ids": ["string"],
581"vector_stores": [
582{
1ff30bf5Stainless Bot2 years ago583"chunking_strategy": {"type": "auto"},
092a8df7Stainless Bot1 years ago584"file_ids": ["string", "string", "string"],
5b20698dStainless Bot2 years ago585"metadata": {},
586}
587],
588},
589},
5429f696Stainless Bot2 years ago590},
f5247e30Stainless Bot2 years ago591tool_choice="none",
5b20698dStainless Bot2 years ago592tool_resources={
593"code_interpreter": {"file_ids": ["string", "string", "string"]},
594"file_search": {"vector_store_ids": ["string"]},
595},
5429f696Stainless Bot2 years ago596tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
5b20698dStainless Bot2 years ago597top_p=1,
f5247e30Stainless Bot2 years ago598truncation_strategy={
599"type": "auto",
600"last_messages": 1,
601},
5429f696Stainless Bot2 years ago602)
603thread_stream.response.close()
604
605@parametrize
606def test_raw_response_create_and_run_overload_2(self, client: OpenAI) -> None:
607response = client.beta.threads.with_raw_response.create_and_run(
608assistant_id="string",
609stream=True,
610)
611
612assert response.http_request.headers.get("X-Stainless-Lang") == "python"
613stream = response.parse()
614stream.close()
615
616@parametrize
617def test_streaming_response_create_and_run_overload_2(self, client: OpenAI) -> None:
618with client.beta.threads.with_streaming_response.create_and_run(
619assistant_id="string",
620stream=True,
621) as response:
622assert not response.is_closed
623assert response.http_request.headers.get("X-Stainless-Lang") == "python"
624
625stream = response.parse()
626stream.close()
627
628assert cast(Any, response.is_closed) is True
629
baa9f07fRobert Craigie2 years ago630
631class TestAsyncThreads:
98d779fbStainless Bot2 years ago632parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
baa9f07fRobert Craigie2 years ago633
634@parametrize
98d779fbStainless Bot2 years ago635async def test_method_create(self, async_client: AsyncOpenAI) -> None:
636thread = await async_client.beta.threads.create()
baa9f07fRobert Craigie2 years ago637assert_matches_type(Thread, thread, path=["response"])
638
639@parametrize
98d779fbStainless Bot2 years ago640async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
641thread = await async_client.beta.threads.create(
baa9f07fRobert Craigie2 years ago642messages=[
643{
79a0b401Stainless Bot2 years ago644"content": "string",
092a8df7Stainless Bot1 years ago645"role": "user",
5b20698dStainless Bot2 years ago646"attachments": [
647{
648"file_id": "string",
f73996b7Stainless Bot2 years ago649"tools": [
650{"type": "code_interpreter"},
651{"type": "code_interpreter"},
652{"type": "code_interpreter"},
653],
5b20698dStainless Bot2 years ago654},
655{
656"file_id": "string",
f73996b7Stainless Bot2 years ago657"tools": [
658{"type": "code_interpreter"},
659{"type": "code_interpreter"},
660{"type": "code_interpreter"},
661],
5b20698dStainless Bot2 years ago662},
663{
664"file_id": "string",
f73996b7Stainless Bot2 years ago665"tools": [
666{"type": "code_interpreter"},
667{"type": "code_interpreter"},
668{"type": "code_interpreter"},
669],
5b20698dStainless Bot2 years ago670},
671],
baa9f07fRobert Craigie2 years ago672"metadata": {},
673},
674{
79a0b401Stainless Bot2 years ago675"content": "string",
092a8df7Stainless Bot1 years ago676"role": "user",
5b20698dStainless Bot2 years ago677"attachments": [
678{
679"file_id": "string",
f73996b7Stainless Bot2 years ago680"tools": [
681{"type": "code_interpreter"},
682{"type": "code_interpreter"},
683{"type": "code_interpreter"},
684],
5b20698dStainless Bot2 years ago685},
686{
687"file_id": "string",
f73996b7Stainless Bot2 years ago688"tools": [
689{"type": "code_interpreter"},
690{"type": "code_interpreter"},
691{"type": "code_interpreter"},
692],
5b20698dStainless Bot2 years ago693},
694{
695"file_id": "string",
f73996b7Stainless Bot2 years ago696"tools": [
697{"type": "code_interpreter"},
698{"type": "code_interpreter"},
699{"type": "code_interpreter"},
700],
5b20698dStainless Bot2 years ago701},
702],
baa9f07fRobert Craigie2 years ago703"metadata": {},
704},
705{
79a0b401Stainless Bot2 years ago706"content": "string",
092a8df7Stainless Bot1 years ago707"role": "user",
5b20698dStainless Bot2 years ago708"attachments": [
709{
710"file_id": "string",
f73996b7Stainless Bot2 years ago711"tools": [
712{"type": "code_interpreter"},
713{"type": "code_interpreter"},
714{"type": "code_interpreter"},
715],
5b20698dStainless Bot2 years ago716},
717{
718"file_id": "string",
f73996b7Stainless Bot2 years ago719"tools": [
720{"type": "code_interpreter"},
721{"type": "code_interpreter"},
722{"type": "code_interpreter"},
723],
5b20698dStainless Bot2 years ago724},
725{
726"file_id": "string",
f73996b7Stainless Bot2 years ago727"tools": [
728{"type": "code_interpreter"},
729{"type": "code_interpreter"},
730{"type": "code_interpreter"},
731],
5b20698dStainless Bot2 years ago732},
733],
baa9f07fRobert Craigie2 years ago734"metadata": {},
735},
736],
737metadata={},
5b20698dStainless Bot2 years ago738tool_resources={
739"code_interpreter": {"file_ids": ["string", "string", "string"]},
740"file_search": {
741"vector_store_ids": ["string"],
742"vector_stores": [
743{
1ff30bf5Stainless Bot2 years ago744"chunking_strategy": {"type": "auto"},
092a8df7Stainless Bot1 years ago745"file_ids": ["string", "string", "string"],
5b20698dStainless Bot2 years ago746"metadata": {},
747}
748],
749},
750},
baa9f07fRobert Craigie2 years ago751)
752assert_matches_type(Thread, thread, path=["response"])
753
754@parametrize
98d779fbStainless Bot2 years ago755async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
756response = await async_client.beta.threads.with_raw_response.create()
86379b44Stainless Bot2 years ago757
758assert response.is_closed is True
baa9f07fRobert Craigie2 years ago759assert response.http_request.headers.get("X-Stainless-Lang") == "python"
760thread = response.parse()
761assert_matches_type(Thread, thread, path=["response"])
762
86379b44Stainless Bot2 years ago763@parametrize
98d779fbStainless Bot2 years ago764async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
765async with async_client.beta.threads.with_streaming_response.create() as response:
86379b44Stainless Bot2 years ago766assert not response.is_closed
767assert response.http_request.headers.get("X-Stainless-Lang") == "python"
768
769thread = await response.parse()
770assert_matches_type(Thread, thread, path=["response"])
771
772assert cast(Any, response.is_closed) is True
773
baa9f07fRobert Craigie2 years ago774@parametrize
98d779fbStainless Bot2 years ago775async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
776thread = await async_client.beta.threads.retrieve(
baa9f07fRobert Craigie2 years ago777"string",
778)
779assert_matches_type(Thread, thread, path=["response"])
780
781@parametrize
98d779fbStainless Bot2 years ago782async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
783response = await async_client.beta.threads.with_raw_response.retrieve(
baa9f07fRobert Craigie2 years ago784"string",
785)
86379b44Stainless Bot2 years ago786
787assert response.is_closed is True
baa9f07fRobert Craigie2 years ago788assert response.http_request.headers.get("X-Stainless-Lang") == "python"
789thread = response.parse()
790assert_matches_type(Thread, thread, path=["response"])
791
86379b44Stainless Bot2 years ago792@parametrize
98d779fbStainless Bot2 years ago793async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
794async with async_client.beta.threads.with_streaming_response.retrieve(
86379b44Stainless Bot2 years ago795"string",
796) as response:
797assert not response.is_closed
798assert response.http_request.headers.get("X-Stainless-Lang") == "python"
799
800thread = await response.parse()
801assert_matches_type(Thread, thread, path=["response"])
802
803assert cast(Any, response.is_closed) is True
804
023a4e66Stainless Bot2 years ago805@parametrize
98d779fbStainless Bot2 years ago806async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago807with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago808await async_client.beta.threads.with_raw_response.retrieve(
023a4e66Stainless Bot2 years ago809"",
810)
811
baa9f07fRobert Craigie2 years ago812@parametrize
98d779fbStainless Bot2 years ago813async def test_method_update(self, async_client: AsyncOpenAI) -> None:
814thread = await async_client.beta.threads.update(
baa9f07fRobert Craigie2 years ago815"string",
816)
817assert_matches_type(Thread, thread, path=["response"])
818
819@parametrize
98d779fbStainless Bot2 years ago820async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None:
821thread = await async_client.beta.threads.update(
baa9f07fRobert Craigie2 years ago822"string",
823metadata={},
5b20698dStainless Bot2 years ago824tool_resources={
825"code_interpreter": {"file_ids": ["string", "string", "string"]},
826"file_search": {"vector_store_ids": ["string"]},
827},
baa9f07fRobert Craigie2 years ago828)
829assert_matches_type(Thread, thread, path=["response"])
830
831@parametrize
98d779fbStainless Bot2 years ago832async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
833response = await async_client.beta.threads.with_raw_response.update(
baa9f07fRobert Craigie2 years ago834"string",
835)
86379b44Stainless Bot2 years ago836
837assert response.is_closed is True
baa9f07fRobert Craigie2 years ago838assert response.http_request.headers.get("X-Stainless-Lang") == "python"
839thread = response.parse()
840assert_matches_type(Thread, thread, path=["response"])
841
86379b44Stainless Bot2 years ago842@parametrize
98d779fbStainless Bot2 years ago843async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
844async with async_client.beta.threads.with_streaming_response.update(
86379b44Stainless Bot2 years ago845"string",
846) as response:
847assert not response.is_closed
848assert response.http_request.headers.get("X-Stainless-Lang") == "python"
849
850thread = await response.parse()
851assert_matches_type(Thread, thread, path=["response"])
852
853assert cast(Any, response.is_closed) is True
854
023a4e66Stainless Bot2 years ago855@parametrize
98d779fbStainless Bot2 years ago856async def test_path_params_update(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago857with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago858await async_client.beta.threads.with_raw_response.update(
023a4e66Stainless Bot2 years ago859"",
860)
861
baa9f07fRobert Craigie2 years ago862@parametrize
98d779fbStainless Bot2 years ago863async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
864thread = await async_client.beta.threads.delete(
baa9f07fRobert Craigie2 years ago865"string",
866)
867assert_matches_type(ThreadDeleted, thread, path=["response"])
868
869@parametrize
98d779fbStainless Bot2 years ago870async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
871response = await async_client.beta.threads.with_raw_response.delete(
baa9f07fRobert Craigie2 years ago872"string",
873)
86379b44Stainless Bot2 years ago874
875assert response.is_closed is True
baa9f07fRobert Craigie2 years ago876assert response.http_request.headers.get("X-Stainless-Lang") == "python"
877thread = response.parse()
878assert_matches_type(ThreadDeleted, thread, path=["response"])
879
86379b44Stainless Bot2 years ago880@parametrize
98d779fbStainless Bot2 years ago881async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
882async with async_client.beta.threads.with_streaming_response.delete(
86379b44Stainless Bot2 years ago883"string",
884) as response:
885assert not response.is_closed
886assert response.http_request.headers.get("X-Stainless-Lang") == "python"
887
888thread = await response.parse()
889assert_matches_type(ThreadDeleted, thread, path=["response"])
890
891assert cast(Any, response.is_closed) is True
892
023a4e66Stainless Bot2 years ago893@parametrize
98d779fbStainless Bot2 years ago894async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago895with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago896await async_client.beta.threads.with_raw_response.delete(
023a4e66Stainless Bot2 years ago897"",
898)
899
baa9f07fRobert Craigie2 years ago900@parametrize
5429f696Stainless Bot2 years ago901async def test_method_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago902thread = await async_client.beta.threads.create_and_run(
baa9f07fRobert Craigie2 years ago903assistant_id="string",
904)
905assert_matches_type(Run, thread, path=["response"])
906
907@parametrize
5429f696Stainless Bot2 years ago908async def test_method_create_and_run_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago909thread = await async_client.beta.threads.create_and_run(
baa9f07fRobert Craigie2 years ago910assistant_id="string",
911instructions="string",
f5247e30Stainless Bot2 years ago912max_completion_tokens=256,
913max_prompt_tokens=256,
baa9f07fRobert Craigie2 years ago914metadata={},
bf1ca86cRobert Craigie1 years ago915model="gpt-4o",
7399ffc8Stainless Bot2 years ago916parallel_tool_calls=True,
bf1ca86cRobert Craigie1 years ago917response_format="auto",
5429f696Stainless Bot2 years ago918stream=False,
27a4626aStainless Bot2 years ago919temperature=1,
baa9f07fRobert Craigie2 years ago920thread={
921"messages": [
922{
79a0b401Stainless Bot2 years ago923"content": "string",
092a8df7Stainless Bot1 years ago924"role": "user",
5b20698dStainless Bot2 years ago925"attachments": [
926{
927"file_id": "string",
f73996b7Stainless Bot2 years ago928"tools": [
929{"type": "code_interpreter"},
930{"type": "code_interpreter"},
931{"type": "code_interpreter"},
932],
5b20698dStainless Bot2 years ago933},
934{
935"file_id": "string",
f73996b7Stainless Bot2 years ago936"tools": [
937{"type": "code_interpreter"},
938{"type": "code_interpreter"},
939{"type": "code_interpreter"},
940],
5b20698dStainless Bot2 years ago941},
942{
943"file_id": "string",
f73996b7Stainless Bot2 years ago944"tools": [
945{"type": "code_interpreter"},
946{"type": "code_interpreter"},
947{"type": "code_interpreter"},
948],
5b20698dStainless Bot2 years ago949},
950],
baa9f07fRobert Craigie2 years ago951"metadata": {},
952},
953{
79a0b401Stainless Bot2 years ago954"content": "string",
092a8df7Stainless Bot1 years ago955"role": "user",
5b20698dStainless Bot2 years ago956"attachments": [
957{
958"file_id": "string",
f73996b7Stainless Bot2 years ago959"tools": [
960{"type": "code_interpreter"},
961{"type": "code_interpreter"},
962{"type": "code_interpreter"},
963],
5b20698dStainless Bot2 years ago964},
965{
966"file_id": "string",
f73996b7Stainless Bot2 years ago967"tools": [
968{"type": "code_interpreter"},
969{"type": "code_interpreter"},
970{"type": "code_interpreter"},
971],
5b20698dStainless Bot2 years ago972},
973{
974"file_id": "string",
f73996b7Stainless Bot2 years ago975"tools": [
976{"type": "code_interpreter"},
977{"type": "code_interpreter"},
978{"type": "code_interpreter"},
979],
5b20698dStainless Bot2 years ago980},
981],
baa9f07fRobert Craigie2 years ago982"metadata": {},
983},
984{
79a0b401Stainless Bot2 years ago985"content": "string",
092a8df7Stainless Bot1 years ago986"role": "user",
5b20698dStainless Bot2 years ago987"attachments": [
988{
989"file_id": "string",
f73996b7Stainless Bot2 years ago990"tools": [
991{"type": "code_interpreter"},
992{"type": "code_interpreter"},
993{"type": "code_interpreter"},
994],
5b20698dStainless Bot2 years ago995},
996{
997"file_id": "string",
f73996b7Stainless Bot2 years ago998"tools": [
999{"type": "code_interpreter"},
1000{"type": "code_interpreter"},
1001{"type": "code_interpreter"},
1002],
5b20698dStainless Bot2 years ago1003},
1004{
1005"file_id": "string",
f73996b7Stainless Bot2 years ago1006"tools": [
1007{"type": "code_interpreter"},
1008{"type": "code_interpreter"},
1009{"type": "code_interpreter"},
1010],
5b20698dStainless Bot2 years ago1011},
1012],
baa9f07fRobert Craigie2 years ago1013"metadata": {},
1014},
1015],
092a8df7Stainless Bot1 years ago1016"metadata": {},
5b20698dStainless Bot2 years ago1017"tool_resources": {
1018"code_interpreter": {"file_ids": ["string", "string", "string"]},
1019"file_search": {
1020"vector_store_ids": ["string"],
1021"vector_stores": [
1022{
1ff30bf5Stainless Bot2 years ago1023"chunking_strategy": {"type": "auto"},
092a8df7Stainless Bot1 years ago1024"file_ids": ["string", "string", "string"],
5b20698dStainless Bot2 years ago1025"metadata": {},
1026}
1027],
1028},
1029},
baa9f07fRobert Craigie2 years ago1030},
f5247e30Stainless Bot2 years ago1031tool_choice="none",
5b20698dStainless Bot2 years ago1032tool_resources={
1033"code_interpreter": {"file_ids": ["string", "string", "string"]},
1034"file_search": {"vector_store_ids": ["string"]},
1035},
baa9f07fRobert Craigie2 years ago1036tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
5b20698dStainless Bot2 years ago1037top_p=1,
f5247e30Stainless Bot2 years ago1038truncation_strategy={
1039"type": "auto",
1040"last_messages": 1,
1041},
baa9f07fRobert Craigie2 years ago1042)
1043assert_matches_type(Run, thread, path=["response"])
1044
1045@parametrize
5429f696Stainless Bot2 years ago1046async def test_raw_response_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago1047response = await async_client.beta.threads.with_raw_response.create_and_run(
baa9f07fRobert Craigie2 years ago1048assistant_id="string",
1049)
86379b44Stainless Bot2 years ago1050
1051assert response.is_closed is True
baa9f07fRobert Craigie2 years ago1052assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1053thread = response.parse()
1054assert_matches_type(Run, thread, path=["response"])
86379b44Stainless Bot2 years ago1055
1056@parametrize
5429f696Stainless Bot2 years ago1057async def test_streaming_response_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago1058async with async_client.beta.threads.with_streaming_response.create_and_run(
86379b44Stainless Bot2 years ago1059assistant_id="string",
1060) as response:
1061assert not response.is_closed
1062assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1063
1064thread = await response.parse()
1065assert_matches_type(Run, thread, path=["response"])
1066
1067assert cast(Any, response.is_closed) is True
5429f696Stainless Bot2 years ago1068
1069@parametrize
1070async def test_method_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None:
1071thread_stream = await async_client.beta.threads.create_and_run(
1072assistant_id="string",
1073stream=True,
1074)
1075await thread_stream.response.aclose()
1076
1077@parametrize
1078async def test_method_create_and_run_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None:
1079thread_stream = await async_client.beta.threads.create_and_run(
1080assistant_id="string",
1081stream=True,
1082instructions="string",
f5247e30Stainless Bot2 years ago1083max_completion_tokens=256,
1084max_prompt_tokens=256,
5429f696Stainless Bot2 years ago1085metadata={},
bf1ca86cRobert Craigie1 years ago1086model="gpt-4o",
7399ffc8Stainless Bot2 years ago1087parallel_tool_calls=True,
bf1ca86cRobert Craigie1 years ago1088response_format="auto",
27a4626aStainless Bot2 years ago1089temperature=1,
5429f696Stainless Bot2 years ago1090thread={
1091"messages": [
1092{
79a0b401Stainless Bot2 years ago1093"content": "string",
092a8df7Stainless Bot1 years ago1094"role": "user",
5b20698dStainless Bot2 years ago1095"attachments": [
1096{
1097"file_id": "string",
f73996b7Stainless Bot2 years ago1098"tools": [
1099{"type": "code_interpreter"},
1100{"type": "code_interpreter"},
1101{"type": "code_interpreter"},
1102],
5b20698dStainless Bot2 years ago1103},
1104{
1105"file_id": "string",
f73996b7Stainless Bot2 years ago1106"tools": [
1107{"type": "code_interpreter"},
1108{"type": "code_interpreter"},
1109{"type": "code_interpreter"},
1110],
5b20698dStainless Bot2 years ago1111},
1112{
1113"file_id": "string",
f73996b7Stainless Bot2 years ago1114"tools": [
1115{"type": "code_interpreter"},
1116{"type": "code_interpreter"},
1117{"type": "code_interpreter"},
1118],
5b20698dStainless Bot2 years ago1119},
1120],
5429f696Stainless Bot2 years ago1121"metadata": {},
1122},
1123{
79a0b401Stainless Bot2 years ago1124"content": "string",
092a8df7Stainless Bot1 years ago1125"role": "user",
5b20698dStainless Bot2 years ago1126"attachments": [
1127{
1128"file_id": "string",
f73996b7Stainless Bot2 years ago1129"tools": [
1130{"type": "code_interpreter"},
1131{"type": "code_interpreter"},
1132{"type": "code_interpreter"},
1133],
5b20698dStainless Bot2 years ago1134},
1135{
1136"file_id": "string",
f73996b7Stainless Bot2 years ago1137"tools": [
1138{"type": "code_interpreter"},
1139{"type": "code_interpreter"},
1140{"type": "code_interpreter"},
1141],
5b20698dStainless Bot2 years ago1142},
1143{
1144"file_id": "string",
f73996b7Stainless Bot2 years ago1145"tools": [
1146{"type": "code_interpreter"},
1147{"type": "code_interpreter"},
1148{"type": "code_interpreter"},
1149],
5b20698dStainless Bot2 years ago1150},
1151],
5429f696Stainless Bot2 years ago1152"metadata": {},
1153},
1154{
79a0b401Stainless Bot2 years ago1155"content": "string",
092a8df7Stainless Bot1 years ago1156"role": "user",
5b20698dStainless Bot2 years ago1157"attachments": [
1158{
1159"file_id": "string",
f73996b7Stainless Bot2 years ago1160"tools": [
1161{"type": "code_interpreter"},
1162{"type": "code_interpreter"},
1163{"type": "code_interpreter"},
1164],
5b20698dStainless Bot2 years ago1165},
1166{
1167"file_id": "string",
f73996b7Stainless Bot2 years ago1168"tools": [
1169{"type": "code_interpreter"},
1170{"type": "code_interpreter"},
1171{"type": "code_interpreter"},
1172],
5b20698dStainless Bot2 years ago1173},
1174{
1175"file_id": "string",
f73996b7Stainless Bot2 years ago1176"tools": [
1177{"type": "code_interpreter"},
1178{"type": "code_interpreter"},
1179{"type": "code_interpreter"},
1180],
5b20698dStainless Bot2 years ago1181},
1182],
5429f696Stainless Bot2 years ago1183"metadata": {},
1184},
1185],
092a8df7Stainless Bot1 years ago1186"metadata": {},
5b20698dStainless Bot2 years ago1187"tool_resources": {
1188"code_interpreter": {"file_ids": ["string", "string", "string"]},
1189"file_search": {
1190"vector_store_ids": ["string"],
1191"vector_stores": [
1192{
1ff30bf5Stainless Bot2 years ago1193"chunking_strategy": {"type": "auto"},
092a8df7Stainless Bot1 years ago1194"file_ids": ["string", "string", "string"],
5b20698dStainless Bot2 years ago1195"metadata": {},
1196}
1197],
1198},
1199},
5429f696Stainless Bot2 years ago1200},
f5247e30Stainless Bot2 years ago1201tool_choice="none",
5b20698dStainless Bot2 years ago1202tool_resources={
1203"code_interpreter": {"file_ids": ["string", "string", "string"]},
1204"file_search": {"vector_store_ids": ["string"]},
1205},
5429f696Stainless Bot2 years ago1206tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
5b20698dStainless Bot2 years ago1207top_p=1,
f5247e30Stainless Bot2 years ago1208truncation_strategy={
1209"type": "auto",
1210"last_messages": 1,
1211},
5429f696Stainless Bot2 years ago1212)
1213await thread_stream.response.aclose()
1214
1215@parametrize
1216async def test_raw_response_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None:
1217response = await async_client.beta.threads.with_raw_response.create_and_run(
1218assistant_id="string",
1219stream=True,
1220)
1221
1222assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1223stream = response.parse()
1224await stream.close()
1225
1226@parametrize
1227async def test_streaming_response_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None:
1228async with async_client.beta.threads.with_streaming_response.create_and_run(
1229assistant_id="string",
1230stream=True,
1231) as response:
1232assert not response.is_closed
1233assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1234
1235stream = await response.parse()
1236await stream.close()
1237
1238assert cast(Any, response.is_closed) is True