openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.105.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/test_threads.py

820lines · 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:
c62e9907stainless-app[bot]1 years ago423parametrize = pytest.mark.parametrize(
424"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
425)
baa9f07fRobert Craigie2 years ago426
427@parametrize
98d779fbStainless Bot2 years ago428async def test_method_create(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago429with pytest.warns(DeprecationWarning):
430thread = await async_client.beta.threads.create()
431
baa9f07fRobert Craigie2 years ago432assert_matches_type(Thread, thread, path=["response"])
433
434@parametrize
98d779fbStainless Bot2 years ago435async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago436with pytest.warns(DeprecationWarning):
437thread = await async_client.beta.threads.create(
438messages=[
439{
440"content": "string",
441"role": "user",
442"attachments": [
443{
444"file_id": "file_id",
445"tools": [{"type": "code_interpreter"}],
446}
447],
448"metadata": {"foo": "string"},
449}
450],
451metadata={"foo": "string"},
452tool_resources={
453"code_interpreter": {"file_ids": ["string"]},
454"file_search": {
455"vector_store_ids": ["string"],
456"vector_stores": [
457{
458"chunking_strategy": {"type": "auto"},
459"file_ids": ["string"],
460"metadata": {"foo": "string"},
461}
462],
463},
5b20698dStainless Bot2 years ago464},
cca09707stainless-app[bot]1 years ago465)
466
baa9f07fRobert Craigie2 years ago467assert_matches_type(Thread, thread, path=["response"])
468
469@parametrize
98d779fbStainless Bot2 years ago470async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago471with pytest.warns(DeprecationWarning):
472response = await async_client.beta.threads.with_raw_response.create()
86379b44Stainless Bot2 years ago473
474assert response.is_closed is True
baa9f07fRobert Craigie2 years ago475assert response.http_request.headers.get("X-Stainless-Lang") == "python"
476thread = response.parse()
477assert_matches_type(Thread, thread, path=["response"])
478
86379b44Stainless Bot2 years ago479@parametrize
98d779fbStainless Bot2 years ago480async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago481with pytest.warns(DeprecationWarning):
482async with async_client.beta.threads.with_streaming_response.create() as response:
483assert not response.is_closed
484assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago485
cca09707stainless-app[bot]1 years ago486thread = await response.parse()
487assert_matches_type(Thread, thread, path=["response"])
86379b44Stainless Bot2 years ago488
489assert cast(Any, response.is_closed) is True
490
baa9f07fRobert Craigie2 years ago491@parametrize
98d779fbStainless Bot2 years ago492async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago493with pytest.warns(DeprecationWarning):
494thread = await async_client.beta.threads.retrieve(
495"thread_id",
496)
497
baa9f07fRobert Craigie2 years ago498assert_matches_type(Thread, thread, path=["response"])
499
500@parametrize
98d779fbStainless Bot2 years ago501async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago502with pytest.warns(DeprecationWarning):
503response = await async_client.beta.threads.with_raw_response.retrieve(
504"thread_id",
505)
86379b44Stainless Bot2 years ago506
507assert response.is_closed is True
baa9f07fRobert Craigie2 years ago508assert response.http_request.headers.get("X-Stainless-Lang") == "python"
509thread = response.parse()
510assert_matches_type(Thread, thread, path=["response"])
511
86379b44Stainless Bot2 years ago512@parametrize
98d779fbStainless Bot2 years ago513async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago514with pytest.warns(DeprecationWarning):
515async with async_client.beta.threads.with_streaming_response.retrieve(
516"thread_id",
517) as response:
518assert not response.is_closed
519assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago520
cca09707stainless-app[bot]1 years ago521thread = await response.parse()
522assert_matches_type(Thread, thread, path=["response"])
86379b44Stainless Bot2 years ago523
524assert cast(Any, response.is_closed) is True
525
023a4e66Stainless Bot2 years ago526@parametrize
98d779fbStainless Bot2 years ago527async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago528with pytest.warns(DeprecationWarning):
529with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
530await async_client.beta.threads.with_raw_response.retrieve(
531"",
532)
023a4e66Stainless Bot2 years ago533
baa9f07fRobert Craigie2 years ago534@parametrize
98d779fbStainless Bot2 years ago535async def test_method_update(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago536with pytest.warns(DeprecationWarning):
537thread = await async_client.beta.threads.update(
538thread_id="thread_id",
539)
540
baa9f07fRobert Craigie2 years ago541assert_matches_type(Thread, thread, path=["response"])
542
543@parametrize
98d779fbStainless Bot2 years ago544async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago545with pytest.warns(DeprecationWarning):
546thread = await async_client.beta.threads.update(
547thread_id="thread_id",
548metadata={"foo": "string"},
549tool_resources={
550"code_interpreter": {"file_ids": ["string"]},
551"file_search": {"vector_store_ids": ["string"]},
552},
553)
554
baa9f07fRobert Craigie2 years ago555assert_matches_type(Thread, thread, path=["response"])
556
557@parametrize
98d779fbStainless Bot2 years ago558async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago559with pytest.warns(DeprecationWarning):
560response = await async_client.beta.threads.with_raw_response.update(
561thread_id="thread_id",
562)
86379b44Stainless Bot2 years ago563
564assert response.is_closed is True
baa9f07fRobert Craigie2 years ago565assert response.http_request.headers.get("X-Stainless-Lang") == "python"
566thread = response.parse()
567assert_matches_type(Thread, thread, path=["response"])
568
86379b44Stainless Bot2 years ago569@parametrize
98d779fbStainless Bot2 years ago570async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago571with pytest.warns(DeprecationWarning):
572async with async_client.beta.threads.with_streaming_response.update(
573thread_id="thread_id",
574) as response:
575assert not response.is_closed
576assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago577
cca09707stainless-app[bot]1 years ago578thread = await response.parse()
579assert_matches_type(Thread, thread, path=["response"])
86379b44Stainless Bot2 years ago580
581assert cast(Any, response.is_closed) is True
582
023a4e66Stainless Bot2 years ago583@parametrize
98d779fbStainless Bot2 years ago584async def test_path_params_update(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago585with pytest.warns(DeprecationWarning):
586with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
587await async_client.beta.threads.with_raw_response.update(
588thread_id="",
589)
023a4e66Stainless Bot2 years ago590
baa9f07fRobert Craigie2 years ago591@parametrize
98d779fbStainless Bot2 years ago592async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago593with pytest.warns(DeprecationWarning):
594thread = await async_client.beta.threads.delete(
595"thread_id",
596)
597
baa9f07fRobert Craigie2 years ago598assert_matches_type(ThreadDeleted, thread, path=["response"])
599
600@parametrize
98d779fbStainless Bot2 years ago601async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago602with pytest.warns(DeprecationWarning):
603response = await async_client.beta.threads.with_raw_response.delete(
604"thread_id",
605)
86379b44Stainless Bot2 years ago606
607assert response.is_closed is True
baa9f07fRobert Craigie2 years ago608assert response.http_request.headers.get("X-Stainless-Lang") == "python"
609thread = response.parse()
610assert_matches_type(ThreadDeleted, thread, path=["response"])
611
86379b44Stainless Bot2 years ago612@parametrize
98d779fbStainless Bot2 years ago613async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago614with pytest.warns(DeprecationWarning):
615async with async_client.beta.threads.with_streaming_response.delete(
616"thread_id",
617) as response:
618assert not response.is_closed
619assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago620
cca09707stainless-app[bot]1 years ago621thread = await response.parse()
622assert_matches_type(ThreadDeleted, thread, path=["response"])
86379b44Stainless Bot2 years ago623
624assert cast(Any, response.is_closed) is True
625
023a4e66Stainless Bot2 years ago626@parametrize
98d779fbStainless Bot2 years ago627async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago628with pytest.warns(DeprecationWarning):
629with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
630await async_client.beta.threads.with_raw_response.delete(
631"",
632)
023a4e66Stainless Bot2 years ago633
baa9f07fRobert Craigie2 years ago634@parametrize
5429f696Stainless Bot2 years ago635async def test_method_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago636with pytest.warns(DeprecationWarning):
637thread = await async_client.beta.threads.create_and_run(
638assistant_id="assistant_id",
639)
640
baa9f07fRobert Craigie2 years ago641assert_matches_type(Run, thread, path=["response"])
642
643@parametrize
5429f696Stainless Bot2 years ago644async def test_method_create_and_run_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago645with pytest.warns(DeprecationWarning):
646thread = await async_client.beta.threads.create_and_run(
647assistant_id="assistant_id",
648instructions="instructions",
649max_completion_tokens=256,
650max_prompt_tokens=256,
651metadata={"foo": "string"},
652model="string",
653parallel_tool_calls=True,
654response_format="auto",
655stream=False,
656temperature=1,
657thread={
658"messages": [
659{
660"content": "string",
661"role": "user",
662"attachments": [
663{
664"file_id": "file_id",
665"tools": [{"type": "code_interpreter"}],
666}
667],
668"metadata": {"foo": "string"},
669}
670],
671"metadata": {"foo": "string"},
672"tool_resources": {
673"code_interpreter": {"file_ids": ["string"]},
674"file_search": {
675"vector_store_ids": ["string"],
676"vector_stores": [
677{
678"chunking_strategy": {"type": "auto"},
679"file_ids": ["string"],
680"metadata": {"foo": "string"},
681}
682],
683},
5b20698dStainless Bot2 years ago684},
685},
cca09707stainless-app[bot]1 years ago686tool_choice="none",
687tool_resources={
688"code_interpreter": {"file_ids": ["string"]},
689"file_search": {"vector_store_ids": ["string"]},
690},
691tools=[{"type": "code_interpreter"}],
692top_p=1,
693truncation_strategy={
694"type": "auto",
695"last_messages": 1,
696},
697)
698
baa9f07fRobert Craigie2 years ago699assert_matches_type(Run, thread, path=["response"])
700
701@parametrize
5429f696Stainless Bot2 years ago702async def test_raw_response_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago703with pytest.warns(DeprecationWarning):
704response = await async_client.beta.threads.with_raw_response.create_and_run(
705assistant_id="assistant_id",
706)
86379b44Stainless Bot2 years ago707
708assert response.is_closed is True
baa9f07fRobert Craigie2 years ago709assert response.http_request.headers.get("X-Stainless-Lang") == "python"
710thread = response.parse()
711assert_matches_type(Run, thread, path=["response"])
86379b44Stainless Bot2 years ago712
713@parametrize
5429f696Stainless Bot2 years ago714async def test_streaming_response_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago715with pytest.warns(DeprecationWarning):
716async with async_client.beta.threads.with_streaming_response.create_and_run(
717assistant_id="assistant_id",
718) as response:
719assert not response.is_closed
720assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago721
cca09707stainless-app[bot]1 years ago722thread = await response.parse()
723assert_matches_type(Run, thread, path=["response"])
86379b44Stainless Bot2 years ago724
725assert cast(Any, response.is_closed) is True
5429f696Stainless Bot2 years ago726
727@parametrize
728async def test_method_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago729with pytest.warns(DeprecationWarning):
730thread_stream = await async_client.beta.threads.create_and_run(
731assistant_id="assistant_id",
732stream=True,
733)
734
5429f696Stainless Bot2 years ago735await thread_stream.response.aclose()
736
737@parametrize
738async def test_method_create_and_run_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago739with pytest.warns(DeprecationWarning):
740thread_stream = await async_client.beta.threads.create_and_run(
741assistant_id="assistant_id",
742stream=True,
743instructions="instructions",
744max_completion_tokens=256,
745max_prompt_tokens=256,
746metadata={"foo": "string"},
747model="string",
748parallel_tool_calls=True,
749response_format="auto",
750temperature=1,
751thread={
752"messages": [
753{
754"content": "string",
755"role": "user",
756"attachments": [
757{
758"file_id": "file_id",
759"tools": [{"type": "code_interpreter"}],
760}
761],
762"metadata": {"foo": "string"},
763}
764],
765"metadata": {"foo": "string"},
766"tool_resources": {
767"code_interpreter": {"file_ids": ["string"]},
768"file_search": {
769"vector_store_ids": ["string"],
770"vector_stores": [
771{
772"chunking_strategy": {"type": "auto"},
773"file_ids": ["string"],
774"metadata": {"foo": "string"},
775}
776],
777},
5b20698dStainless Bot2 years ago778},
779},
cca09707stainless-app[bot]1 years ago780tool_choice="none",
781tool_resources={
782"code_interpreter": {"file_ids": ["string"]},
783"file_search": {"vector_store_ids": ["string"]},
784},
785tools=[{"type": "code_interpreter"}],
786top_p=1,
787truncation_strategy={
788"type": "auto",
789"last_messages": 1,
790},
791)
792
5429f696Stainless Bot2 years ago793await thread_stream.response.aclose()
794
795@parametrize
796async def test_raw_response_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago797with pytest.warns(DeprecationWarning):
798response = await async_client.beta.threads.with_raw_response.create_and_run(
799assistant_id="assistant_id",
800stream=True,
801)
5429f696Stainless Bot2 years ago802
803assert response.http_request.headers.get("X-Stainless-Lang") == "python"
804stream = response.parse()
805await stream.close()
806
807@parametrize
808async def test_streaming_response_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago809with pytest.warns(DeprecationWarning):
810async with async_client.beta.threads.with_streaming_response.create_and_run(
811assistant_id="assistant_id",
812stream=True,
813) as response:
814assert not response.is_closed
815assert response.http_request.headers.get("X-Stainless-Lang") == "python"
816
817stream = await response.parse()
818await stream.close()
5429f696Stainless Bot2 years ago819
820assert cast(Any, response.is_closed) is True