openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
tests/api_resources/beta/threads/test_runs.py
929lines · modecode
| 1 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import os |
| 6 | from typing import Any, cast |
| 7 | |
| 8 | import pytest |
| 9 | |
| 10 | from openai import OpenAI, AsyncOpenAI |
| 11 | from tests.utils import assert_matches_type |
| 12 | from openai.pagination import SyncCursorPage, AsyncCursorPage |
| 13 | from openai.types.beta.threads import ( |
| 14 | Run, |
| 15 | ) |
| 16 | |
| 17 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 18 | |
| 19 | |
| 20 | class TestRuns: |
| 21 | parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
| 22 | |
| 23 | @parametrize |
| 24 | def test_method_create_overload_1(self, client: OpenAI) -> None: |
| 25 | run = client.beta.threads.runs.create( |
| 26 | "string", |
| 27 | assistant_id="string", |
| 28 | ) |
| 29 | assert_matches_type(Run, run, path=["response"]) |
| 30 | |
| 31 | @parametrize |
| 32 | def test_method_create_with_all_params_overload_1(self, client: OpenAI) -> None: |
| 33 | run = client.beta.threads.runs.create( |
| 34 | "string", |
| 35 | assistant_id="string", |
| 36 | additional_instructions="string", |
| 37 | instructions="string", |
| 38 | metadata={}, |
| 39 | model="string", |
| 40 | stream=False, |
| 41 | temperature=1, |
| 42 | tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}], |
| 43 | ) |
| 44 | assert_matches_type(Run, run, path=["response"]) |
| 45 | |
| 46 | @parametrize |
| 47 | def test_raw_response_create_overload_1(self, client: OpenAI) -> None: |
| 48 | response = client.beta.threads.runs.with_raw_response.create( |
| 49 | "string", |
| 50 | assistant_id="string", |
| 51 | ) |
| 52 | |
| 53 | assert response.is_closed is True |
| 54 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 55 | run = response.parse() |
| 56 | assert_matches_type(Run, run, path=["response"]) |
| 57 | |
| 58 | @parametrize |
| 59 | def test_streaming_response_create_overload_1(self, client: OpenAI) -> None: |
| 60 | with client.beta.threads.runs.with_streaming_response.create( |
| 61 | "string", |
| 62 | assistant_id="string", |
| 63 | ) as response: |
| 64 | assert not response.is_closed |
| 65 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 66 | |
| 67 | run = response.parse() |
| 68 | assert_matches_type(Run, run, path=["response"]) |
| 69 | |
| 70 | assert cast(Any, response.is_closed) is True |
| 71 | |
| 72 | @parametrize |
| 73 | def test_path_params_create_overload_1(self, client: OpenAI) -> None: |
| 74 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 75 | client.beta.threads.runs.with_raw_response.create( |
| 76 | "", |
| 77 | assistant_id="string", |
| 78 | ) |
| 79 | |
| 80 | @parametrize |
| 81 | def test_method_create_overload_2(self, client: OpenAI) -> None: |
| 82 | run_stream = client.beta.threads.runs.create( |
| 83 | "string", |
| 84 | assistant_id="string", |
| 85 | stream=True, |
| 86 | ) |
| 87 | run_stream.response.close() |
| 88 | |
| 89 | @parametrize |
| 90 | def test_method_create_with_all_params_overload_2(self, client: OpenAI) -> None: |
| 91 | run_stream = client.beta.threads.runs.create( |
| 92 | "string", |
| 93 | assistant_id="string", |
| 94 | stream=True, |
| 95 | additional_instructions="string", |
| 96 | instructions="string", |
| 97 | metadata={}, |
| 98 | model="string", |
| 99 | temperature=1, |
| 100 | tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}], |
| 101 | ) |
| 102 | run_stream.response.close() |
| 103 | |
| 104 | @parametrize |
| 105 | def test_raw_response_create_overload_2(self, client: OpenAI) -> None: |
| 106 | response = client.beta.threads.runs.with_raw_response.create( |
| 107 | "string", |
| 108 | assistant_id="string", |
| 109 | stream=True, |
| 110 | ) |
| 111 | |
| 112 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 113 | stream = response.parse() |
| 114 | stream.close() |
| 115 | |
| 116 | @parametrize |
| 117 | def test_streaming_response_create_overload_2(self, client: OpenAI) -> None: |
| 118 | with client.beta.threads.runs.with_streaming_response.create( |
| 119 | "string", |
| 120 | assistant_id="string", |
| 121 | stream=True, |
| 122 | ) as response: |
| 123 | assert not response.is_closed |
| 124 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 125 | |
| 126 | stream = response.parse() |
| 127 | stream.close() |
| 128 | |
| 129 | assert cast(Any, response.is_closed) is True |
| 130 | |
| 131 | @parametrize |
| 132 | def test_path_params_create_overload_2(self, client: OpenAI) -> None: |
| 133 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 134 | client.beta.threads.runs.with_raw_response.create( |
| 135 | "", |
| 136 | assistant_id="string", |
| 137 | stream=True, |
| 138 | ) |
| 139 | |
| 140 | @parametrize |
| 141 | def test_method_retrieve(self, client: OpenAI) -> None: |
| 142 | run = client.beta.threads.runs.retrieve( |
| 143 | "string", |
| 144 | thread_id="string", |
| 145 | ) |
| 146 | assert_matches_type(Run, run, path=["response"]) |
| 147 | |
| 148 | @parametrize |
| 149 | def test_raw_response_retrieve(self, client: OpenAI) -> None: |
| 150 | response = client.beta.threads.runs.with_raw_response.retrieve( |
| 151 | "string", |
| 152 | thread_id="string", |
| 153 | ) |
| 154 | |
| 155 | assert response.is_closed is True |
| 156 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 157 | run = response.parse() |
| 158 | assert_matches_type(Run, run, path=["response"]) |
| 159 | |
| 160 | @parametrize |
| 161 | def test_streaming_response_retrieve(self, client: OpenAI) -> None: |
| 162 | with client.beta.threads.runs.with_streaming_response.retrieve( |
| 163 | "string", |
| 164 | thread_id="string", |
| 165 | ) as response: |
| 166 | assert not response.is_closed |
| 167 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 168 | |
| 169 | run = response.parse() |
| 170 | assert_matches_type(Run, run, path=["response"]) |
| 171 | |
| 172 | assert cast(Any, response.is_closed) is True |
| 173 | |
| 174 | @parametrize |
| 175 | def test_path_params_retrieve(self, client: OpenAI) -> None: |
| 176 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 177 | client.beta.threads.runs.with_raw_response.retrieve( |
| 178 | "string", |
| 179 | thread_id="", |
| 180 | ) |
| 181 | |
| 182 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 183 | client.beta.threads.runs.with_raw_response.retrieve( |
| 184 | "", |
| 185 | thread_id="string", |
| 186 | ) |
| 187 | |
| 188 | @parametrize |
| 189 | def test_method_update(self, client: OpenAI) -> None: |
| 190 | run = client.beta.threads.runs.update( |
| 191 | "string", |
| 192 | thread_id="string", |
| 193 | ) |
| 194 | assert_matches_type(Run, run, path=["response"]) |
| 195 | |
| 196 | @parametrize |
| 197 | def test_method_update_with_all_params(self, client: OpenAI) -> None: |
| 198 | run = client.beta.threads.runs.update( |
| 199 | "string", |
| 200 | thread_id="string", |
| 201 | metadata={}, |
| 202 | ) |
| 203 | assert_matches_type(Run, run, path=["response"]) |
| 204 | |
| 205 | @parametrize |
| 206 | def test_raw_response_update(self, client: OpenAI) -> None: |
| 207 | response = client.beta.threads.runs.with_raw_response.update( |
| 208 | "string", |
| 209 | thread_id="string", |
| 210 | ) |
| 211 | |
| 212 | assert response.is_closed is True |
| 213 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 214 | run = response.parse() |
| 215 | assert_matches_type(Run, run, path=["response"]) |
| 216 | |
| 217 | @parametrize |
| 218 | def test_streaming_response_update(self, client: OpenAI) -> None: |
| 219 | with client.beta.threads.runs.with_streaming_response.update( |
| 220 | "string", |
| 221 | thread_id="string", |
| 222 | ) as response: |
| 223 | assert not response.is_closed |
| 224 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 225 | |
| 226 | run = response.parse() |
| 227 | assert_matches_type(Run, run, path=["response"]) |
| 228 | |
| 229 | assert cast(Any, response.is_closed) is True |
| 230 | |
| 231 | @parametrize |
| 232 | def test_path_params_update(self, client: OpenAI) -> None: |
| 233 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 234 | client.beta.threads.runs.with_raw_response.update( |
| 235 | "string", |
| 236 | thread_id="", |
| 237 | ) |
| 238 | |
| 239 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 240 | client.beta.threads.runs.with_raw_response.update( |
| 241 | "", |
| 242 | thread_id="string", |
| 243 | ) |
| 244 | |
| 245 | @parametrize |
| 246 | def test_method_list(self, client: OpenAI) -> None: |
| 247 | run = client.beta.threads.runs.list( |
| 248 | "string", |
| 249 | ) |
| 250 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 251 | |
| 252 | @parametrize |
| 253 | def test_method_list_with_all_params(self, client: OpenAI) -> None: |
| 254 | run = client.beta.threads.runs.list( |
| 255 | "string", |
| 256 | after="string", |
| 257 | before="string", |
| 258 | limit=0, |
| 259 | order="asc", |
| 260 | ) |
| 261 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 262 | |
| 263 | @parametrize |
| 264 | def test_raw_response_list(self, client: OpenAI) -> None: |
| 265 | response = client.beta.threads.runs.with_raw_response.list( |
| 266 | "string", |
| 267 | ) |
| 268 | |
| 269 | assert response.is_closed is True |
| 270 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 271 | run = response.parse() |
| 272 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 273 | |
| 274 | @parametrize |
| 275 | def test_streaming_response_list(self, client: OpenAI) -> None: |
| 276 | with client.beta.threads.runs.with_streaming_response.list( |
| 277 | "string", |
| 278 | ) as response: |
| 279 | assert not response.is_closed |
| 280 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 281 | |
| 282 | run = response.parse() |
| 283 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 284 | |
| 285 | assert cast(Any, response.is_closed) is True |
| 286 | |
| 287 | @parametrize |
| 288 | def test_path_params_list(self, client: OpenAI) -> None: |
| 289 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 290 | client.beta.threads.runs.with_raw_response.list( |
| 291 | "", |
| 292 | ) |
| 293 | |
| 294 | @parametrize |
| 295 | def test_method_cancel(self, client: OpenAI) -> None: |
| 296 | run = client.beta.threads.runs.cancel( |
| 297 | "string", |
| 298 | thread_id="string", |
| 299 | ) |
| 300 | assert_matches_type(Run, run, path=["response"]) |
| 301 | |
| 302 | @parametrize |
| 303 | def test_raw_response_cancel(self, client: OpenAI) -> None: |
| 304 | response = client.beta.threads.runs.with_raw_response.cancel( |
| 305 | "string", |
| 306 | thread_id="string", |
| 307 | ) |
| 308 | |
| 309 | assert response.is_closed is True |
| 310 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 311 | run = response.parse() |
| 312 | assert_matches_type(Run, run, path=["response"]) |
| 313 | |
| 314 | @parametrize |
| 315 | def test_streaming_response_cancel(self, client: OpenAI) -> None: |
| 316 | with client.beta.threads.runs.with_streaming_response.cancel( |
| 317 | "string", |
| 318 | thread_id="string", |
| 319 | ) as response: |
| 320 | assert not response.is_closed |
| 321 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 322 | |
| 323 | run = response.parse() |
| 324 | assert_matches_type(Run, run, path=["response"]) |
| 325 | |
| 326 | assert cast(Any, response.is_closed) is True |
| 327 | |
| 328 | @parametrize |
| 329 | def test_path_params_cancel(self, client: OpenAI) -> None: |
| 330 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 331 | client.beta.threads.runs.with_raw_response.cancel( |
| 332 | "string", |
| 333 | thread_id="", |
| 334 | ) |
| 335 | |
| 336 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 337 | client.beta.threads.runs.with_raw_response.cancel( |
| 338 | "", |
| 339 | thread_id="string", |
| 340 | ) |
| 341 | |
| 342 | @parametrize |
| 343 | def test_method_submit_tool_outputs_overload_1(self, client: OpenAI) -> None: |
| 344 | run = client.beta.threads.runs.submit_tool_outputs( |
| 345 | "string", |
| 346 | thread_id="string", |
| 347 | tool_outputs=[{}, {}, {}], |
| 348 | ) |
| 349 | assert_matches_type(Run, run, path=["response"]) |
| 350 | |
| 351 | @parametrize |
| 352 | def test_method_submit_tool_outputs_with_all_params_overload_1(self, client: OpenAI) -> None: |
| 353 | run = client.beta.threads.runs.submit_tool_outputs( |
| 354 | "string", |
| 355 | thread_id="string", |
| 356 | tool_outputs=[ |
| 357 | { |
| 358 | "tool_call_id": "string", |
| 359 | "output": "string", |
| 360 | }, |
| 361 | { |
| 362 | "tool_call_id": "string", |
| 363 | "output": "string", |
| 364 | }, |
| 365 | { |
| 366 | "tool_call_id": "string", |
| 367 | "output": "string", |
| 368 | }, |
| 369 | ], |
| 370 | stream=False, |
| 371 | ) |
| 372 | assert_matches_type(Run, run, path=["response"]) |
| 373 | |
| 374 | @parametrize |
| 375 | def test_raw_response_submit_tool_outputs_overload_1(self, client: OpenAI) -> None: |
| 376 | response = client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 377 | "string", |
| 378 | thread_id="string", |
| 379 | tool_outputs=[{}, {}, {}], |
| 380 | ) |
| 381 | |
| 382 | assert response.is_closed is True |
| 383 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 384 | run = response.parse() |
| 385 | assert_matches_type(Run, run, path=["response"]) |
| 386 | |
| 387 | @parametrize |
| 388 | def test_streaming_response_submit_tool_outputs_overload_1(self, client: OpenAI) -> None: |
| 389 | with client.beta.threads.runs.with_streaming_response.submit_tool_outputs( |
| 390 | "string", |
| 391 | thread_id="string", |
| 392 | tool_outputs=[{}, {}, {}], |
| 393 | ) as response: |
| 394 | assert not response.is_closed |
| 395 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 396 | |
| 397 | run = response.parse() |
| 398 | assert_matches_type(Run, run, path=["response"]) |
| 399 | |
| 400 | assert cast(Any, response.is_closed) is True |
| 401 | |
| 402 | @parametrize |
| 403 | def test_path_params_submit_tool_outputs_overload_1(self, client: OpenAI) -> None: |
| 404 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 405 | client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 406 | "string", |
| 407 | thread_id="", |
| 408 | tool_outputs=[{}, {}, {}], |
| 409 | ) |
| 410 | |
| 411 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 412 | client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 413 | "", |
| 414 | thread_id="string", |
| 415 | tool_outputs=[{}, {}, {}], |
| 416 | ) |
| 417 | |
| 418 | @parametrize |
| 419 | def test_method_submit_tool_outputs_overload_2(self, client: OpenAI) -> None: |
| 420 | run_stream = client.beta.threads.runs.submit_tool_outputs( |
| 421 | "string", |
| 422 | thread_id="string", |
| 423 | stream=True, |
| 424 | tool_outputs=[{}, {}, {}], |
| 425 | ) |
| 426 | run_stream.response.close() |
| 427 | |
| 428 | @parametrize |
| 429 | def test_raw_response_submit_tool_outputs_overload_2(self, client: OpenAI) -> None: |
| 430 | response = client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 431 | "string", |
| 432 | thread_id="string", |
| 433 | stream=True, |
| 434 | tool_outputs=[{}, {}, {}], |
| 435 | ) |
| 436 | |
| 437 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 438 | stream = response.parse() |
| 439 | stream.close() |
| 440 | |
| 441 | @parametrize |
| 442 | def test_streaming_response_submit_tool_outputs_overload_2(self, client: OpenAI) -> None: |
| 443 | with client.beta.threads.runs.with_streaming_response.submit_tool_outputs( |
| 444 | "string", |
| 445 | thread_id="string", |
| 446 | stream=True, |
| 447 | tool_outputs=[{}, {}, {}], |
| 448 | ) as response: |
| 449 | assert not response.is_closed |
| 450 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 451 | |
| 452 | stream = response.parse() |
| 453 | stream.close() |
| 454 | |
| 455 | assert cast(Any, response.is_closed) is True |
| 456 | |
| 457 | @parametrize |
| 458 | def test_path_params_submit_tool_outputs_overload_2(self, client: OpenAI) -> None: |
| 459 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 460 | client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 461 | "string", |
| 462 | thread_id="", |
| 463 | stream=True, |
| 464 | tool_outputs=[{}, {}, {}], |
| 465 | ) |
| 466 | |
| 467 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 468 | client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 469 | "", |
| 470 | thread_id="string", |
| 471 | stream=True, |
| 472 | tool_outputs=[{}, {}, {}], |
| 473 | ) |
| 474 | |
| 475 | |
| 476 | class TestAsyncRuns: |
| 477 | parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) |
| 478 | |
| 479 | @parametrize |
| 480 | async def test_method_create_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 481 | run = await async_client.beta.threads.runs.create( |
| 482 | "string", |
| 483 | assistant_id="string", |
| 484 | ) |
| 485 | assert_matches_type(Run, run, path=["response"]) |
| 486 | |
| 487 | @parametrize |
| 488 | async def test_method_create_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 489 | run = await async_client.beta.threads.runs.create( |
| 490 | "string", |
| 491 | assistant_id="string", |
| 492 | additional_instructions="string", |
| 493 | instructions="string", |
| 494 | metadata={}, |
| 495 | model="string", |
| 496 | stream=False, |
| 497 | temperature=1, |
| 498 | tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}], |
| 499 | ) |
| 500 | assert_matches_type(Run, run, path=["response"]) |
| 501 | |
| 502 | @parametrize |
| 503 | async def test_raw_response_create_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 504 | response = await async_client.beta.threads.runs.with_raw_response.create( |
| 505 | "string", |
| 506 | assistant_id="string", |
| 507 | ) |
| 508 | |
| 509 | assert response.is_closed is True |
| 510 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 511 | run = response.parse() |
| 512 | assert_matches_type(Run, run, path=["response"]) |
| 513 | |
| 514 | @parametrize |
| 515 | async def test_streaming_response_create_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 516 | async with async_client.beta.threads.runs.with_streaming_response.create( |
| 517 | "string", |
| 518 | assistant_id="string", |
| 519 | ) as response: |
| 520 | assert not response.is_closed |
| 521 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 522 | |
| 523 | run = await response.parse() |
| 524 | assert_matches_type(Run, run, path=["response"]) |
| 525 | |
| 526 | assert cast(Any, response.is_closed) is True |
| 527 | |
| 528 | @parametrize |
| 529 | async def test_path_params_create_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 530 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 531 | await async_client.beta.threads.runs.with_raw_response.create( |
| 532 | "", |
| 533 | assistant_id="string", |
| 534 | ) |
| 535 | |
| 536 | @parametrize |
| 537 | async def test_method_create_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 538 | run_stream = await async_client.beta.threads.runs.create( |
| 539 | "string", |
| 540 | assistant_id="string", |
| 541 | stream=True, |
| 542 | ) |
| 543 | await run_stream.response.aclose() |
| 544 | |
| 545 | @parametrize |
| 546 | async def test_method_create_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 547 | run_stream = await async_client.beta.threads.runs.create( |
| 548 | "string", |
| 549 | assistant_id="string", |
| 550 | stream=True, |
| 551 | additional_instructions="string", |
| 552 | instructions="string", |
| 553 | metadata={}, |
| 554 | model="string", |
| 555 | temperature=1, |
| 556 | tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}], |
| 557 | ) |
| 558 | await run_stream.response.aclose() |
| 559 | |
| 560 | @parametrize |
| 561 | async def test_raw_response_create_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 562 | response = await async_client.beta.threads.runs.with_raw_response.create( |
| 563 | "string", |
| 564 | assistant_id="string", |
| 565 | stream=True, |
| 566 | ) |
| 567 | |
| 568 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 569 | stream = response.parse() |
| 570 | await stream.close() |
| 571 | |
| 572 | @parametrize |
| 573 | async def test_streaming_response_create_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 574 | async with async_client.beta.threads.runs.with_streaming_response.create( |
| 575 | "string", |
| 576 | assistant_id="string", |
| 577 | stream=True, |
| 578 | ) as response: |
| 579 | assert not response.is_closed |
| 580 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 581 | |
| 582 | stream = await response.parse() |
| 583 | await stream.close() |
| 584 | |
| 585 | assert cast(Any, response.is_closed) is True |
| 586 | |
| 587 | @parametrize |
| 588 | async def test_path_params_create_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 589 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 590 | await async_client.beta.threads.runs.with_raw_response.create( |
| 591 | "", |
| 592 | assistant_id="string", |
| 593 | stream=True, |
| 594 | ) |
| 595 | |
| 596 | @parametrize |
| 597 | async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 598 | run = await async_client.beta.threads.runs.retrieve( |
| 599 | "string", |
| 600 | thread_id="string", |
| 601 | ) |
| 602 | assert_matches_type(Run, run, path=["response"]) |
| 603 | |
| 604 | @parametrize |
| 605 | async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 606 | response = await async_client.beta.threads.runs.with_raw_response.retrieve( |
| 607 | "string", |
| 608 | thread_id="string", |
| 609 | ) |
| 610 | |
| 611 | assert response.is_closed is True |
| 612 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 613 | run = response.parse() |
| 614 | assert_matches_type(Run, run, path=["response"]) |
| 615 | |
| 616 | @parametrize |
| 617 | async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 618 | async with async_client.beta.threads.runs.with_streaming_response.retrieve( |
| 619 | "string", |
| 620 | thread_id="string", |
| 621 | ) as response: |
| 622 | assert not response.is_closed |
| 623 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 624 | |
| 625 | run = await response.parse() |
| 626 | assert_matches_type(Run, run, path=["response"]) |
| 627 | |
| 628 | assert cast(Any, response.is_closed) is True |
| 629 | |
| 630 | @parametrize |
| 631 | async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 632 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 633 | await async_client.beta.threads.runs.with_raw_response.retrieve( |
| 634 | "string", |
| 635 | thread_id="", |
| 636 | ) |
| 637 | |
| 638 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 639 | await async_client.beta.threads.runs.with_raw_response.retrieve( |
| 640 | "", |
| 641 | thread_id="string", |
| 642 | ) |
| 643 | |
| 644 | @parametrize |
| 645 | async def test_method_update(self, async_client: AsyncOpenAI) -> None: |
| 646 | run = await async_client.beta.threads.runs.update( |
| 647 | "string", |
| 648 | thread_id="string", |
| 649 | ) |
| 650 | assert_matches_type(Run, run, path=["response"]) |
| 651 | |
| 652 | @parametrize |
| 653 | async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 654 | run = await async_client.beta.threads.runs.update( |
| 655 | "string", |
| 656 | thread_id="string", |
| 657 | metadata={}, |
| 658 | ) |
| 659 | assert_matches_type(Run, run, path=["response"]) |
| 660 | |
| 661 | @parametrize |
| 662 | async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None: |
| 663 | response = await async_client.beta.threads.runs.with_raw_response.update( |
| 664 | "string", |
| 665 | thread_id="string", |
| 666 | ) |
| 667 | |
| 668 | assert response.is_closed is True |
| 669 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 670 | run = response.parse() |
| 671 | assert_matches_type(Run, run, path=["response"]) |
| 672 | |
| 673 | @parametrize |
| 674 | async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None: |
| 675 | async with async_client.beta.threads.runs.with_streaming_response.update( |
| 676 | "string", |
| 677 | thread_id="string", |
| 678 | ) as response: |
| 679 | assert not response.is_closed |
| 680 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 681 | |
| 682 | run = await response.parse() |
| 683 | assert_matches_type(Run, run, path=["response"]) |
| 684 | |
| 685 | assert cast(Any, response.is_closed) is True |
| 686 | |
| 687 | @parametrize |
| 688 | async def test_path_params_update(self, async_client: AsyncOpenAI) -> None: |
| 689 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 690 | await async_client.beta.threads.runs.with_raw_response.update( |
| 691 | "string", |
| 692 | thread_id="", |
| 693 | ) |
| 694 | |
| 695 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 696 | await async_client.beta.threads.runs.with_raw_response.update( |
| 697 | "", |
| 698 | thread_id="string", |
| 699 | ) |
| 700 | |
| 701 | @parametrize |
| 702 | async def test_method_list(self, async_client: AsyncOpenAI) -> None: |
| 703 | run = await async_client.beta.threads.runs.list( |
| 704 | "string", |
| 705 | ) |
| 706 | assert_matches_type(AsyncCursorPage[Run], run, path=["response"]) |
| 707 | |
| 708 | @parametrize |
| 709 | async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 710 | run = await async_client.beta.threads.runs.list( |
| 711 | "string", |
| 712 | after="string", |
| 713 | before="string", |
| 714 | limit=0, |
| 715 | order="asc", |
| 716 | ) |
| 717 | assert_matches_type(AsyncCursorPage[Run], run, path=["response"]) |
| 718 | |
| 719 | @parametrize |
| 720 | async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None: |
| 721 | response = await async_client.beta.threads.runs.with_raw_response.list( |
| 722 | "string", |
| 723 | ) |
| 724 | |
| 725 | assert response.is_closed is True |
| 726 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 727 | run = response.parse() |
| 728 | assert_matches_type(AsyncCursorPage[Run], run, path=["response"]) |
| 729 | |
| 730 | @parametrize |
| 731 | async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None: |
| 732 | async with async_client.beta.threads.runs.with_streaming_response.list( |
| 733 | "string", |
| 734 | ) as response: |
| 735 | assert not response.is_closed |
| 736 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 737 | |
| 738 | run = await response.parse() |
| 739 | assert_matches_type(AsyncCursorPage[Run], run, path=["response"]) |
| 740 | |
| 741 | assert cast(Any, response.is_closed) is True |
| 742 | |
| 743 | @parametrize |
| 744 | async def test_path_params_list(self, async_client: AsyncOpenAI) -> None: |
| 745 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 746 | await async_client.beta.threads.runs.with_raw_response.list( |
| 747 | "", |
| 748 | ) |
| 749 | |
| 750 | @parametrize |
| 751 | async def test_method_cancel(self, async_client: AsyncOpenAI) -> None: |
| 752 | run = await async_client.beta.threads.runs.cancel( |
| 753 | "string", |
| 754 | thread_id="string", |
| 755 | ) |
| 756 | assert_matches_type(Run, run, path=["response"]) |
| 757 | |
| 758 | @parametrize |
| 759 | async def test_raw_response_cancel(self, async_client: AsyncOpenAI) -> None: |
| 760 | response = await async_client.beta.threads.runs.with_raw_response.cancel( |
| 761 | "string", |
| 762 | thread_id="string", |
| 763 | ) |
| 764 | |
| 765 | assert response.is_closed is True |
| 766 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 767 | run = response.parse() |
| 768 | assert_matches_type(Run, run, path=["response"]) |
| 769 | |
| 770 | @parametrize |
| 771 | async def test_streaming_response_cancel(self, async_client: AsyncOpenAI) -> None: |
| 772 | async with async_client.beta.threads.runs.with_streaming_response.cancel( |
| 773 | "string", |
| 774 | thread_id="string", |
| 775 | ) as response: |
| 776 | assert not response.is_closed |
| 777 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 778 | |
| 779 | run = await response.parse() |
| 780 | assert_matches_type(Run, run, path=["response"]) |
| 781 | |
| 782 | assert cast(Any, response.is_closed) is True |
| 783 | |
| 784 | @parametrize |
| 785 | async def test_path_params_cancel(self, async_client: AsyncOpenAI) -> None: |
| 786 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 787 | await async_client.beta.threads.runs.with_raw_response.cancel( |
| 788 | "string", |
| 789 | thread_id="", |
| 790 | ) |
| 791 | |
| 792 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 793 | await async_client.beta.threads.runs.with_raw_response.cancel( |
| 794 | "", |
| 795 | thread_id="string", |
| 796 | ) |
| 797 | |
| 798 | @parametrize |
| 799 | async def test_method_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 800 | run = await async_client.beta.threads.runs.submit_tool_outputs( |
| 801 | "string", |
| 802 | thread_id="string", |
| 803 | tool_outputs=[{}, {}, {}], |
| 804 | ) |
| 805 | assert_matches_type(Run, run, path=["response"]) |
| 806 | |
| 807 | @parametrize |
| 808 | async def test_method_submit_tool_outputs_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 809 | run = await async_client.beta.threads.runs.submit_tool_outputs( |
| 810 | "string", |
| 811 | thread_id="string", |
| 812 | tool_outputs=[ |
| 813 | { |
| 814 | "tool_call_id": "string", |
| 815 | "output": "string", |
| 816 | }, |
| 817 | { |
| 818 | "tool_call_id": "string", |
| 819 | "output": "string", |
| 820 | }, |
| 821 | { |
| 822 | "tool_call_id": "string", |
| 823 | "output": "string", |
| 824 | }, |
| 825 | ], |
| 826 | stream=False, |
| 827 | ) |
| 828 | assert_matches_type(Run, run, path=["response"]) |
| 829 | |
| 830 | @parametrize |
| 831 | async def test_raw_response_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 832 | response = await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 833 | "string", |
| 834 | thread_id="string", |
| 835 | tool_outputs=[{}, {}, {}], |
| 836 | ) |
| 837 | |
| 838 | assert response.is_closed is True |
| 839 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 840 | run = response.parse() |
| 841 | assert_matches_type(Run, run, path=["response"]) |
| 842 | |
| 843 | @parametrize |
| 844 | async def test_streaming_response_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 845 | async with async_client.beta.threads.runs.with_streaming_response.submit_tool_outputs( |
| 846 | "string", |
| 847 | thread_id="string", |
| 848 | tool_outputs=[{}, {}, {}], |
| 849 | ) as response: |
| 850 | assert not response.is_closed |
| 851 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 852 | |
| 853 | run = await response.parse() |
| 854 | assert_matches_type(Run, run, path=["response"]) |
| 855 | |
| 856 | assert cast(Any, response.is_closed) is True |
| 857 | |
| 858 | @parametrize |
| 859 | async def test_path_params_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 860 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 861 | await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 862 | "string", |
| 863 | thread_id="", |
| 864 | tool_outputs=[{}, {}, {}], |
| 865 | ) |
| 866 | |
| 867 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 868 | await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 869 | "", |
| 870 | thread_id="string", |
| 871 | tool_outputs=[{}, {}, {}], |
| 872 | ) |
| 873 | |
| 874 | @parametrize |
| 875 | async def test_method_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 876 | run_stream = await async_client.beta.threads.runs.submit_tool_outputs( |
| 877 | "string", |
| 878 | thread_id="string", |
| 879 | stream=True, |
| 880 | tool_outputs=[{}, {}, {}], |
| 881 | ) |
| 882 | await run_stream.response.aclose() |
| 883 | |
| 884 | @parametrize |
| 885 | async def test_raw_response_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 886 | response = await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 887 | "string", |
| 888 | thread_id="string", |
| 889 | stream=True, |
| 890 | tool_outputs=[{}, {}, {}], |
| 891 | ) |
| 892 | |
| 893 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 894 | stream = response.parse() |
| 895 | await stream.close() |
| 896 | |
| 897 | @parametrize |
| 898 | async def test_streaming_response_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 899 | async with async_client.beta.threads.runs.with_streaming_response.submit_tool_outputs( |
| 900 | "string", |
| 901 | thread_id="string", |
| 902 | stream=True, |
| 903 | tool_outputs=[{}, {}, {}], |
| 904 | ) as response: |
| 905 | assert not response.is_closed |
| 906 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 907 | |
| 908 | stream = await response.parse() |
| 909 | await stream.close() |
| 910 | |
| 911 | assert cast(Any, response.is_closed) is True |
| 912 | |
| 913 | @parametrize |
| 914 | async def test_path_params_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 915 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 916 | await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 917 | "string", |
| 918 | thread_id="", |
| 919 | stream=True, |
| 920 | tool_outputs=[{}, {}, {}], |
| 921 | ) |
| 922 | |
| 923 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 924 | await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 925 | "", |
| 926 | thread_id="string", |
| 927 | stream=True, |
| 928 | tool_outputs=[{}, {}, {}], |
| 929 | ) |
| 930 | |