openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
tests/api_resources/beta/threads/test_runs.py
651lines · modecode
| 1 | # File generated from our OpenAPI spec by Stainless. |
| 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._client import OpenAI, AsyncOpenAI |
| 13 | from openai.pagination import SyncCursorPage, AsyncCursorPage |
| 14 | from openai.types.beta.threads import ( |
| 15 | Run, |
| 16 | ) |
| 17 | |
| 18 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 19 | api_key = "My API Key" |
| 20 | |
| 21 | |
| 22 | class TestRuns: |
| 23 | strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True) |
| 24 | loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False) |
| 25 | parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"]) |
| 26 | |
| 27 | @parametrize |
| 28 | def test_method_create(self, client: OpenAI) -> None: |
| 29 | run = client.beta.threads.runs.create( |
| 30 | "string", |
| 31 | assistant_id="string", |
| 32 | ) |
| 33 | assert_matches_type(Run, run, path=["response"]) |
| 34 | |
| 35 | @parametrize |
| 36 | def test_method_create_with_all_params(self, client: OpenAI) -> None: |
| 37 | run = client.beta.threads.runs.create( |
| 38 | "string", |
| 39 | assistant_id="string", |
| 40 | additional_instructions="string", |
| 41 | instructions="string", |
| 42 | metadata={}, |
| 43 | model="string", |
| 44 | tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}], |
| 45 | ) |
| 46 | assert_matches_type(Run, run, path=["response"]) |
| 47 | |
| 48 | @parametrize |
| 49 | def test_raw_response_create(self, client: OpenAI) -> None: |
| 50 | response = client.beta.threads.runs.with_raw_response.create( |
| 51 | "string", |
| 52 | assistant_id="string", |
| 53 | ) |
| 54 | |
| 55 | assert response.is_closed is True |
| 56 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 57 | run = response.parse() |
| 58 | assert_matches_type(Run, run, path=["response"]) |
| 59 | |
| 60 | @parametrize |
| 61 | def test_streaming_response_create(self, client: OpenAI) -> None: |
| 62 | with client.beta.threads.runs.with_streaming_response.create( |
| 63 | "string", |
| 64 | assistant_id="string", |
| 65 | ) as response: |
| 66 | assert not response.is_closed |
| 67 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 68 | |
| 69 | run = response.parse() |
| 70 | assert_matches_type(Run, run, path=["response"]) |
| 71 | |
| 72 | assert cast(Any, response.is_closed) is True |
| 73 | |
| 74 | @parametrize |
| 75 | def test_path_params_create(self, client: OpenAI) -> None: |
| 76 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 77 | client.beta.threads.runs.with_raw_response.create( |
| 78 | "", |
| 79 | assistant_id="string", |
| 80 | ) |
| 81 | |
| 82 | @parametrize |
| 83 | def test_method_retrieve(self, client: OpenAI) -> None: |
| 84 | run = client.beta.threads.runs.retrieve( |
| 85 | "string", |
| 86 | thread_id="string", |
| 87 | ) |
| 88 | assert_matches_type(Run, run, path=["response"]) |
| 89 | |
| 90 | @parametrize |
| 91 | def test_raw_response_retrieve(self, client: OpenAI) -> None: |
| 92 | response = client.beta.threads.runs.with_raw_response.retrieve( |
| 93 | "string", |
| 94 | thread_id="string", |
| 95 | ) |
| 96 | |
| 97 | assert response.is_closed is True |
| 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_streaming_response_retrieve(self, client: OpenAI) -> None: |
| 104 | with client.beta.threads.runs.with_streaming_response.retrieve( |
| 105 | "string", |
| 106 | thread_id="string", |
| 107 | ) as response: |
| 108 | assert not response.is_closed |
| 109 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 110 | |
| 111 | run = response.parse() |
| 112 | assert_matches_type(Run, run, path=["response"]) |
| 113 | |
| 114 | assert cast(Any, response.is_closed) is True |
| 115 | |
| 116 | @parametrize |
| 117 | def test_path_params_retrieve(self, client: OpenAI) -> None: |
| 118 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 119 | client.beta.threads.runs.with_raw_response.retrieve( |
| 120 | "string", |
| 121 | thread_id="", |
| 122 | ) |
| 123 | |
| 124 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 125 | client.beta.threads.runs.with_raw_response.retrieve( |
| 126 | "", |
| 127 | thread_id="string", |
| 128 | ) |
| 129 | |
| 130 | @parametrize |
| 131 | def test_method_update(self, client: OpenAI) -> None: |
| 132 | run = client.beta.threads.runs.update( |
| 133 | "string", |
| 134 | thread_id="string", |
| 135 | ) |
| 136 | assert_matches_type(Run, run, path=["response"]) |
| 137 | |
| 138 | @parametrize |
| 139 | def test_method_update_with_all_params(self, client: OpenAI) -> None: |
| 140 | run = client.beta.threads.runs.update( |
| 141 | "string", |
| 142 | thread_id="string", |
| 143 | metadata={}, |
| 144 | ) |
| 145 | assert_matches_type(Run, run, path=["response"]) |
| 146 | |
| 147 | @parametrize |
| 148 | def test_raw_response_update(self, client: OpenAI) -> None: |
| 149 | response = client.beta.threads.runs.with_raw_response.update( |
| 150 | "string", |
| 151 | thread_id="string", |
| 152 | ) |
| 153 | |
| 154 | assert response.is_closed is True |
| 155 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 156 | run = response.parse() |
| 157 | assert_matches_type(Run, run, path=["response"]) |
| 158 | |
| 159 | @parametrize |
| 160 | def test_streaming_response_update(self, client: OpenAI) -> None: |
| 161 | with client.beta.threads.runs.with_streaming_response.update( |
| 162 | "string", |
| 163 | thread_id="string", |
| 164 | ) as response: |
| 165 | assert not response.is_closed |
| 166 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 167 | |
| 168 | run = response.parse() |
| 169 | assert_matches_type(Run, run, path=["response"]) |
| 170 | |
| 171 | assert cast(Any, response.is_closed) is True |
| 172 | |
| 173 | @parametrize |
| 174 | def test_path_params_update(self, client: OpenAI) -> None: |
| 175 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 176 | client.beta.threads.runs.with_raw_response.update( |
| 177 | "string", |
| 178 | thread_id="", |
| 179 | ) |
| 180 | |
| 181 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 182 | client.beta.threads.runs.with_raw_response.update( |
| 183 | "", |
| 184 | thread_id="string", |
| 185 | ) |
| 186 | |
| 187 | @parametrize |
| 188 | def test_method_list(self, client: OpenAI) -> None: |
| 189 | run = client.beta.threads.runs.list( |
| 190 | "string", |
| 191 | ) |
| 192 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 193 | |
| 194 | @parametrize |
| 195 | def test_method_list_with_all_params(self, client: OpenAI) -> None: |
| 196 | run = client.beta.threads.runs.list( |
| 197 | "string", |
| 198 | after="string", |
| 199 | before="string", |
| 200 | limit=0, |
| 201 | order="asc", |
| 202 | ) |
| 203 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 204 | |
| 205 | @parametrize |
| 206 | def test_raw_response_list(self, client: OpenAI) -> None: |
| 207 | response = client.beta.threads.runs.with_raw_response.list( |
| 208 | "string", |
| 209 | ) |
| 210 | |
| 211 | assert response.is_closed is True |
| 212 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 213 | run = response.parse() |
| 214 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 215 | |
| 216 | @parametrize |
| 217 | def test_streaming_response_list(self, client: OpenAI) -> None: |
| 218 | with client.beta.threads.runs.with_streaming_response.list( |
| 219 | "string", |
| 220 | ) as response: |
| 221 | assert not response.is_closed |
| 222 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 223 | |
| 224 | run = response.parse() |
| 225 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 226 | |
| 227 | assert cast(Any, response.is_closed) is True |
| 228 | |
| 229 | @parametrize |
| 230 | def test_path_params_list(self, client: OpenAI) -> None: |
| 231 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 232 | client.beta.threads.runs.with_raw_response.list( |
| 233 | "", |
| 234 | ) |
| 235 | |
| 236 | @parametrize |
| 237 | def test_method_cancel(self, client: OpenAI) -> None: |
| 238 | run = client.beta.threads.runs.cancel( |
| 239 | "string", |
| 240 | thread_id="string", |
| 241 | ) |
| 242 | assert_matches_type(Run, run, path=["response"]) |
| 243 | |
| 244 | @parametrize |
| 245 | def test_raw_response_cancel(self, client: OpenAI) -> None: |
| 246 | response = client.beta.threads.runs.with_raw_response.cancel( |
| 247 | "string", |
| 248 | thread_id="string", |
| 249 | ) |
| 250 | |
| 251 | assert response.is_closed is True |
| 252 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 253 | run = response.parse() |
| 254 | assert_matches_type(Run, run, path=["response"]) |
| 255 | |
| 256 | @parametrize |
| 257 | def test_streaming_response_cancel(self, client: OpenAI) -> None: |
| 258 | with client.beta.threads.runs.with_streaming_response.cancel( |
| 259 | "string", |
| 260 | thread_id="string", |
| 261 | ) as response: |
| 262 | assert not response.is_closed |
| 263 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 264 | |
| 265 | run = response.parse() |
| 266 | assert_matches_type(Run, run, path=["response"]) |
| 267 | |
| 268 | assert cast(Any, response.is_closed) is True |
| 269 | |
| 270 | @parametrize |
| 271 | def test_path_params_cancel(self, client: OpenAI) -> None: |
| 272 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 273 | client.beta.threads.runs.with_raw_response.cancel( |
| 274 | "string", |
| 275 | thread_id="", |
| 276 | ) |
| 277 | |
| 278 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 279 | client.beta.threads.runs.with_raw_response.cancel( |
| 280 | "", |
| 281 | thread_id="string", |
| 282 | ) |
| 283 | |
| 284 | @parametrize |
| 285 | def test_method_submit_tool_outputs(self, client: OpenAI) -> None: |
| 286 | run = client.beta.threads.runs.submit_tool_outputs( |
| 287 | "string", |
| 288 | thread_id="string", |
| 289 | tool_outputs=[{}, {}, {}], |
| 290 | ) |
| 291 | assert_matches_type(Run, run, path=["response"]) |
| 292 | |
| 293 | @parametrize |
| 294 | def test_raw_response_submit_tool_outputs(self, client: OpenAI) -> None: |
| 295 | response = client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 296 | "string", |
| 297 | thread_id="string", |
| 298 | tool_outputs=[{}, {}, {}], |
| 299 | ) |
| 300 | |
| 301 | assert response.is_closed is True |
| 302 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 303 | run = response.parse() |
| 304 | assert_matches_type(Run, run, path=["response"]) |
| 305 | |
| 306 | @parametrize |
| 307 | def test_streaming_response_submit_tool_outputs(self, client: OpenAI) -> None: |
| 308 | with client.beta.threads.runs.with_streaming_response.submit_tool_outputs( |
| 309 | "string", |
| 310 | thread_id="string", |
| 311 | tool_outputs=[{}, {}, {}], |
| 312 | ) as response: |
| 313 | assert not response.is_closed |
| 314 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 315 | |
| 316 | run = response.parse() |
| 317 | assert_matches_type(Run, run, path=["response"]) |
| 318 | |
| 319 | assert cast(Any, response.is_closed) is True |
| 320 | |
| 321 | @parametrize |
| 322 | def test_path_params_submit_tool_outputs(self, client: OpenAI) -> None: |
| 323 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 324 | client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 325 | "string", |
| 326 | thread_id="", |
| 327 | tool_outputs=[{}, {}, {}], |
| 328 | ) |
| 329 | |
| 330 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 331 | client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 332 | "", |
| 333 | thread_id="string", |
| 334 | tool_outputs=[{}, {}, {}], |
| 335 | ) |
| 336 | |
| 337 | |
| 338 | class TestAsyncRuns: |
| 339 | strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True) |
| 340 | loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False) |
| 341 | parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"]) |
| 342 | |
| 343 | @parametrize |
| 344 | async def test_method_create(self, client: AsyncOpenAI) -> None: |
| 345 | run = await client.beta.threads.runs.create( |
| 346 | "string", |
| 347 | assistant_id="string", |
| 348 | ) |
| 349 | assert_matches_type(Run, run, path=["response"]) |
| 350 | |
| 351 | @parametrize |
| 352 | async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None: |
| 353 | run = await client.beta.threads.runs.create( |
| 354 | "string", |
| 355 | assistant_id="string", |
| 356 | additional_instructions="string", |
| 357 | instructions="string", |
| 358 | metadata={}, |
| 359 | model="string", |
| 360 | tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}], |
| 361 | ) |
| 362 | assert_matches_type(Run, run, path=["response"]) |
| 363 | |
| 364 | @parametrize |
| 365 | async def test_raw_response_create(self, client: AsyncOpenAI) -> None: |
| 366 | response = await client.beta.threads.runs.with_raw_response.create( |
| 367 | "string", |
| 368 | assistant_id="string", |
| 369 | ) |
| 370 | |
| 371 | assert response.is_closed is True |
| 372 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 373 | run = response.parse() |
| 374 | assert_matches_type(Run, run, path=["response"]) |
| 375 | |
| 376 | @parametrize |
| 377 | async def test_streaming_response_create(self, client: AsyncOpenAI) -> None: |
| 378 | async with client.beta.threads.runs.with_streaming_response.create( |
| 379 | "string", |
| 380 | assistant_id="string", |
| 381 | ) as response: |
| 382 | assert not response.is_closed |
| 383 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 384 | |
| 385 | run = await response.parse() |
| 386 | assert_matches_type(Run, run, path=["response"]) |
| 387 | |
| 388 | assert cast(Any, response.is_closed) is True |
| 389 | |
| 390 | @parametrize |
| 391 | async def test_path_params_create(self, client: AsyncOpenAI) -> None: |
| 392 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 393 | await client.beta.threads.runs.with_raw_response.create( |
| 394 | "", |
| 395 | assistant_id="string", |
| 396 | ) |
| 397 | |
| 398 | @parametrize |
| 399 | async def test_method_retrieve(self, client: AsyncOpenAI) -> None: |
| 400 | run = await client.beta.threads.runs.retrieve( |
| 401 | "string", |
| 402 | thread_id="string", |
| 403 | ) |
| 404 | assert_matches_type(Run, run, path=["response"]) |
| 405 | |
| 406 | @parametrize |
| 407 | async def test_raw_response_retrieve(self, client: AsyncOpenAI) -> None: |
| 408 | response = await client.beta.threads.runs.with_raw_response.retrieve( |
| 409 | "string", |
| 410 | thread_id="string", |
| 411 | ) |
| 412 | |
| 413 | assert response.is_closed is True |
| 414 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 415 | run = response.parse() |
| 416 | assert_matches_type(Run, run, path=["response"]) |
| 417 | |
| 418 | @parametrize |
| 419 | async def test_streaming_response_retrieve(self, client: AsyncOpenAI) -> None: |
| 420 | async with client.beta.threads.runs.with_streaming_response.retrieve( |
| 421 | "string", |
| 422 | thread_id="string", |
| 423 | ) as response: |
| 424 | assert not response.is_closed |
| 425 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 426 | |
| 427 | run = await response.parse() |
| 428 | assert_matches_type(Run, run, path=["response"]) |
| 429 | |
| 430 | assert cast(Any, response.is_closed) is True |
| 431 | |
| 432 | @parametrize |
| 433 | async def test_path_params_retrieve(self, client: AsyncOpenAI) -> None: |
| 434 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 435 | await client.beta.threads.runs.with_raw_response.retrieve( |
| 436 | "string", |
| 437 | thread_id="", |
| 438 | ) |
| 439 | |
| 440 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 441 | await client.beta.threads.runs.with_raw_response.retrieve( |
| 442 | "", |
| 443 | thread_id="string", |
| 444 | ) |
| 445 | |
| 446 | @parametrize |
| 447 | async def test_method_update(self, client: AsyncOpenAI) -> None: |
| 448 | run = await client.beta.threads.runs.update( |
| 449 | "string", |
| 450 | thread_id="string", |
| 451 | ) |
| 452 | assert_matches_type(Run, run, path=["response"]) |
| 453 | |
| 454 | @parametrize |
| 455 | async def test_method_update_with_all_params(self, client: AsyncOpenAI) -> None: |
| 456 | run = await client.beta.threads.runs.update( |
| 457 | "string", |
| 458 | thread_id="string", |
| 459 | metadata={}, |
| 460 | ) |
| 461 | assert_matches_type(Run, run, path=["response"]) |
| 462 | |
| 463 | @parametrize |
| 464 | async def test_raw_response_update(self, client: AsyncOpenAI) -> None: |
| 465 | response = await client.beta.threads.runs.with_raw_response.update( |
| 466 | "string", |
| 467 | thread_id="string", |
| 468 | ) |
| 469 | |
| 470 | assert response.is_closed is True |
| 471 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 472 | run = response.parse() |
| 473 | assert_matches_type(Run, run, path=["response"]) |
| 474 | |
| 475 | @parametrize |
| 476 | async def test_streaming_response_update(self, client: AsyncOpenAI) -> None: |
| 477 | async with client.beta.threads.runs.with_streaming_response.update( |
| 478 | "string", |
| 479 | thread_id="string", |
| 480 | ) as response: |
| 481 | assert not response.is_closed |
| 482 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 483 | |
| 484 | run = await response.parse() |
| 485 | assert_matches_type(Run, run, path=["response"]) |
| 486 | |
| 487 | assert cast(Any, response.is_closed) is True |
| 488 | |
| 489 | @parametrize |
| 490 | async def test_path_params_update(self, client: AsyncOpenAI) -> None: |
| 491 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 492 | await client.beta.threads.runs.with_raw_response.update( |
| 493 | "string", |
| 494 | thread_id="", |
| 495 | ) |
| 496 | |
| 497 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 498 | await client.beta.threads.runs.with_raw_response.update( |
| 499 | "", |
| 500 | thread_id="string", |
| 501 | ) |
| 502 | |
| 503 | @parametrize |
| 504 | async def test_method_list(self, client: AsyncOpenAI) -> None: |
| 505 | run = await client.beta.threads.runs.list( |
| 506 | "string", |
| 507 | ) |
| 508 | assert_matches_type(AsyncCursorPage[Run], run, path=["response"]) |
| 509 | |
| 510 | @parametrize |
| 511 | async def test_method_list_with_all_params(self, client: AsyncOpenAI) -> None: |
| 512 | run = await client.beta.threads.runs.list( |
| 513 | "string", |
| 514 | after="string", |
| 515 | before="string", |
| 516 | limit=0, |
| 517 | order="asc", |
| 518 | ) |
| 519 | assert_matches_type(AsyncCursorPage[Run], run, path=["response"]) |
| 520 | |
| 521 | @parametrize |
| 522 | async def test_raw_response_list(self, client: AsyncOpenAI) -> None: |
| 523 | response = await client.beta.threads.runs.with_raw_response.list( |
| 524 | "string", |
| 525 | ) |
| 526 | |
| 527 | assert response.is_closed is True |
| 528 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 529 | run = response.parse() |
| 530 | assert_matches_type(AsyncCursorPage[Run], run, path=["response"]) |
| 531 | |
| 532 | @parametrize |
| 533 | async def test_streaming_response_list(self, client: AsyncOpenAI) -> None: |
| 534 | async with client.beta.threads.runs.with_streaming_response.list( |
| 535 | "string", |
| 536 | ) as response: |
| 537 | assert not response.is_closed |
| 538 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 539 | |
| 540 | run = await response.parse() |
| 541 | assert_matches_type(AsyncCursorPage[Run], run, path=["response"]) |
| 542 | |
| 543 | assert cast(Any, response.is_closed) is True |
| 544 | |
| 545 | @parametrize |
| 546 | async def test_path_params_list(self, client: AsyncOpenAI) -> None: |
| 547 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 548 | await client.beta.threads.runs.with_raw_response.list( |
| 549 | "", |
| 550 | ) |
| 551 | |
| 552 | @parametrize |
| 553 | async def test_method_cancel(self, client: AsyncOpenAI) -> None: |
| 554 | run = await client.beta.threads.runs.cancel( |
| 555 | "string", |
| 556 | thread_id="string", |
| 557 | ) |
| 558 | assert_matches_type(Run, run, path=["response"]) |
| 559 | |
| 560 | @parametrize |
| 561 | async def test_raw_response_cancel(self, client: AsyncOpenAI) -> None: |
| 562 | response = await client.beta.threads.runs.with_raw_response.cancel( |
| 563 | "string", |
| 564 | thread_id="string", |
| 565 | ) |
| 566 | |
| 567 | assert response.is_closed is True |
| 568 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 569 | run = response.parse() |
| 570 | assert_matches_type(Run, run, path=["response"]) |
| 571 | |
| 572 | @parametrize |
| 573 | async def test_streaming_response_cancel(self, client: AsyncOpenAI) -> None: |
| 574 | async with client.beta.threads.runs.with_streaming_response.cancel( |
| 575 | "string", |
| 576 | thread_id="string", |
| 577 | ) as response: |
| 578 | assert not response.is_closed |
| 579 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 580 | |
| 581 | run = await response.parse() |
| 582 | assert_matches_type(Run, run, path=["response"]) |
| 583 | |
| 584 | assert cast(Any, response.is_closed) is True |
| 585 | |
| 586 | @parametrize |
| 587 | async def test_path_params_cancel(self, client: AsyncOpenAI) -> None: |
| 588 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 589 | await client.beta.threads.runs.with_raw_response.cancel( |
| 590 | "string", |
| 591 | thread_id="", |
| 592 | ) |
| 593 | |
| 594 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 595 | await client.beta.threads.runs.with_raw_response.cancel( |
| 596 | "", |
| 597 | thread_id="string", |
| 598 | ) |
| 599 | |
| 600 | @parametrize |
| 601 | async def test_method_submit_tool_outputs(self, client: AsyncOpenAI) -> None: |
| 602 | run = await client.beta.threads.runs.submit_tool_outputs( |
| 603 | "string", |
| 604 | thread_id="string", |
| 605 | tool_outputs=[{}, {}, {}], |
| 606 | ) |
| 607 | assert_matches_type(Run, run, path=["response"]) |
| 608 | |
| 609 | @parametrize |
| 610 | async def test_raw_response_submit_tool_outputs(self, client: AsyncOpenAI) -> None: |
| 611 | response = await client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 612 | "string", |
| 613 | thread_id="string", |
| 614 | tool_outputs=[{}, {}, {}], |
| 615 | ) |
| 616 | |
| 617 | assert response.is_closed is True |
| 618 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 619 | run = response.parse() |
| 620 | assert_matches_type(Run, run, path=["response"]) |
| 621 | |
| 622 | @parametrize |
| 623 | async def test_streaming_response_submit_tool_outputs(self, client: AsyncOpenAI) -> None: |
| 624 | async with client.beta.threads.runs.with_streaming_response.submit_tool_outputs( |
| 625 | "string", |
| 626 | thread_id="string", |
| 627 | tool_outputs=[{}, {}, {}], |
| 628 | ) as response: |
| 629 | assert not response.is_closed |
| 630 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 631 | |
| 632 | run = await response.parse() |
| 633 | assert_matches_type(Run, run, path=["response"]) |
| 634 | |
| 635 | assert cast(Any, response.is_closed) is True |
| 636 | |
| 637 | @parametrize |
| 638 | async def test_path_params_submit_tool_outputs(self, client: AsyncOpenAI) -> None: |
| 639 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 640 | await client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 641 | "string", |
| 642 | thread_id="", |
| 643 | tool_outputs=[{}, {}, {}], |
| 644 | ) |
| 645 | |
| 646 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 647 | await client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 648 | "", |
| 649 | thread_id="string", |
| 650 | tool_outputs=[{}, {}, {}], |
| 651 | ) |
| 652 | |