openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.24.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/test_threads.py

1228lines · 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{
34"role": "user",
35"content": "x",
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{
65"role": "user",
66"content": "x",
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{
96"role": "user",
97"content": "x",
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{
134"file_ids": ["string", "string", "string"],
135"metadata": {},
136}
137],
138},
139},
baa9f07fRobert Craigie2 years ago140)
141assert_matches_type(Thread, thread, path=["response"])
142
143@parametrize
144def test_raw_response_create(self, client: OpenAI) -> None:
145response = client.beta.threads.with_raw_response.create()
86379b44Stainless Bot2 years ago146
147assert response.is_closed is True
baa9f07fRobert Craigie2 years ago148assert response.http_request.headers.get("X-Stainless-Lang") == "python"
149thread = response.parse()
150assert_matches_type(Thread, thread, path=["response"])
151
86379b44Stainless Bot2 years ago152@parametrize
153def test_streaming_response_create(self, client: OpenAI) -> None:
154with client.beta.threads.with_streaming_response.create() 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
baa9f07fRobert Craigie2 years ago163@parametrize
164def test_method_retrieve(self, client: OpenAI) -> None:
165thread = client.beta.threads.retrieve(
166"string",
167)
168assert_matches_type(Thread, thread, path=["response"])
169
170@parametrize
171def test_raw_response_retrieve(self, client: OpenAI) -> None:
172response = client.beta.threads.with_raw_response.retrieve(
173"string",
174)
86379b44Stainless Bot2 years ago175
176assert response.is_closed is True
baa9f07fRobert Craigie2 years ago177assert response.http_request.headers.get("X-Stainless-Lang") == "python"
178thread = response.parse()
179assert_matches_type(Thread, thread, path=["response"])
180
86379b44Stainless Bot2 years ago181@parametrize
182def test_streaming_response_retrieve(self, client: OpenAI) -> None:
183with client.beta.threads.with_streaming_response.retrieve(
184"string",
185) as response:
186assert not response.is_closed
187assert response.http_request.headers.get("X-Stainless-Lang") == "python"
188
189thread = response.parse()
190assert_matches_type(Thread, thread, path=["response"])
191
192assert cast(Any, response.is_closed) is True
193
023a4e66Stainless Bot2 years ago194@parametrize
195def test_path_params_retrieve(self, client: OpenAI) -> None:
196with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
197client.beta.threads.with_raw_response.retrieve(
198"",
199)
200
baa9f07fRobert Craigie2 years ago201@parametrize
202def test_method_update(self, client: OpenAI) -> None:
203thread = client.beta.threads.update(
204"string",
205)
206assert_matches_type(Thread, thread, path=["response"])
207
208@parametrize
209def test_method_update_with_all_params(self, client: OpenAI) -> None:
210thread = client.beta.threads.update(
211"string",
212metadata={},
5b20698dStainless Bot2 years ago213tool_resources={
214"code_interpreter": {"file_ids": ["string", "string", "string"]},
215"file_search": {"vector_store_ids": ["string"]},
216},
baa9f07fRobert Craigie2 years ago217)
218assert_matches_type(Thread, thread, path=["response"])
219
220@parametrize
221def test_raw_response_update(self, client: OpenAI) -> None:
222response = client.beta.threads.with_raw_response.update(
223"string",
224)
86379b44Stainless Bot2 years ago225
226assert response.is_closed is True
baa9f07fRobert Craigie2 years ago227assert response.http_request.headers.get("X-Stainless-Lang") == "python"
228thread = response.parse()
229assert_matches_type(Thread, thread, path=["response"])
230
86379b44Stainless Bot2 years ago231@parametrize
232def test_streaming_response_update(self, client: OpenAI) -> None:
233with client.beta.threads.with_streaming_response.update(
234"string",
235) as response:
236assert not response.is_closed
237assert response.http_request.headers.get("X-Stainless-Lang") == "python"
238
239thread = response.parse()
240assert_matches_type(Thread, thread, path=["response"])
241
242assert cast(Any, response.is_closed) is True
243
023a4e66Stainless Bot2 years ago244@parametrize
245def test_path_params_update(self, client: OpenAI) -> None:
246with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
247client.beta.threads.with_raw_response.update(
248"",
249)
250
baa9f07fRobert Craigie2 years ago251@parametrize
252def test_method_delete(self, client: OpenAI) -> None:
253thread = client.beta.threads.delete(
254"string",
255)
256assert_matches_type(ThreadDeleted, thread, path=["response"])
257
258@parametrize
259def test_raw_response_delete(self, client: OpenAI) -> None:
260response = client.beta.threads.with_raw_response.delete(
261"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"
266thread = response.parse()
267assert_matches_type(ThreadDeleted, thread, path=["response"])
268
86379b44Stainless Bot2 years ago269@parametrize
270def test_streaming_response_delete(self, client: OpenAI) -> None:
271with client.beta.threads.with_streaming_response.delete(
272"string",
273) as response:
274assert not response.is_closed
275assert response.http_request.headers.get("X-Stainless-Lang") == "python"
276
277thread = response.parse()
278assert_matches_type(ThreadDeleted, thread, path=["response"])
279
280assert cast(Any, response.is_closed) is True
281
023a4e66Stainless Bot2 years ago282@parametrize
283def test_path_params_delete(self, client: OpenAI) -> None:
284with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
285client.beta.threads.with_raw_response.delete(
286"",
287)
288
baa9f07fRobert Craigie2 years ago289@parametrize
5429f696Stainless Bot2 years ago290def test_method_create_and_run_overload_1(self, client: OpenAI) -> None:
baa9f07fRobert Craigie2 years ago291thread = client.beta.threads.create_and_run(
292assistant_id="string",
293)
294assert_matches_type(Run, thread, path=["response"])
295
296@parametrize
5429f696Stainless Bot2 years ago297def test_method_create_and_run_with_all_params_overload_1(self, client: OpenAI) -> None:
baa9f07fRobert Craigie2 years ago298thread = client.beta.threads.create_and_run(
299assistant_id="string",
300instructions="string",
f5247e30Stainless Bot2 years ago301max_completion_tokens=256,
302max_prompt_tokens=256,
baa9f07fRobert Craigie2 years ago303metadata={},
f5247e30Stainless Bot2 years ago304model="gpt-4-turbo",
305response_format="none",
5429f696Stainless Bot2 years ago306stream=False,
27a4626aStainless Bot2 years ago307temperature=1,
baa9f07fRobert Craigie2 years ago308thread={
309"messages": [
310{
311"role": "user",
312"content": "x",
5b20698dStainless Bot2 years ago313"attachments": [
314{
315"file_id": "string",
f73996b7Stainless Bot2 years ago316"tools": [
317{"type": "code_interpreter"},
318{"type": "code_interpreter"},
319{"type": "code_interpreter"},
320],
5b20698dStainless Bot2 years ago321},
322{
323"file_id": "string",
f73996b7Stainless Bot2 years ago324"tools": [
325{"type": "code_interpreter"},
326{"type": "code_interpreter"},
327{"type": "code_interpreter"},
328],
5b20698dStainless Bot2 years ago329},
330{
331"file_id": "string",
f73996b7Stainless Bot2 years ago332"tools": [
333{"type": "code_interpreter"},
334{"type": "code_interpreter"},
335{"type": "code_interpreter"},
336],
5b20698dStainless Bot2 years ago337},
338],
baa9f07fRobert Craigie2 years ago339"metadata": {},
340},
341{
342"role": "user",
343"content": "x",
5b20698dStainless Bot2 years ago344"attachments": [
345{
346"file_id": "string",
f73996b7Stainless Bot2 years ago347"tools": [
348{"type": "code_interpreter"},
349{"type": "code_interpreter"},
350{"type": "code_interpreter"},
351],
5b20698dStainless Bot2 years ago352},
353{
354"file_id": "string",
f73996b7Stainless Bot2 years ago355"tools": [
356{"type": "code_interpreter"},
357{"type": "code_interpreter"},
358{"type": "code_interpreter"},
359],
5b20698dStainless Bot2 years ago360},
361{
362"file_id": "string",
f73996b7Stainless Bot2 years ago363"tools": [
364{"type": "code_interpreter"},
365{"type": "code_interpreter"},
366{"type": "code_interpreter"},
367],
5b20698dStainless Bot2 years ago368},
369],
baa9f07fRobert Craigie2 years ago370"metadata": {},
371},
372{
373"role": "user",
374"content": "x",
5b20698dStainless Bot2 years ago375"attachments": [
376{
377"file_id": "string",
f73996b7Stainless Bot2 years ago378"tools": [
379{"type": "code_interpreter"},
380{"type": "code_interpreter"},
381{"type": "code_interpreter"},
382],
5b20698dStainless Bot2 years ago383},
384{
385"file_id": "string",
f73996b7Stainless Bot2 years ago386"tools": [
387{"type": "code_interpreter"},
388{"type": "code_interpreter"},
389{"type": "code_interpreter"},
390],
5b20698dStainless Bot2 years ago391},
392{
393"file_id": "string",
f73996b7Stainless Bot2 years ago394"tools": [
395{"type": "code_interpreter"},
396{"type": "code_interpreter"},
397{"type": "code_interpreter"},
398],
5b20698dStainless Bot2 years ago399},
400],
baa9f07fRobert Craigie2 years ago401"metadata": {},
402},
403],
5b20698dStainless Bot2 years ago404"tool_resources": {
405"code_interpreter": {"file_ids": ["string", "string", "string"]},
406"file_search": {
407"vector_store_ids": ["string"],
408"vector_stores": [
409{
410"file_ids": ["string", "string", "string"],
411"metadata": {},
412}
413],
414},
415},
baa9f07fRobert Craigie2 years ago416"metadata": {},
417},
f5247e30Stainless Bot2 years ago418tool_choice="none",
5b20698dStainless Bot2 years ago419tool_resources={
420"code_interpreter": {"file_ids": ["string", "string", "string"]},
421"file_search": {"vector_store_ids": ["string"]},
422},
baa9f07fRobert Craigie2 years ago423tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
5b20698dStainless Bot2 years ago424top_p=1,
f5247e30Stainless Bot2 years ago425truncation_strategy={
426"type": "auto",
427"last_messages": 1,
428},
baa9f07fRobert Craigie2 years ago429)
430assert_matches_type(Run, thread, path=["response"])
431
432@parametrize
5429f696Stainless Bot2 years ago433def test_raw_response_create_and_run_overload_1(self, client: OpenAI) -> None:
baa9f07fRobert Craigie2 years ago434response = client.beta.threads.with_raw_response.create_and_run(
435assistant_id="string",
436)
86379b44Stainless Bot2 years ago437
438assert response.is_closed is True
baa9f07fRobert Craigie2 years ago439assert response.http_request.headers.get("X-Stainless-Lang") == "python"
440thread = response.parse()
441assert_matches_type(Run, thread, path=["response"])
442
86379b44Stainless Bot2 years ago443@parametrize
5429f696Stainless Bot2 years ago444def test_streaming_response_create_and_run_overload_1(self, client: OpenAI) -> None:
86379b44Stainless Bot2 years ago445with client.beta.threads.with_streaming_response.create_and_run(
446assistant_id="string",
447) as response:
448assert not response.is_closed
449assert response.http_request.headers.get("X-Stainless-Lang") == "python"
450
451thread = response.parse()
452assert_matches_type(Run, thread, path=["response"])
453
454assert cast(Any, response.is_closed) is True
455
5429f696Stainless Bot2 years ago456@parametrize
457def test_method_create_and_run_overload_2(self, client: OpenAI) -> None:
458thread_stream = client.beta.threads.create_and_run(
459assistant_id="string",
460stream=True,
461)
462thread_stream.response.close()
463
464@parametrize
465def test_method_create_and_run_with_all_params_overload_2(self, client: OpenAI) -> None:
466thread_stream = client.beta.threads.create_and_run(
467assistant_id="string",
468stream=True,
469instructions="string",
f5247e30Stainless Bot2 years ago470max_completion_tokens=256,
471max_prompt_tokens=256,
5429f696Stainless Bot2 years ago472metadata={},
f5247e30Stainless Bot2 years ago473model="gpt-4-turbo",
474response_format="none",
27a4626aStainless Bot2 years ago475temperature=1,
5429f696Stainless Bot2 years ago476thread={
477"messages": [
478{
479"role": "user",
480"content": "x",
5b20698dStainless Bot2 years ago481"attachments": [
482{
483"file_id": "string",
f73996b7Stainless Bot2 years ago484"tools": [
485{"type": "code_interpreter"},
486{"type": "code_interpreter"},
487{"type": "code_interpreter"},
488],
5b20698dStainless Bot2 years ago489},
490{
491"file_id": "string",
f73996b7Stainless Bot2 years ago492"tools": [
493{"type": "code_interpreter"},
494{"type": "code_interpreter"},
495{"type": "code_interpreter"},
496],
5b20698dStainless Bot2 years ago497},
498{
499"file_id": "string",
f73996b7Stainless Bot2 years ago500"tools": [
501{"type": "code_interpreter"},
502{"type": "code_interpreter"},
503{"type": "code_interpreter"},
504],
5b20698dStainless Bot2 years ago505},
506],
5429f696Stainless Bot2 years ago507"metadata": {},
508},
509{
510"role": "user",
511"content": "x",
5b20698dStainless Bot2 years ago512"attachments": [
513{
514"file_id": "string",
f73996b7Stainless Bot2 years ago515"tools": [
516{"type": "code_interpreter"},
517{"type": "code_interpreter"},
518{"type": "code_interpreter"},
519],
5b20698dStainless Bot2 years ago520},
521{
522"file_id": "string",
f73996b7Stainless Bot2 years ago523"tools": [
524{"type": "code_interpreter"},
525{"type": "code_interpreter"},
526{"type": "code_interpreter"},
527],
5b20698dStainless Bot2 years ago528},
529{
530"file_id": "string",
f73996b7Stainless Bot2 years ago531"tools": [
532{"type": "code_interpreter"},
533{"type": "code_interpreter"},
534{"type": "code_interpreter"},
535],
5b20698dStainless Bot2 years ago536},
537],
5429f696Stainless Bot2 years ago538"metadata": {},
539},
540{
541"role": "user",
542"content": "x",
5b20698dStainless Bot2 years ago543"attachments": [
544{
545"file_id": "string",
f73996b7Stainless Bot2 years ago546"tools": [
547{"type": "code_interpreter"},
548{"type": "code_interpreter"},
549{"type": "code_interpreter"},
550],
5b20698dStainless Bot2 years ago551},
552{
553"file_id": "string",
f73996b7Stainless Bot2 years ago554"tools": [
555{"type": "code_interpreter"},
556{"type": "code_interpreter"},
557{"type": "code_interpreter"},
558],
5b20698dStainless Bot2 years ago559},
560{
561"file_id": "string",
f73996b7Stainless Bot2 years ago562"tools": [
563{"type": "code_interpreter"},
564{"type": "code_interpreter"},
565{"type": "code_interpreter"},
566],
5b20698dStainless Bot2 years ago567},
568],
5429f696Stainless Bot2 years ago569"metadata": {},
570},
571],
5b20698dStainless Bot2 years ago572"tool_resources": {
573"code_interpreter": {"file_ids": ["string", "string", "string"]},
574"file_search": {
575"vector_store_ids": ["string"],
576"vector_stores": [
577{
578"file_ids": ["string", "string", "string"],
579"metadata": {},
580}
581],
582},
583},
5429f696Stainless Bot2 years ago584"metadata": {},
585},
f5247e30Stainless Bot2 years ago586tool_choice="none",
5b20698dStainless Bot2 years ago587tool_resources={
588"code_interpreter": {"file_ids": ["string", "string", "string"]},
589"file_search": {"vector_store_ids": ["string"]},
590},
5429f696Stainless Bot2 years ago591tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
5b20698dStainless Bot2 years ago592top_p=1,
f5247e30Stainless Bot2 years ago593truncation_strategy={
594"type": "auto",
595"last_messages": 1,
596},
5429f696Stainless Bot2 years ago597)
598thread_stream.response.close()
599
600@parametrize
601def test_raw_response_create_and_run_overload_2(self, client: OpenAI) -> None:
602response = client.beta.threads.with_raw_response.create_and_run(
603assistant_id="string",
604stream=True,
605)
606
607assert response.http_request.headers.get("X-Stainless-Lang") == "python"
608stream = response.parse()
609stream.close()
610
611@parametrize
612def test_streaming_response_create_and_run_overload_2(self, client: OpenAI) -> None:
613with client.beta.threads.with_streaming_response.create_and_run(
614assistant_id="string",
615stream=True,
616) as response:
617assert not response.is_closed
618assert response.http_request.headers.get("X-Stainless-Lang") == "python"
619
620stream = response.parse()
621stream.close()
622
623assert cast(Any, response.is_closed) is True
624
baa9f07fRobert Craigie2 years ago625
626class TestAsyncThreads:
98d779fbStainless Bot2 years ago627parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
baa9f07fRobert Craigie2 years ago628
629@parametrize
98d779fbStainless Bot2 years ago630async def test_method_create(self, async_client: AsyncOpenAI) -> None:
631thread = await async_client.beta.threads.create()
baa9f07fRobert Craigie2 years ago632assert_matches_type(Thread, thread, path=["response"])
633
634@parametrize
98d779fbStainless Bot2 years ago635async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
636thread = await async_client.beta.threads.create(
baa9f07fRobert Craigie2 years ago637messages=[
638{
639"role": "user",
640"content": "x",
5b20698dStainless Bot2 years ago641"attachments": [
642{
643"file_id": "string",
f73996b7Stainless Bot2 years ago644"tools": [
645{"type": "code_interpreter"},
646{"type": "code_interpreter"},
647{"type": "code_interpreter"},
648],
5b20698dStainless Bot2 years ago649},
650{
651"file_id": "string",
f73996b7Stainless Bot2 years ago652"tools": [
653{"type": "code_interpreter"},
654{"type": "code_interpreter"},
655{"type": "code_interpreter"},
656],
5b20698dStainless Bot2 years ago657},
658{
659"file_id": "string",
f73996b7Stainless Bot2 years ago660"tools": [
661{"type": "code_interpreter"},
662{"type": "code_interpreter"},
663{"type": "code_interpreter"},
664],
5b20698dStainless Bot2 years ago665},
666],
baa9f07fRobert Craigie2 years ago667"metadata": {},
668},
669{
670"role": "user",
671"content": "x",
5b20698dStainless Bot2 years ago672"attachments": [
673{
674"file_id": "string",
f73996b7Stainless Bot2 years ago675"tools": [
676{"type": "code_interpreter"},
677{"type": "code_interpreter"},
678{"type": "code_interpreter"},
679],
5b20698dStainless Bot2 years ago680},
681{
682"file_id": "string",
f73996b7Stainless Bot2 years ago683"tools": [
684{"type": "code_interpreter"},
685{"type": "code_interpreter"},
686{"type": "code_interpreter"},
687],
5b20698dStainless Bot2 years ago688},
689{
690"file_id": "string",
f73996b7Stainless Bot2 years ago691"tools": [
692{"type": "code_interpreter"},
693{"type": "code_interpreter"},
694{"type": "code_interpreter"},
695],
5b20698dStainless Bot2 years ago696},
697],
baa9f07fRobert Craigie2 years ago698"metadata": {},
699},
700{
701"role": "user",
702"content": "x",
5b20698dStainless Bot2 years ago703"attachments": [
704{
705"file_id": "string",
f73996b7Stainless Bot2 years ago706"tools": [
707{"type": "code_interpreter"},
708{"type": "code_interpreter"},
709{"type": "code_interpreter"},
710],
5b20698dStainless Bot2 years ago711},
712{
713"file_id": "string",
f73996b7Stainless Bot2 years ago714"tools": [
715{"type": "code_interpreter"},
716{"type": "code_interpreter"},
717{"type": "code_interpreter"},
718],
5b20698dStainless Bot2 years ago719},
720{
721"file_id": "string",
f73996b7Stainless Bot2 years ago722"tools": [
723{"type": "code_interpreter"},
724{"type": "code_interpreter"},
725{"type": "code_interpreter"},
726],
5b20698dStainless Bot2 years ago727},
728],
baa9f07fRobert Craigie2 years ago729"metadata": {},
730},
731],
732metadata={},
5b20698dStainless Bot2 years ago733tool_resources={
734"code_interpreter": {"file_ids": ["string", "string", "string"]},
735"file_search": {
736"vector_store_ids": ["string"],
737"vector_stores": [
738{
739"file_ids": ["string", "string", "string"],
740"metadata": {},
741}
742],
743},
744},
baa9f07fRobert Craigie2 years ago745)
746assert_matches_type(Thread, thread, path=["response"])
747
748@parametrize
98d779fbStainless Bot2 years ago749async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
750response = await async_client.beta.threads.with_raw_response.create()
86379b44Stainless Bot2 years ago751
752assert response.is_closed is True
baa9f07fRobert Craigie2 years ago753assert response.http_request.headers.get("X-Stainless-Lang") == "python"
754thread = response.parse()
755assert_matches_type(Thread, thread, path=["response"])
756
86379b44Stainless Bot2 years ago757@parametrize
98d779fbStainless Bot2 years ago758async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
759async with async_client.beta.threads.with_streaming_response.create() as response:
86379b44Stainless Bot2 years ago760assert not response.is_closed
761assert response.http_request.headers.get("X-Stainless-Lang") == "python"
762
763thread = await response.parse()
764assert_matches_type(Thread, thread, path=["response"])
765
766assert cast(Any, response.is_closed) is True
767
baa9f07fRobert Craigie2 years ago768@parametrize
98d779fbStainless Bot2 years ago769async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
770thread = await async_client.beta.threads.retrieve(
baa9f07fRobert Craigie2 years ago771"string",
772)
773assert_matches_type(Thread, thread, path=["response"])
774
775@parametrize
98d779fbStainless Bot2 years ago776async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
777response = await async_client.beta.threads.with_raw_response.retrieve(
baa9f07fRobert Craigie2 years ago778"string",
779)
86379b44Stainless Bot2 years ago780
781assert response.is_closed is True
baa9f07fRobert Craigie2 years ago782assert response.http_request.headers.get("X-Stainless-Lang") == "python"
783thread = response.parse()
784assert_matches_type(Thread, thread, path=["response"])
785
86379b44Stainless Bot2 years ago786@parametrize
98d779fbStainless Bot2 years ago787async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
788async with async_client.beta.threads.with_streaming_response.retrieve(
86379b44Stainless Bot2 years ago789"string",
790) as response:
791assert not response.is_closed
792assert response.http_request.headers.get("X-Stainless-Lang") == "python"
793
794thread = await response.parse()
795assert_matches_type(Thread, thread, path=["response"])
796
797assert cast(Any, response.is_closed) is True
798
023a4e66Stainless Bot2 years ago799@parametrize
98d779fbStainless Bot2 years ago800async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago801with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago802await async_client.beta.threads.with_raw_response.retrieve(
023a4e66Stainless Bot2 years ago803"",
804)
805
baa9f07fRobert Craigie2 years ago806@parametrize
98d779fbStainless Bot2 years ago807async def test_method_update(self, async_client: AsyncOpenAI) -> None:
808thread = await async_client.beta.threads.update(
baa9f07fRobert Craigie2 years ago809"string",
810)
811assert_matches_type(Thread, thread, path=["response"])
812
813@parametrize
98d779fbStainless Bot2 years ago814async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None:
815thread = await async_client.beta.threads.update(
baa9f07fRobert Craigie2 years ago816"string",
817metadata={},
5b20698dStainless Bot2 years ago818tool_resources={
819"code_interpreter": {"file_ids": ["string", "string", "string"]},
820"file_search": {"vector_store_ids": ["string"]},
821},
baa9f07fRobert Craigie2 years ago822)
823assert_matches_type(Thread, thread, path=["response"])
824
825@parametrize
98d779fbStainless Bot2 years ago826async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
827response = await async_client.beta.threads.with_raw_response.update(
baa9f07fRobert Craigie2 years ago828"string",
829)
86379b44Stainless Bot2 years ago830
831assert response.is_closed is True
baa9f07fRobert Craigie2 years ago832assert response.http_request.headers.get("X-Stainless-Lang") == "python"
833thread = response.parse()
834assert_matches_type(Thread, thread, path=["response"])
835
86379b44Stainless Bot2 years ago836@parametrize
98d779fbStainless Bot2 years ago837async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
838async with async_client.beta.threads.with_streaming_response.update(
86379b44Stainless Bot2 years ago839"string",
840) as response:
841assert not response.is_closed
842assert response.http_request.headers.get("X-Stainless-Lang") == "python"
843
844thread = await response.parse()
845assert_matches_type(Thread, thread, path=["response"])
846
847assert cast(Any, response.is_closed) is True
848
023a4e66Stainless Bot2 years ago849@parametrize
98d779fbStainless Bot2 years ago850async def test_path_params_update(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago851with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago852await async_client.beta.threads.with_raw_response.update(
023a4e66Stainless Bot2 years ago853"",
854)
855
baa9f07fRobert Craigie2 years ago856@parametrize
98d779fbStainless Bot2 years ago857async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
858thread = await async_client.beta.threads.delete(
baa9f07fRobert Craigie2 years ago859"string",
860)
861assert_matches_type(ThreadDeleted, thread, path=["response"])
862
863@parametrize
98d779fbStainless Bot2 years ago864async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
865response = await async_client.beta.threads.with_raw_response.delete(
baa9f07fRobert Craigie2 years ago866"string",
867)
86379b44Stainless Bot2 years ago868
869assert response.is_closed is True
baa9f07fRobert Craigie2 years ago870assert response.http_request.headers.get("X-Stainless-Lang") == "python"
871thread = response.parse()
872assert_matches_type(ThreadDeleted, thread, path=["response"])
873
86379b44Stainless Bot2 years ago874@parametrize
98d779fbStainless Bot2 years ago875async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
876async with async_client.beta.threads.with_streaming_response.delete(
86379b44Stainless Bot2 years ago877"string",
878) as response:
879assert not response.is_closed
880assert response.http_request.headers.get("X-Stainless-Lang") == "python"
881
882thread = await response.parse()
883assert_matches_type(ThreadDeleted, thread, path=["response"])
884
885assert cast(Any, response.is_closed) is True
886
023a4e66Stainless Bot2 years ago887@parametrize
98d779fbStainless Bot2 years ago888async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago889with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago890await async_client.beta.threads.with_raw_response.delete(
023a4e66Stainless Bot2 years ago891"",
892)
893
baa9f07fRobert Craigie2 years ago894@parametrize
5429f696Stainless Bot2 years ago895async def test_method_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago896thread = await async_client.beta.threads.create_and_run(
baa9f07fRobert Craigie2 years ago897assistant_id="string",
898)
899assert_matches_type(Run, thread, path=["response"])
900
901@parametrize
5429f696Stainless Bot2 years ago902async def test_method_create_and_run_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago903thread = await async_client.beta.threads.create_and_run(
baa9f07fRobert Craigie2 years ago904assistant_id="string",
905instructions="string",
f5247e30Stainless Bot2 years ago906max_completion_tokens=256,
907max_prompt_tokens=256,
baa9f07fRobert Craigie2 years ago908metadata={},
f5247e30Stainless Bot2 years ago909model="gpt-4-turbo",
910response_format="none",
5429f696Stainless Bot2 years ago911stream=False,
27a4626aStainless Bot2 years ago912temperature=1,
baa9f07fRobert Craigie2 years ago913thread={
914"messages": [
915{
916"role": "user",
917"content": "x",
5b20698dStainless Bot2 years ago918"attachments": [
919{
920"file_id": "string",
f73996b7Stainless Bot2 years ago921"tools": [
922{"type": "code_interpreter"},
923{"type": "code_interpreter"},
924{"type": "code_interpreter"},
925],
5b20698dStainless Bot2 years ago926},
927{
928"file_id": "string",
f73996b7Stainless Bot2 years ago929"tools": [
930{"type": "code_interpreter"},
931{"type": "code_interpreter"},
932{"type": "code_interpreter"},
933],
5b20698dStainless Bot2 years ago934},
935{
936"file_id": "string",
f73996b7Stainless Bot2 years ago937"tools": [
938{"type": "code_interpreter"},
939{"type": "code_interpreter"},
940{"type": "code_interpreter"},
941],
5b20698dStainless Bot2 years ago942},
943],
baa9f07fRobert Craigie2 years ago944"metadata": {},
945},
946{
947"role": "user",
948"content": "x",
5b20698dStainless Bot2 years ago949"attachments": [
950{
951"file_id": "string",
f73996b7Stainless Bot2 years ago952"tools": [
953{"type": "code_interpreter"},
954{"type": "code_interpreter"},
955{"type": "code_interpreter"},
956],
5b20698dStainless Bot2 years ago957},
958{
959"file_id": "string",
f73996b7Stainless Bot2 years ago960"tools": [
961{"type": "code_interpreter"},
962{"type": "code_interpreter"},
963{"type": "code_interpreter"},
964],
5b20698dStainless Bot2 years ago965},
966{
967"file_id": "string",
f73996b7Stainless Bot2 years ago968"tools": [
969{"type": "code_interpreter"},
970{"type": "code_interpreter"},
971{"type": "code_interpreter"},
972],
5b20698dStainless Bot2 years ago973},
974],
baa9f07fRobert Craigie2 years ago975"metadata": {},
976},
977{
978"role": "user",
979"content": "x",
5b20698dStainless Bot2 years ago980"attachments": [
981{
982"file_id": "string",
f73996b7Stainless Bot2 years ago983"tools": [
984{"type": "code_interpreter"},
985{"type": "code_interpreter"},
986{"type": "code_interpreter"},
987],
5b20698dStainless Bot2 years ago988},
989{
990"file_id": "string",
f73996b7Stainless Bot2 years ago991"tools": [
992{"type": "code_interpreter"},
993{"type": "code_interpreter"},
994{"type": "code_interpreter"},
995],
5b20698dStainless Bot2 years ago996},
997{
998"file_id": "string",
f73996b7Stainless Bot2 years ago999"tools": [
1000{"type": "code_interpreter"},
1001{"type": "code_interpreter"},
1002{"type": "code_interpreter"},
1003],
5b20698dStainless Bot2 years ago1004},
1005],
baa9f07fRobert Craigie2 years ago1006"metadata": {},
1007},
1008],
5b20698dStainless Bot2 years ago1009"tool_resources": {
1010"code_interpreter": {"file_ids": ["string", "string", "string"]},
1011"file_search": {
1012"vector_store_ids": ["string"],
1013"vector_stores": [
1014{
1015"file_ids": ["string", "string", "string"],
1016"metadata": {},
1017}
1018],
1019},
1020},
baa9f07fRobert Craigie2 years ago1021"metadata": {},
1022},
f5247e30Stainless Bot2 years ago1023tool_choice="none",
5b20698dStainless Bot2 years ago1024tool_resources={
1025"code_interpreter": {"file_ids": ["string", "string", "string"]},
1026"file_search": {"vector_store_ids": ["string"]},
1027},
baa9f07fRobert Craigie2 years ago1028tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
5b20698dStainless Bot2 years ago1029top_p=1,
f5247e30Stainless Bot2 years ago1030truncation_strategy={
1031"type": "auto",
1032"last_messages": 1,
1033},
baa9f07fRobert Craigie2 years ago1034)
1035assert_matches_type(Run, thread, path=["response"])
1036
1037@parametrize
5429f696Stainless Bot2 years ago1038async def test_raw_response_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago1039response = await async_client.beta.threads.with_raw_response.create_and_run(
baa9f07fRobert Craigie2 years ago1040assistant_id="string",
1041)
86379b44Stainless Bot2 years ago1042
1043assert response.is_closed is True
baa9f07fRobert Craigie2 years ago1044assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1045thread = response.parse()
1046assert_matches_type(Run, thread, path=["response"])
86379b44Stainless Bot2 years ago1047
1048@parametrize
5429f696Stainless Bot2 years ago1049async def test_streaming_response_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago1050async with async_client.beta.threads.with_streaming_response.create_and_run(
86379b44Stainless Bot2 years ago1051assistant_id="string",
1052) as response:
1053assert not response.is_closed
1054assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1055
1056thread = await response.parse()
1057assert_matches_type(Run, thread, path=["response"])
1058
1059assert cast(Any, response.is_closed) is True
5429f696Stainless Bot2 years ago1060
1061@parametrize
1062async def test_method_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None:
1063thread_stream = await async_client.beta.threads.create_and_run(
1064assistant_id="string",
1065stream=True,
1066)
1067await thread_stream.response.aclose()
1068
1069@parametrize
1070async def test_method_create_and_run_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None:
1071thread_stream = await async_client.beta.threads.create_and_run(
1072assistant_id="string",
1073stream=True,
1074instructions="string",
f5247e30Stainless Bot2 years ago1075max_completion_tokens=256,
1076max_prompt_tokens=256,
5429f696Stainless Bot2 years ago1077metadata={},
f5247e30Stainless Bot2 years ago1078model="gpt-4-turbo",
1079response_format="none",
27a4626aStainless Bot2 years ago1080temperature=1,
5429f696Stainless Bot2 years ago1081thread={
1082"messages": [
1083{
1084"role": "user",
1085"content": "x",
5b20698dStainless Bot2 years ago1086"attachments": [
1087{
1088"file_id": "string",
f73996b7Stainless Bot2 years ago1089"tools": [
1090{"type": "code_interpreter"},
1091{"type": "code_interpreter"},
1092{"type": "code_interpreter"},
1093],
5b20698dStainless Bot2 years ago1094},
1095{
1096"file_id": "string",
f73996b7Stainless Bot2 years ago1097"tools": [
1098{"type": "code_interpreter"},
1099{"type": "code_interpreter"},
1100{"type": "code_interpreter"},
1101],
5b20698dStainless Bot2 years ago1102},
1103{
1104"file_id": "string",
f73996b7Stainless Bot2 years ago1105"tools": [
1106{"type": "code_interpreter"},
1107{"type": "code_interpreter"},
1108{"type": "code_interpreter"},
1109],
5b20698dStainless Bot2 years ago1110},
1111],
5429f696Stainless Bot2 years ago1112"metadata": {},
1113},
1114{
1115"role": "user",
1116"content": "x",
5b20698dStainless Bot2 years ago1117"attachments": [
1118{
1119"file_id": "string",
f73996b7Stainless Bot2 years ago1120"tools": [
1121{"type": "code_interpreter"},
1122{"type": "code_interpreter"},
1123{"type": "code_interpreter"},
1124],
5b20698dStainless Bot2 years ago1125},
1126{
1127"file_id": "string",
f73996b7Stainless Bot2 years ago1128"tools": [
1129{"type": "code_interpreter"},
1130{"type": "code_interpreter"},
1131{"type": "code_interpreter"},
1132],
5b20698dStainless Bot2 years ago1133},
1134{
1135"file_id": "string",
f73996b7Stainless Bot2 years ago1136"tools": [
1137{"type": "code_interpreter"},
1138{"type": "code_interpreter"},
1139{"type": "code_interpreter"},
1140],
5b20698dStainless Bot2 years ago1141},
1142],
5429f696Stainless Bot2 years ago1143"metadata": {},
1144},
1145{
1146"role": "user",
1147"content": "x",
5b20698dStainless Bot2 years ago1148"attachments": [
1149{
1150"file_id": "string",
f73996b7Stainless Bot2 years ago1151"tools": [
1152{"type": "code_interpreter"},
1153{"type": "code_interpreter"},
1154{"type": "code_interpreter"},
1155],
5b20698dStainless Bot2 years ago1156},
1157{
1158"file_id": "string",
f73996b7Stainless Bot2 years ago1159"tools": [
1160{"type": "code_interpreter"},
1161{"type": "code_interpreter"},
1162{"type": "code_interpreter"},
1163],
5b20698dStainless Bot2 years ago1164},
1165{
1166"file_id": "string",
f73996b7Stainless Bot2 years ago1167"tools": [
1168{"type": "code_interpreter"},
1169{"type": "code_interpreter"},
1170{"type": "code_interpreter"},
1171],
5b20698dStainless Bot2 years ago1172},
1173],
5429f696Stainless Bot2 years ago1174"metadata": {},
1175},
1176],
5b20698dStainless Bot2 years ago1177"tool_resources": {
1178"code_interpreter": {"file_ids": ["string", "string", "string"]},
1179"file_search": {
1180"vector_store_ids": ["string"],
1181"vector_stores": [
1182{
1183"file_ids": ["string", "string", "string"],
1184"metadata": {},
1185}
1186],
1187},
1188},
5429f696Stainless Bot2 years ago1189"metadata": {},
1190},
f5247e30Stainless Bot2 years ago1191tool_choice="none",
5b20698dStainless Bot2 years ago1192tool_resources={
1193"code_interpreter": {"file_ids": ["string", "string", "string"]},
1194"file_search": {"vector_store_ids": ["string"]},
1195},
5429f696Stainless Bot2 years ago1196tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
5b20698dStainless Bot2 years ago1197top_p=1,
f5247e30Stainless Bot2 years ago1198truncation_strategy={
1199"type": "auto",
1200"last_messages": 1,
1201},
5429f696Stainless Bot2 years ago1202)
1203await thread_stream.response.aclose()
1204
1205@parametrize
1206async def test_raw_response_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None:
1207response = await async_client.beta.threads.with_raw_response.create_and_run(
1208assistant_id="string",
1209stream=True,
1210)
1211
1212assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1213stream = response.parse()
1214await stream.close()
1215
1216@parametrize
1217async def test_streaming_response_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None:
1218async with async_client.beta.threads.with_streaming_response.create_and_run(
1219assistant_id="string",
1220stream=True,
1221) as response:
1222assert not response.is_closed
1223assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1224
1225stream = await response.parse()
1226await stream.close()
1227
1228assert cast(Any, response.is_closed) is True