openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.7.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/test_runs.py

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