openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.86.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/test_threads.py

818lines · 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
cca09707stainless-app[bot]1 years ago18# pyright: reportDeprecated=false
19
baa9f07fRobert Craigie2 years ago20base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
21
22
23class TestThreads:
98d779fbStainless Bot2 years ago24parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
baa9f07fRobert Craigie2 years ago25
26@parametrize
27def test_method_create(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago28with pytest.warns(DeprecationWarning):
29thread = client.beta.threads.create()
30
baa9f07fRobert Craigie2 years ago31assert_matches_type(Thread, thread, path=["response"])
32
33@parametrize
34def test_method_create_with_all_params(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago35with pytest.warns(DeprecationWarning):
36thread = client.beta.threads.create(
37messages=[
38{
39"content": "string",
40"role": "user",
41"attachments": [
42{
43"file_id": "file_id",
44"tools": [{"type": "code_interpreter"}],
45}
46],
47"metadata": {"foo": "string"},
48}
49],
50metadata={"foo": "string"},
51tool_resources={
52"code_interpreter": {"file_ids": ["string"]},
53"file_search": {
54"vector_store_ids": ["string"],
55"vector_stores": [
56{
57"chunking_strategy": {"type": "auto"},
58"file_ids": ["string"],
59"metadata": {"foo": "string"},
60}
61],
62},
5b20698dStainless Bot2 years ago63},
cca09707stainless-app[bot]1 years ago64)
65
baa9f07fRobert Craigie2 years ago66assert_matches_type(Thread, thread, path=["response"])
67
68@parametrize
69def test_raw_response_create(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago70with pytest.warns(DeprecationWarning):
71response = client.beta.threads.with_raw_response.create()
86379b44Stainless Bot2 years ago72
73assert response.is_closed is True
baa9f07fRobert Craigie2 years ago74assert response.http_request.headers.get("X-Stainless-Lang") == "python"
75thread = response.parse()
76assert_matches_type(Thread, thread, path=["response"])
77
86379b44Stainless Bot2 years ago78@parametrize
79def test_streaming_response_create(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago80with pytest.warns(DeprecationWarning):
81with client.beta.threads.with_streaming_response.create() as response:
82assert not response.is_closed
83assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago84
cca09707stainless-app[bot]1 years ago85thread = response.parse()
86assert_matches_type(Thread, thread, path=["response"])
86379b44Stainless Bot2 years ago87
88assert cast(Any, response.is_closed) is True
89
baa9f07fRobert Craigie2 years ago90@parametrize
91def test_method_retrieve(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago92with pytest.warns(DeprecationWarning):
93thread = client.beta.threads.retrieve(
94"thread_id",
95)
96
baa9f07fRobert Craigie2 years ago97assert_matches_type(Thread, thread, path=["response"])
98
99@parametrize
100def test_raw_response_retrieve(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago101with pytest.warns(DeprecationWarning):
102response = client.beta.threads.with_raw_response.retrieve(
103"thread_id",
104)
86379b44Stainless Bot2 years ago105
106assert response.is_closed is True
baa9f07fRobert Craigie2 years ago107assert response.http_request.headers.get("X-Stainless-Lang") == "python"
108thread = response.parse()
109assert_matches_type(Thread, thread, path=["response"])
110
86379b44Stainless Bot2 years ago111@parametrize
112def test_streaming_response_retrieve(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago113with pytest.warns(DeprecationWarning):
114with client.beta.threads.with_streaming_response.retrieve(
115"thread_id",
116) as response:
117assert not response.is_closed
118assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago119
cca09707stainless-app[bot]1 years ago120thread = response.parse()
121assert_matches_type(Thread, thread, path=["response"])
86379b44Stainless Bot2 years ago122
123assert cast(Any, response.is_closed) is True
124
023a4e66Stainless Bot2 years ago125@parametrize
126def test_path_params_retrieve(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago127with pytest.warns(DeprecationWarning):
128with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
129client.beta.threads.with_raw_response.retrieve(
130"",
131)
023a4e66Stainless Bot2 years ago132
baa9f07fRobert Craigie2 years ago133@parametrize
134def test_method_update(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago135with pytest.warns(DeprecationWarning):
136thread = client.beta.threads.update(
137thread_id="thread_id",
138)
139
baa9f07fRobert Craigie2 years ago140assert_matches_type(Thread, thread, path=["response"])
141
142@parametrize
143def test_method_update_with_all_params(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago144with pytest.warns(DeprecationWarning):
145thread = client.beta.threads.update(
146thread_id="thread_id",
147metadata={"foo": "string"},
148tool_resources={
149"code_interpreter": {"file_ids": ["string"]},
150"file_search": {"vector_store_ids": ["string"]},
151},
152)
153
baa9f07fRobert Craigie2 years ago154assert_matches_type(Thread, thread, path=["response"])
155
156@parametrize
157def test_raw_response_update(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago158with pytest.warns(DeprecationWarning):
159response = client.beta.threads.with_raw_response.update(
160thread_id="thread_id",
161)
86379b44Stainless Bot2 years ago162
163assert response.is_closed is True
baa9f07fRobert Craigie2 years ago164assert response.http_request.headers.get("X-Stainless-Lang") == "python"
165thread = response.parse()
166assert_matches_type(Thread, thread, path=["response"])
167
86379b44Stainless Bot2 years ago168@parametrize
169def test_streaming_response_update(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago170with pytest.warns(DeprecationWarning):
171with client.beta.threads.with_streaming_response.update(
172thread_id="thread_id",
173) as response:
174assert not response.is_closed
175assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago176
cca09707stainless-app[bot]1 years ago177thread = response.parse()
178assert_matches_type(Thread, thread, path=["response"])
86379b44Stainless Bot2 years ago179
180assert cast(Any, response.is_closed) is True
181
023a4e66Stainless Bot2 years ago182@parametrize
183def test_path_params_update(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago184with pytest.warns(DeprecationWarning):
185with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
186client.beta.threads.with_raw_response.update(
187thread_id="",
188)
023a4e66Stainless Bot2 years ago189
baa9f07fRobert Craigie2 years ago190@parametrize
191def test_method_delete(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago192with pytest.warns(DeprecationWarning):
193thread = client.beta.threads.delete(
194"thread_id",
195)
196
baa9f07fRobert Craigie2 years ago197assert_matches_type(ThreadDeleted, thread, path=["response"])
198
199@parametrize
200def test_raw_response_delete(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago201with pytest.warns(DeprecationWarning):
202response = client.beta.threads.with_raw_response.delete(
203"thread_id",
204)
86379b44Stainless Bot2 years ago205
206assert response.is_closed is True
baa9f07fRobert Craigie2 years ago207assert response.http_request.headers.get("X-Stainless-Lang") == "python"
208thread = response.parse()
209assert_matches_type(ThreadDeleted, thread, path=["response"])
210
86379b44Stainless Bot2 years ago211@parametrize
212def test_streaming_response_delete(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago213with pytest.warns(DeprecationWarning):
214with client.beta.threads.with_streaming_response.delete(
215"thread_id",
216) as response:
217assert not response.is_closed
218assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago219
cca09707stainless-app[bot]1 years ago220thread = response.parse()
221assert_matches_type(ThreadDeleted, thread, path=["response"])
86379b44Stainless Bot2 years ago222
223assert cast(Any, response.is_closed) is True
224
023a4e66Stainless Bot2 years ago225@parametrize
226def test_path_params_delete(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago227with pytest.warns(DeprecationWarning):
228with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
229client.beta.threads.with_raw_response.delete(
230"",
231)
023a4e66Stainless Bot2 years ago232
baa9f07fRobert Craigie2 years ago233@parametrize
5429f696Stainless Bot2 years ago234def test_method_create_and_run_overload_1(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago235with pytest.warns(DeprecationWarning):
236thread = client.beta.threads.create_and_run(
237assistant_id="assistant_id",
238)
239
baa9f07fRobert Craigie2 years ago240assert_matches_type(Run, thread, path=["response"])
241
242@parametrize
5429f696Stainless Bot2 years ago243def test_method_create_and_run_with_all_params_overload_1(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago244with pytest.warns(DeprecationWarning):
245thread = client.beta.threads.create_and_run(
246assistant_id="assistant_id",
247instructions="instructions",
248max_completion_tokens=256,
249max_prompt_tokens=256,
250metadata={"foo": "string"},
251model="string",
252parallel_tool_calls=True,
253response_format="auto",
254stream=False,
255temperature=1,
256thread={
257"messages": [
258{
259"content": "string",
260"role": "user",
261"attachments": [
262{
263"file_id": "file_id",
264"tools": [{"type": "code_interpreter"}],
265}
266],
267"metadata": {"foo": "string"},
268}
269],
270"metadata": {"foo": "string"},
271"tool_resources": {
272"code_interpreter": {"file_ids": ["string"]},
273"file_search": {
274"vector_store_ids": ["string"],
275"vector_stores": [
276{
277"chunking_strategy": {"type": "auto"},
278"file_ids": ["string"],
279"metadata": {"foo": "string"},
280}
281],
282},
5b20698dStainless Bot2 years ago283},
284},
cca09707stainless-app[bot]1 years ago285tool_choice="none",
286tool_resources={
287"code_interpreter": {"file_ids": ["string"]},
288"file_search": {"vector_store_ids": ["string"]},
289},
290tools=[{"type": "code_interpreter"}],
291top_p=1,
292truncation_strategy={
293"type": "auto",
294"last_messages": 1,
295},
296)
297
baa9f07fRobert Craigie2 years ago298assert_matches_type(Run, thread, path=["response"])
299
300@parametrize
5429f696Stainless Bot2 years ago301def test_raw_response_create_and_run_overload_1(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago302with pytest.warns(DeprecationWarning):
303response = client.beta.threads.with_raw_response.create_and_run(
304assistant_id="assistant_id",
305)
86379b44Stainless Bot2 years ago306
307assert response.is_closed is True
baa9f07fRobert Craigie2 years ago308assert response.http_request.headers.get("X-Stainless-Lang") == "python"
309thread = response.parse()
310assert_matches_type(Run, thread, path=["response"])
311
86379b44Stainless Bot2 years ago312@parametrize
5429f696Stainless Bot2 years ago313def test_streaming_response_create_and_run_overload_1(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago314with pytest.warns(DeprecationWarning):
315with client.beta.threads.with_streaming_response.create_and_run(
316assistant_id="assistant_id",
317) as response:
318assert not response.is_closed
319assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago320
cca09707stainless-app[bot]1 years ago321thread = response.parse()
322assert_matches_type(Run, thread, path=["response"])
86379b44Stainless Bot2 years ago323
324assert cast(Any, response.is_closed) is True
325
5429f696Stainless Bot2 years ago326@parametrize
327def test_method_create_and_run_overload_2(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago328with pytest.warns(DeprecationWarning):
329thread_stream = client.beta.threads.create_and_run(
330assistant_id="assistant_id",
331stream=True,
332)
333
5429f696Stainless Bot2 years ago334thread_stream.response.close()
335
336@parametrize
337def test_method_create_and_run_with_all_params_overload_2(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago338with pytest.warns(DeprecationWarning):
339thread_stream = client.beta.threads.create_and_run(
340assistant_id="assistant_id",
341stream=True,
342instructions="instructions",
343max_completion_tokens=256,
344max_prompt_tokens=256,
345metadata={"foo": "string"},
346model="string",
347parallel_tool_calls=True,
348response_format="auto",
349temperature=1,
350thread={
351"messages": [
352{
353"content": "string",
354"role": "user",
355"attachments": [
356{
357"file_id": "file_id",
358"tools": [{"type": "code_interpreter"}],
359}
360],
361"metadata": {"foo": "string"},
362}
363],
364"metadata": {"foo": "string"},
365"tool_resources": {
366"code_interpreter": {"file_ids": ["string"]},
367"file_search": {
368"vector_store_ids": ["string"],
369"vector_stores": [
370{
371"chunking_strategy": {"type": "auto"},
372"file_ids": ["string"],
373"metadata": {"foo": "string"},
374}
375],
376},
5b20698dStainless Bot2 years ago377},
378},
cca09707stainless-app[bot]1 years ago379tool_choice="none",
380tool_resources={
381"code_interpreter": {"file_ids": ["string"]},
382"file_search": {"vector_store_ids": ["string"]},
383},
384tools=[{"type": "code_interpreter"}],
385top_p=1,
386truncation_strategy={
387"type": "auto",
388"last_messages": 1,
389},
390)
391
5429f696Stainless Bot2 years ago392thread_stream.response.close()
393
394@parametrize
395def test_raw_response_create_and_run_overload_2(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago396with pytest.warns(DeprecationWarning):
397response = client.beta.threads.with_raw_response.create_and_run(
398assistant_id="assistant_id",
399stream=True,
400)
5429f696Stainless Bot2 years ago401
402assert response.http_request.headers.get("X-Stainless-Lang") == "python"
403stream = response.parse()
404stream.close()
405
406@parametrize
407def test_streaming_response_create_and_run_overload_2(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago408with pytest.warns(DeprecationWarning):
409with client.beta.threads.with_streaming_response.create_and_run(
410assistant_id="assistant_id",
411stream=True,
412) as response:
413assert not response.is_closed
414assert response.http_request.headers.get("X-Stainless-Lang") == "python"
5429f696Stainless Bot2 years ago415
cca09707stainless-app[bot]1 years ago416stream = response.parse()
417stream.close()
5429f696Stainless Bot2 years ago418
419assert cast(Any, response.is_closed) is True
420
baa9f07fRobert Craigie2 years ago421
422class TestAsyncThreads:
98d779fbStainless Bot2 years ago423parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
baa9f07fRobert Craigie2 years ago424
425@parametrize
98d779fbStainless Bot2 years ago426async def test_method_create(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago427with pytest.warns(DeprecationWarning):
428thread = await async_client.beta.threads.create()
429
baa9f07fRobert Craigie2 years ago430assert_matches_type(Thread, thread, path=["response"])
431
432@parametrize
98d779fbStainless Bot2 years ago433async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago434with pytest.warns(DeprecationWarning):
435thread = await async_client.beta.threads.create(
436messages=[
437{
438"content": "string",
439"role": "user",
440"attachments": [
441{
442"file_id": "file_id",
443"tools": [{"type": "code_interpreter"}],
444}
445],
446"metadata": {"foo": "string"},
447}
448],
449metadata={"foo": "string"},
450tool_resources={
451"code_interpreter": {"file_ids": ["string"]},
452"file_search": {
453"vector_store_ids": ["string"],
454"vector_stores": [
455{
456"chunking_strategy": {"type": "auto"},
457"file_ids": ["string"],
458"metadata": {"foo": "string"},
459}
460],
461},
5b20698dStainless Bot2 years ago462},
cca09707stainless-app[bot]1 years ago463)
464
baa9f07fRobert Craigie2 years ago465assert_matches_type(Thread, thread, path=["response"])
466
467@parametrize
98d779fbStainless Bot2 years ago468async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago469with pytest.warns(DeprecationWarning):
470response = await async_client.beta.threads.with_raw_response.create()
86379b44Stainless Bot2 years ago471
472assert response.is_closed is True
baa9f07fRobert Craigie2 years ago473assert response.http_request.headers.get("X-Stainless-Lang") == "python"
474thread = response.parse()
475assert_matches_type(Thread, thread, path=["response"])
476
86379b44Stainless Bot2 years ago477@parametrize
98d779fbStainless Bot2 years ago478async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago479with pytest.warns(DeprecationWarning):
480async with async_client.beta.threads.with_streaming_response.create() as response:
481assert not response.is_closed
482assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago483
cca09707stainless-app[bot]1 years ago484thread = await response.parse()
485assert_matches_type(Thread, thread, path=["response"])
86379b44Stainless Bot2 years ago486
487assert cast(Any, response.is_closed) is True
488
baa9f07fRobert Craigie2 years ago489@parametrize
98d779fbStainless Bot2 years ago490async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago491with pytest.warns(DeprecationWarning):
492thread = await async_client.beta.threads.retrieve(
493"thread_id",
494)
495
baa9f07fRobert Craigie2 years ago496assert_matches_type(Thread, thread, path=["response"])
497
498@parametrize
98d779fbStainless Bot2 years ago499async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago500with pytest.warns(DeprecationWarning):
501response = await async_client.beta.threads.with_raw_response.retrieve(
502"thread_id",
503)
86379b44Stainless Bot2 years ago504
505assert response.is_closed is True
baa9f07fRobert Craigie2 years ago506assert response.http_request.headers.get("X-Stainless-Lang") == "python"
507thread = response.parse()
508assert_matches_type(Thread, thread, path=["response"])
509
86379b44Stainless Bot2 years ago510@parametrize
98d779fbStainless Bot2 years ago511async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago512with pytest.warns(DeprecationWarning):
513async with async_client.beta.threads.with_streaming_response.retrieve(
514"thread_id",
515) as response:
516assert not response.is_closed
517assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago518
cca09707stainless-app[bot]1 years ago519thread = await response.parse()
520assert_matches_type(Thread, thread, path=["response"])
86379b44Stainless Bot2 years ago521
522assert cast(Any, response.is_closed) is True
523
023a4e66Stainless Bot2 years ago524@parametrize
98d779fbStainless Bot2 years ago525async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago526with pytest.warns(DeprecationWarning):
527with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
528await async_client.beta.threads.with_raw_response.retrieve(
529"",
530)
023a4e66Stainless Bot2 years ago531
baa9f07fRobert Craigie2 years ago532@parametrize
98d779fbStainless Bot2 years ago533async def test_method_update(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago534with pytest.warns(DeprecationWarning):
535thread = await async_client.beta.threads.update(
536thread_id="thread_id",
537)
538
baa9f07fRobert Craigie2 years ago539assert_matches_type(Thread, thread, path=["response"])
540
541@parametrize
98d779fbStainless Bot2 years ago542async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago543with pytest.warns(DeprecationWarning):
544thread = await async_client.beta.threads.update(
545thread_id="thread_id",
546metadata={"foo": "string"},
547tool_resources={
548"code_interpreter": {"file_ids": ["string"]},
549"file_search": {"vector_store_ids": ["string"]},
550},
551)
552
baa9f07fRobert Craigie2 years ago553assert_matches_type(Thread, thread, path=["response"])
554
555@parametrize
98d779fbStainless Bot2 years ago556async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago557with pytest.warns(DeprecationWarning):
558response = await async_client.beta.threads.with_raw_response.update(
559thread_id="thread_id",
560)
86379b44Stainless Bot2 years ago561
562assert response.is_closed is True
baa9f07fRobert Craigie2 years ago563assert response.http_request.headers.get("X-Stainless-Lang") == "python"
564thread = response.parse()
565assert_matches_type(Thread, thread, path=["response"])
566
86379b44Stainless Bot2 years ago567@parametrize
98d779fbStainless Bot2 years ago568async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago569with pytest.warns(DeprecationWarning):
570async with async_client.beta.threads.with_streaming_response.update(
571thread_id="thread_id",
572) as response:
573assert not response.is_closed
574assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago575
cca09707stainless-app[bot]1 years ago576thread = await response.parse()
577assert_matches_type(Thread, thread, path=["response"])
86379b44Stainless Bot2 years ago578
579assert cast(Any, response.is_closed) is True
580
023a4e66Stainless Bot2 years ago581@parametrize
98d779fbStainless Bot2 years ago582async def test_path_params_update(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago583with pytest.warns(DeprecationWarning):
584with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
585await async_client.beta.threads.with_raw_response.update(
586thread_id="",
587)
023a4e66Stainless Bot2 years ago588
baa9f07fRobert Craigie2 years ago589@parametrize
98d779fbStainless Bot2 years ago590async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago591with pytest.warns(DeprecationWarning):
592thread = await async_client.beta.threads.delete(
593"thread_id",
594)
595
baa9f07fRobert Craigie2 years ago596assert_matches_type(ThreadDeleted, thread, path=["response"])
597
598@parametrize
98d779fbStainless Bot2 years ago599async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago600with pytest.warns(DeprecationWarning):
601response = await async_client.beta.threads.with_raw_response.delete(
602"thread_id",
603)
86379b44Stainless Bot2 years ago604
605assert response.is_closed is True
baa9f07fRobert Craigie2 years ago606assert response.http_request.headers.get("X-Stainless-Lang") == "python"
607thread = response.parse()
608assert_matches_type(ThreadDeleted, thread, path=["response"])
609
86379b44Stainless Bot2 years ago610@parametrize
98d779fbStainless Bot2 years ago611async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago612with pytest.warns(DeprecationWarning):
613async with async_client.beta.threads.with_streaming_response.delete(
614"thread_id",
615) as response:
616assert not response.is_closed
617assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago618
cca09707stainless-app[bot]1 years ago619thread = await response.parse()
620assert_matches_type(ThreadDeleted, thread, path=["response"])
86379b44Stainless Bot2 years ago621
622assert cast(Any, response.is_closed) is True
623
023a4e66Stainless Bot2 years ago624@parametrize
98d779fbStainless Bot2 years ago625async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago626with pytest.warns(DeprecationWarning):
627with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
628await async_client.beta.threads.with_raw_response.delete(
629"",
630)
023a4e66Stainless Bot2 years ago631
baa9f07fRobert Craigie2 years ago632@parametrize
5429f696Stainless Bot2 years ago633async def test_method_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago634with pytest.warns(DeprecationWarning):
635thread = await async_client.beta.threads.create_and_run(
636assistant_id="assistant_id",
637)
638
baa9f07fRobert Craigie2 years ago639assert_matches_type(Run, thread, path=["response"])
640
641@parametrize
5429f696Stainless Bot2 years ago642async def test_method_create_and_run_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago643with pytest.warns(DeprecationWarning):
644thread = await async_client.beta.threads.create_and_run(
645assistant_id="assistant_id",
646instructions="instructions",
647max_completion_tokens=256,
648max_prompt_tokens=256,
649metadata={"foo": "string"},
650model="string",
651parallel_tool_calls=True,
652response_format="auto",
653stream=False,
654temperature=1,
655thread={
656"messages": [
657{
658"content": "string",
659"role": "user",
660"attachments": [
661{
662"file_id": "file_id",
663"tools": [{"type": "code_interpreter"}],
664}
665],
666"metadata": {"foo": "string"},
667}
668],
669"metadata": {"foo": "string"},
670"tool_resources": {
671"code_interpreter": {"file_ids": ["string"]},
672"file_search": {
673"vector_store_ids": ["string"],
674"vector_stores": [
675{
676"chunking_strategy": {"type": "auto"},
677"file_ids": ["string"],
678"metadata": {"foo": "string"},
679}
680],
681},
5b20698dStainless Bot2 years ago682},
683},
cca09707stainless-app[bot]1 years ago684tool_choice="none",
685tool_resources={
686"code_interpreter": {"file_ids": ["string"]},
687"file_search": {"vector_store_ids": ["string"]},
688},
689tools=[{"type": "code_interpreter"}],
690top_p=1,
691truncation_strategy={
692"type": "auto",
693"last_messages": 1,
694},
695)
696
baa9f07fRobert Craigie2 years ago697assert_matches_type(Run, thread, path=["response"])
698
699@parametrize
5429f696Stainless Bot2 years ago700async def test_raw_response_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago701with pytest.warns(DeprecationWarning):
702response = await async_client.beta.threads.with_raw_response.create_and_run(
703assistant_id="assistant_id",
704)
86379b44Stainless Bot2 years ago705
706assert response.is_closed is True
baa9f07fRobert Craigie2 years ago707assert response.http_request.headers.get("X-Stainless-Lang") == "python"
708thread = response.parse()
709assert_matches_type(Run, thread, path=["response"])
86379b44Stainless Bot2 years ago710
711@parametrize
5429f696Stainless Bot2 years ago712async def test_streaming_response_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago713with pytest.warns(DeprecationWarning):
714async with async_client.beta.threads.with_streaming_response.create_and_run(
715assistant_id="assistant_id",
716) as response:
717assert not response.is_closed
718assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago719
cca09707stainless-app[bot]1 years ago720thread = await response.parse()
721assert_matches_type(Run, thread, path=["response"])
86379b44Stainless Bot2 years ago722
723assert cast(Any, response.is_closed) is True
5429f696Stainless Bot2 years ago724
725@parametrize
726async def test_method_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago727with pytest.warns(DeprecationWarning):
728thread_stream = await async_client.beta.threads.create_and_run(
729assistant_id="assistant_id",
730stream=True,
731)
732
5429f696Stainless Bot2 years ago733await thread_stream.response.aclose()
734
735@parametrize
736async def test_method_create_and_run_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago737with pytest.warns(DeprecationWarning):
738thread_stream = await async_client.beta.threads.create_and_run(
739assistant_id="assistant_id",
740stream=True,
741instructions="instructions",
742max_completion_tokens=256,
743max_prompt_tokens=256,
744metadata={"foo": "string"},
745model="string",
746parallel_tool_calls=True,
747response_format="auto",
748temperature=1,
749thread={
750"messages": [
751{
752"content": "string",
753"role": "user",
754"attachments": [
755{
756"file_id": "file_id",
757"tools": [{"type": "code_interpreter"}],
758}
759],
760"metadata": {"foo": "string"},
761}
762],
763"metadata": {"foo": "string"},
764"tool_resources": {
765"code_interpreter": {"file_ids": ["string"]},
766"file_search": {
767"vector_store_ids": ["string"],
768"vector_stores": [
769{
770"chunking_strategy": {"type": "auto"},
771"file_ids": ["string"],
772"metadata": {"foo": "string"},
773}
774],
775},
5b20698dStainless Bot2 years ago776},
777},
cca09707stainless-app[bot]1 years ago778tool_choice="none",
779tool_resources={
780"code_interpreter": {"file_ids": ["string"]},
781"file_search": {"vector_store_ids": ["string"]},
782},
783tools=[{"type": "code_interpreter"}],
784top_p=1,
785truncation_strategy={
786"type": "auto",
787"last_messages": 1,
788},
789)
790
5429f696Stainless Bot2 years ago791await thread_stream.response.aclose()
792
793@parametrize
794async def test_raw_response_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago795with pytest.warns(DeprecationWarning):
796response = await async_client.beta.threads.with_raw_response.create_and_run(
797assistant_id="assistant_id",
798stream=True,
799)
5429f696Stainless Bot2 years ago800
801assert response.http_request.headers.get("X-Stainless-Lang") == "python"
802stream = response.parse()
803await stream.close()
804
805@parametrize
806async def test_streaming_response_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago807with pytest.warns(DeprecationWarning):
808async with async_client.beta.threads.with_streaming_response.create_and_run(
809assistant_id="assistant_id",
810stream=True,
811) as response:
812assert not response.is_closed
813assert response.http_request.headers.get("X-Stainless-Lang") == "python"
814
815stream = await response.parse()
816await stream.close()
5429f696Stainless Bot2 years ago817
818assert cast(Any, response.is_closed) is True