openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
7db6d5644b6ea3ff22ba3c391bbbe05f2b9ebafa

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/test_runs.py

308lines · modecode

1# File generated from our OpenAPI spec by Stainless.
2
3from __future__ import annotations
4
5import os
6
7import pytest
8
9from openai import OpenAI, AsyncOpenAI
10from tests.utils import assert_matches_type
11from openai._client import OpenAI, AsyncOpenAI
12from openai.pagination import SyncCursorPage, AsyncCursorPage
13from openai.types.beta.threads import Run
14
15base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16api_key = "My API Key"
17
18
19class TestRuns:
20 strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
21 loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
22 parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
23
24 @parametrize
25 def test_method_create(self, client: OpenAI) -> None:
26 run = client.beta.threads.runs.create(
27 "string",
28 assistant_id="string",
29 )
30 assert_matches_type(Run, run, path=["response"])
31
32 @parametrize
33 def test_method_create_with_all_params(self, client: OpenAI) -> None:
34 run = client.beta.threads.runs.create(
35 "string",
36 assistant_id="string",
37 instructions="string",
38 metadata={},
39 model="string",
40 tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
41 )
42 assert_matches_type(Run, run, path=["response"])
43
44 @parametrize
45 def test_raw_response_create(self, client: OpenAI) -> None:
46 response = client.beta.threads.runs.with_raw_response.create(
47 "string",
48 assistant_id="string",
49 )
50 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
51 run = response.parse()
52 assert_matches_type(Run, run, path=["response"])
53
54 @parametrize
55 def test_method_retrieve(self, client: OpenAI) -> None:
56 run = client.beta.threads.runs.retrieve(
57 "string",
58 thread_id="string",
59 )
60 assert_matches_type(Run, run, path=["response"])
61
62 @parametrize
63 def test_raw_response_retrieve(self, client: OpenAI) -> None:
64 response = client.beta.threads.runs.with_raw_response.retrieve(
65 "string",
66 thread_id="string",
67 )
68 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
69 run = response.parse()
70 assert_matches_type(Run, run, path=["response"])
71
72 @parametrize
73 def test_method_update(self, client: OpenAI) -> None:
74 run = client.beta.threads.runs.update(
75 "string",
76 thread_id="string",
77 )
78 assert_matches_type(Run, run, path=["response"])
79
80 @parametrize
81 def test_method_update_with_all_params(self, client: OpenAI) -> None:
82 run = client.beta.threads.runs.update(
83 "string",
84 thread_id="string",
85 metadata={},
86 )
87 assert_matches_type(Run, run, path=["response"])
88
89 @parametrize
90 def test_raw_response_update(self, client: OpenAI) -> None:
91 response = client.beta.threads.runs.with_raw_response.update(
92 "string",
93 thread_id="string",
94 )
95 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
96 run = response.parse()
97 assert_matches_type(Run, run, path=["response"])
98
99 @parametrize
100 def test_method_list(self, client: OpenAI) -> None:
101 run = client.beta.threads.runs.list(
102 "string",
103 )
104 assert_matches_type(SyncCursorPage[Run], run, path=["response"])
105
106 @parametrize
107 def test_method_list_with_all_params(self, client: OpenAI) -> None:
108 run = client.beta.threads.runs.list(
109 "string",
110 after="string",
111 before="string",
112 limit=0,
113 order="asc",
114 )
115 assert_matches_type(SyncCursorPage[Run], run, path=["response"])
116
117 @parametrize
118 def test_raw_response_list(self, client: OpenAI) -> None:
119 response = client.beta.threads.runs.with_raw_response.list(
120 "string",
121 )
122 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
123 run = response.parse()
124 assert_matches_type(SyncCursorPage[Run], run, path=["response"])
125
126 @parametrize
127 def test_method_cancel(self, client: OpenAI) -> None:
128 run = client.beta.threads.runs.cancel(
129 "string",
130 thread_id="string",
131 )
132 assert_matches_type(Run, run, path=["response"])
133
134 @parametrize
135 def test_raw_response_cancel(self, client: OpenAI) -> None:
136 response = client.beta.threads.runs.with_raw_response.cancel(
137 "string",
138 thread_id="string",
139 )
140 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
141 run = response.parse()
142 assert_matches_type(Run, run, path=["response"])
143
144 @parametrize
145 def test_method_submit_tool_outputs(self, client: OpenAI) -> None:
146 run = client.beta.threads.runs.submit_tool_outputs(
147 "string",
148 thread_id="string",
149 tool_outputs=[{}, {}, {}],
150 )
151 assert_matches_type(Run, run, path=["response"])
152
153 @parametrize
154 def test_raw_response_submit_tool_outputs(self, client: OpenAI) -> None:
155 response = client.beta.threads.runs.with_raw_response.submit_tool_outputs(
156 "string",
157 thread_id="string",
158 tool_outputs=[{}, {}, {}],
159 )
160 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
161 run = response.parse()
162 assert_matches_type(Run, run, path=["response"])
163
164
165class TestAsyncRuns:
166 strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
167 loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
168 parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
169
170 @parametrize
171 async def test_method_create(self, client: AsyncOpenAI) -> None:
172 run = await client.beta.threads.runs.create(
173 "string",
174 assistant_id="string",
175 )
176 assert_matches_type(Run, run, path=["response"])
177
178 @parametrize
179 async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None:
180 run = await client.beta.threads.runs.create(
181 "string",
182 assistant_id="string",
183 instructions="string",
184 metadata={},
185 model="string",
186 tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
187 )
188 assert_matches_type(Run, run, path=["response"])
189
190 @parametrize
191 async def test_raw_response_create(self, client: AsyncOpenAI) -> None:
192 response = await client.beta.threads.runs.with_raw_response.create(
193 "string",
194 assistant_id="string",
195 )
196 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
197 run = response.parse()
198 assert_matches_type(Run, run, path=["response"])
199
200 @parametrize
201 async def test_method_retrieve(self, client: AsyncOpenAI) -> None:
202 run = await client.beta.threads.runs.retrieve(
203 "string",
204 thread_id="string",
205 )
206 assert_matches_type(Run, run, path=["response"])
207
208 @parametrize
209 async def test_raw_response_retrieve(self, client: AsyncOpenAI) -> None:
210 response = await client.beta.threads.runs.with_raw_response.retrieve(
211 "string",
212 thread_id="string",
213 )
214 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
215 run = response.parse()
216 assert_matches_type(Run, run, path=["response"])
217
218 @parametrize
219 async def test_method_update(self, client: AsyncOpenAI) -> None:
220 run = await client.beta.threads.runs.update(
221 "string",
222 thread_id="string",
223 )
224 assert_matches_type(Run, run, path=["response"])
225
226 @parametrize
227 async def test_method_update_with_all_params(self, client: AsyncOpenAI) -> None:
228 run = await client.beta.threads.runs.update(
229 "string",
230 thread_id="string",
231 metadata={},
232 )
233 assert_matches_type(Run, run, path=["response"])
234
235 @parametrize
236 async def test_raw_response_update(self, client: AsyncOpenAI) -> None:
237 response = await client.beta.threads.runs.with_raw_response.update(
238 "string",
239 thread_id="string",
240 )
241 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
242 run = response.parse()
243 assert_matches_type(Run, run, path=["response"])
244
245 @parametrize
246 async def test_method_list(self, client: AsyncOpenAI) -> None:
247 run = await client.beta.threads.runs.list(
248 "string",
249 )
250 assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
251
252 @parametrize
253 async def test_method_list_with_all_params(self, client: AsyncOpenAI) -> None:
254 run = await client.beta.threads.runs.list(
255 "string",
256 after="string",
257 before="string",
258 limit=0,
259 order="asc",
260 )
261 assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
262
263 @parametrize
264 async def test_raw_response_list(self, client: AsyncOpenAI) -> None:
265 response = await client.beta.threads.runs.with_raw_response.list(
266 "string",
267 )
268 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
269 run = response.parse()
270 assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
271
272 @parametrize
273 async def test_method_cancel(self, client: AsyncOpenAI) -> None:
274 run = await client.beta.threads.runs.cancel(
275 "string",
276 thread_id="string",
277 )
278 assert_matches_type(Run, run, path=["response"])
279
280 @parametrize
281 async def test_raw_response_cancel(self, client: AsyncOpenAI) -> None:
282 response = await client.beta.threads.runs.with_raw_response.cancel(
283 "string",
284 thread_id="string",
285 )
286 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
287 run = response.parse()
288 assert_matches_type(Run, run, path=["response"])
289
290 @parametrize
291 async def test_method_submit_tool_outputs(self, client: AsyncOpenAI) -> None:
292 run = await client.beta.threads.runs.submit_tool_outputs(
293 "string",
294 thread_id="string",
295 tool_outputs=[{}, {}, {}],
296 )
297 assert_matches_type(Run, run, path=["response"])
298
299 @parametrize
300 async def test_raw_response_submit_tool_outputs(self, client: AsyncOpenAI) -> None:
301 response = await client.beta.threads.runs.with_raw_response.submit_tool_outputs(
302 "string",
303 thread_id="string",
304 tool_outputs=[{}, {}, {}],
305 )
306 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
307 run = response.parse()
308 assert_matches_type(Run, run, path=["response"])
309