openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
tests/api_resources/beta/threads/test_runs.py
1347lines · 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 | # pyright: reportDeprecated=false |
| 18 | |
| 19 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 20 | |
| 21 | |
| 22 | class TestRuns: |
| 23 | parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
| 24 | |
| 25 | @parametrize |
| 26 | def test_method_create_overload_1(self, client: OpenAI) -> None: |
| 27 | run = client.beta.threads.runs.create( |
| 28 | "string", |
| 29 | assistant_id="string", |
| 30 | ) |
| 31 | assert_matches_type(Run, run, path=["response"]) |
| 32 | |
| 33 | @parametrize |
| 34 | def test_method_create_with_all_params_overload_1(self, client: OpenAI) -> None: |
| 35 | run = client.beta.threads.runs.create( |
| 36 | "string", |
| 37 | assistant_id="string", |
| 38 | additional_instructions="string", |
| 39 | additional_messages=[ |
| 40 | { |
| 41 | "role": "user", |
| 42 | "content": "x", |
| 43 | "attachments": [ |
| 44 | { |
| 45 | "file_id": "string", |
| 46 | "tools": [ |
| 47 | {"type": "code_interpreter"}, |
| 48 | {"type": "code_interpreter"}, |
| 49 | {"type": "code_interpreter"}, |
| 50 | ], |
| 51 | }, |
| 52 | { |
| 53 | "file_id": "string", |
| 54 | "tools": [ |
| 55 | {"type": "code_interpreter"}, |
| 56 | {"type": "code_interpreter"}, |
| 57 | {"type": "code_interpreter"}, |
| 58 | ], |
| 59 | }, |
| 60 | { |
| 61 | "file_id": "string", |
| 62 | "tools": [ |
| 63 | {"type": "code_interpreter"}, |
| 64 | {"type": "code_interpreter"}, |
| 65 | {"type": "code_interpreter"}, |
| 66 | ], |
| 67 | }, |
| 68 | ], |
| 69 | "metadata": {}, |
| 70 | }, |
| 71 | { |
| 72 | "role": "user", |
| 73 | "content": "x", |
| 74 | "attachments": [ |
| 75 | { |
| 76 | "file_id": "string", |
| 77 | "tools": [ |
| 78 | {"type": "code_interpreter"}, |
| 79 | {"type": "code_interpreter"}, |
| 80 | {"type": "code_interpreter"}, |
| 81 | ], |
| 82 | }, |
| 83 | { |
| 84 | "file_id": "string", |
| 85 | "tools": [ |
| 86 | {"type": "code_interpreter"}, |
| 87 | {"type": "code_interpreter"}, |
| 88 | {"type": "code_interpreter"}, |
| 89 | ], |
| 90 | }, |
| 91 | { |
| 92 | "file_id": "string", |
| 93 | "tools": [ |
| 94 | {"type": "code_interpreter"}, |
| 95 | {"type": "code_interpreter"}, |
| 96 | {"type": "code_interpreter"}, |
| 97 | ], |
| 98 | }, |
| 99 | ], |
| 100 | "metadata": {}, |
| 101 | }, |
| 102 | { |
| 103 | "role": "user", |
| 104 | "content": "x", |
| 105 | "attachments": [ |
| 106 | { |
| 107 | "file_id": "string", |
| 108 | "tools": [ |
| 109 | {"type": "code_interpreter"}, |
| 110 | {"type": "code_interpreter"}, |
| 111 | {"type": "code_interpreter"}, |
| 112 | ], |
| 113 | }, |
| 114 | { |
| 115 | "file_id": "string", |
| 116 | "tools": [ |
| 117 | {"type": "code_interpreter"}, |
| 118 | {"type": "code_interpreter"}, |
| 119 | {"type": "code_interpreter"}, |
| 120 | ], |
| 121 | }, |
| 122 | { |
| 123 | "file_id": "string", |
| 124 | "tools": [ |
| 125 | {"type": "code_interpreter"}, |
| 126 | {"type": "code_interpreter"}, |
| 127 | {"type": "code_interpreter"}, |
| 128 | ], |
| 129 | }, |
| 130 | ], |
| 131 | "metadata": {}, |
| 132 | }, |
| 133 | ], |
| 134 | instructions="string", |
| 135 | max_completion_tokens=256, |
| 136 | max_prompt_tokens=256, |
| 137 | metadata={}, |
| 138 | model="gpt-4-turbo", |
| 139 | response_format="none", |
| 140 | stream=False, |
| 141 | temperature=1, |
| 142 | tool_choice="none", |
| 143 | tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}], |
| 144 | top_p=1, |
| 145 | truncation_strategy={ |
| 146 | "type": "auto", |
| 147 | "last_messages": 1, |
| 148 | }, |
| 149 | ) |
| 150 | assert_matches_type(Run, run, path=["response"]) |
| 151 | |
| 152 | @parametrize |
| 153 | def test_raw_response_create_overload_1(self, client: OpenAI) -> None: |
| 154 | response = client.beta.threads.runs.with_raw_response.create( |
| 155 | "string", |
| 156 | assistant_id="string", |
| 157 | ) |
| 158 | |
| 159 | assert response.is_closed is True |
| 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 | @parametrize |
| 165 | def test_streaming_response_create_overload_1(self, client: OpenAI) -> None: |
| 166 | with client.beta.threads.runs.with_streaming_response.create( |
| 167 | "string", |
| 168 | assistant_id="string", |
| 169 | ) as response: |
| 170 | assert not response.is_closed |
| 171 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 172 | |
| 173 | run = response.parse() |
| 174 | assert_matches_type(Run, run, path=["response"]) |
| 175 | |
| 176 | assert cast(Any, response.is_closed) is True |
| 177 | |
| 178 | @parametrize |
| 179 | def test_path_params_create_overload_1(self, client: OpenAI) -> None: |
| 180 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 181 | client.beta.threads.runs.with_raw_response.create( |
| 182 | "", |
| 183 | assistant_id="string", |
| 184 | ) |
| 185 | |
| 186 | @parametrize |
| 187 | def test_method_create_overload_2(self, client: OpenAI) -> None: |
| 188 | run_stream = client.beta.threads.runs.create( |
| 189 | "string", |
| 190 | assistant_id="string", |
| 191 | stream=True, |
| 192 | ) |
| 193 | run_stream.response.close() |
| 194 | |
| 195 | @parametrize |
| 196 | def test_method_create_with_all_params_overload_2(self, client: OpenAI) -> None: |
| 197 | run_stream = client.beta.threads.runs.create( |
| 198 | "string", |
| 199 | assistant_id="string", |
| 200 | stream=True, |
| 201 | additional_instructions="string", |
| 202 | additional_messages=[ |
| 203 | { |
| 204 | "role": "user", |
| 205 | "content": "x", |
| 206 | "attachments": [ |
| 207 | { |
| 208 | "file_id": "string", |
| 209 | "tools": [ |
| 210 | {"type": "code_interpreter"}, |
| 211 | {"type": "code_interpreter"}, |
| 212 | {"type": "code_interpreter"}, |
| 213 | ], |
| 214 | }, |
| 215 | { |
| 216 | "file_id": "string", |
| 217 | "tools": [ |
| 218 | {"type": "code_interpreter"}, |
| 219 | {"type": "code_interpreter"}, |
| 220 | {"type": "code_interpreter"}, |
| 221 | ], |
| 222 | }, |
| 223 | { |
| 224 | "file_id": "string", |
| 225 | "tools": [ |
| 226 | {"type": "code_interpreter"}, |
| 227 | {"type": "code_interpreter"}, |
| 228 | {"type": "code_interpreter"}, |
| 229 | ], |
| 230 | }, |
| 231 | ], |
| 232 | "metadata": {}, |
| 233 | }, |
| 234 | { |
| 235 | "role": "user", |
| 236 | "content": "x", |
| 237 | "attachments": [ |
| 238 | { |
| 239 | "file_id": "string", |
| 240 | "tools": [ |
| 241 | {"type": "code_interpreter"}, |
| 242 | {"type": "code_interpreter"}, |
| 243 | {"type": "code_interpreter"}, |
| 244 | ], |
| 245 | }, |
| 246 | { |
| 247 | "file_id": "string", |
| 248 | "tools": [ |
| 249 | {"type": "code_interpreter"}, |
| 250 | {"type": "code_interpreter"}, |
| 251 | {"type": "code_interpreter"}, |
| 252 | ], |
| 253 | }, |
| 254 | { |
| 255 | "file_id": "string", |
| 256 | "tools": [ |
| 257 | {"type": "code_interpreter"}, |
| 258 | {"type": "code_interpreter"}, |
| 259 | {"type": "code_interpreter"}, |
| 260 | ], |
| 261 | }, |
| 262 | ], |
| 263 | "metadata": {}, |
| 264 | }, |
| 265 | { |
| 266 | "role": "user", |
| 267 | "content": "x", |
| 268 | "attachments": [ |
| 269 | { |
| 270 | "file_id": "string", |
| 271 | "tools": [ |
| 272 | {"type": "code_interpreter"}, |
| 273 | {"type": "code_interpreter"}, |
| 274 | {"type": "code_interpreter"}, |
| 275 | ], |
| 276 | }, |
| 277 | { |
| 278 | "file_id": "string", |
| 279 | "tools": [ |
| 280 | {"type": "code_interpreter"}, |
| 281 | {"type": "code_interpreter"}, |
| 282 | {"type": "code_interpreter"}, |
| 283 | ], |
| 284 | }, |
| 285 | { |
| 286 | "file_id": "string", |
| 287 | "tools": [ |
| 288 | {"type": "code_interpreter"}, |
| 289 | {"type": "code_interpreter"}, |
| 290 | {"type": "code_interpreter"}, |
| 291 | ], |
| 292 | }, |
| 293 | ], |
| 294 | "metadata": {}, |
| 295 | }, |
| 296 | ], |
| 297 | instructions="string", |
| 298 | max_completion_tokens=256, |
| 299 | max_prompt_tokens=256, |
| 300 | metadata={}, |
| 301 | model="gpt-4-turbo", |
| 302 | response_format="none", |
| 303 | temperature=1, |
| 304 | tool_choice="none", |
| 305 | tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}], |
| 306 | top_p=1, |
| 307 | truncation_strategy={ |
| 308 | "type": "auto", |
| 309 | "last_messages": 1, |
| 310 | }, |
| 311 | ) |
| 312 | run_stream.response.close() |
| 313 | |
| 314 | @parametrize |
| 315 | def test_raw_response_create_overload_2(self, client: OpenAI) -> None: |
| 316 | response = client.beta.threads.runs.with_raw_response.create( |
| 317 | "string", |
| 318 | assistant_id="string", |
| 319 | stream=True, |
| 320 | ) |
| 321 | |
| 322 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 323 | stream = response.parse() |
| 324 | stream.close() |
| 325 | |
| 326 | @parametrize |
| 327 | def test_streaming_response_create_overload_2(self, client: OpenAI) -> None: |
| 328 | with client.beta.threads.runs.with_streaming_response.create( |
| 329 | "string", |
| 330 | assistant_id="string", |
| 331 | stream=True, |
| 332 | ) as response: |
| 333 | assert not response.is_closed |
| 334 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 335 | |
| 336 | stream = response.parse() |
| 337 | stream.close() |
| 338 | |
| 339 | assert cast(Any, response.is_closed) is True |
| 340 | |
| 341 | @parametrize |
| 342 | def test_path_params_create_overload_2(self, client: OpenAI) -> None: |
| 343 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 344 | client.beta.threads.runs.with_raw_response.create( |
| 345 | "", |
| 346 | assistant_id="string", |
| 347 | stream=True, |
| 348 | ) |
| 349 | |
| 350 | @parametrize |
| 351 | def test_method_retrieve(self, client: OpenAI) -> None: |
| 352 | run = client.beta.threads.runs.retrieve( |
| 353 | "string", |
| 354 | thread_id="string", |
| 355 | ) |
| 356 | assert_matches_type(Run, run, path=["response"]) |
| 357 | |
| 358 | @parametrize |
| 359 | def test_raw_response_retrieve(self, client: OpenAI) -> None: |
| 360 | response = client.beta.threads.runs.with_raw_response.retrieve( |
| 361 | "string", |
| 362 | thread_id="string", |
| 363 | ) |
| 364 | |
| 365 | assert response.is_closed is True |
| 366 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 367 | run = response.parse() |
| 368 | assert_matches_type(Run, run, path=["response"]) |
| 369 | |
| 370 | @parametrize |
| 371 | def test_streaming_response_retrieve(self, client: OpenAI) -> None: |
| 372 | with client.beta.threads.runs.with_streaming_response.retrieve( |
| 373 | "string", |
| 374 | thread_id="string", |
| 375 | ) as response: |
| 376 | assert not response.is_closed |
| 377 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 378 | |
| 379 | run = response.parse() |
| 380 | assert_matches_type(Run, run, path=["response"]) |
| 381 | |
| 382 | assert cast(Any, response.is_closed) is True |
| 383 | |
| 384 | @parametrize |
| 385 | def test_path_params_retrieve(self, client: OpenAI) -> None: |
| 386 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 387 | client.beta.threads.runs.with_raw_response.retrieve( |
| 388 | "string", |
| 389 | thread_id="", |
| 390 | ) |
| 391 | |
| 392 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 393 | client.beta.threads.runs.with_raw_response.retrieve( |
| 394 | "", |
| 395 | thread_id="string", |
| 396 | ) |
| 397 | |
| 398 | @parametrize |
| 399 | def test_method_update(self, client: OpenAI) -> None: |
| 400 | run = client.beta.threads.runs.update( |
| 401 | "string", |
| 402 | thread_id="string", |
| 403 | ) |
| 404 | assert_matches_type(Run, run, path=["response"]) |
| 405 | |
| 406 | @parametrize |
| 407 | def test_method_update_with_all_params(self, client: OpenAI) -> None: |
| 408 | run = client.beta.threads.runs.update( |
| 409 | "string", |
| 410 | thread_id="string", |
| 411 | metadata={}, |
| 412 | ) |
| 413 | assert_matches_type(Run, run, path=["response"]) |
| 414 | |
| 415 | @parametrize |
| 416 | def test_raw_response_update(self, client: OpenAI) -> None: |
| 417 | response = client.beta.threads.runs.with_raw_response.update( |
| 418 | "string", |
| 419 | thread_id="string", |
| 420 | ) |
| 421 | |
| 422 | assert response.is_closed is True |
| 423 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 424 | run = response.parse() |
| 425 | assert_matches_type(Run, run, path=["response"]) |
| 426 | |
| 427 | @parametrize |
| 428 | def test_streaming_response_update(self, client: OpenAI) -> None: |
| 429 | with client.beta.threads.runs.with_streaming_response.update( |
| 430 | "string", |
| 431 | thread_id="string", |
| 432 | ) as response: |
| 433 | assert not response.is_closed |
| 434 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 435 | |
| 436 | run = response.parse() |
| 437 | assert_matches_type(Run, run, path=["response"]) |
| 438 | |
| 439 | assert cast(Any, response.is_closed) is True |
| 440 | |
| 441 | @parametrize |
| 442 | def test_path_params_update(self, client: OpenAI) -> None: |
| 443 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 444 | client.beta.threads.runs.with_raw_response.update( |
| 445 | "string", |
| 446 | thread_id="", |
| 447 | ) |
| 448 | |
| 449 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 450 | client.beta.threads.runs.with_raw_response.update( |
| 451 | "", |
| 452 | thread_id="string", |
| 453 | ) |
| 454 | |
| 455 | @parametrize |
| 456 | def test_method_list(self, client: OpenAI) -> None: |
| 457 | run = client.beta.threads.runs.list( |
| 458 | "string", |
| 459 | ) |
| 460 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 461 | |
| 462 | @parametrize |
| 463 | def test_method_list_with_all_params(self, client: OpenAI) -> None: |
| 464 | run = client.beta.threads.runs.list( |
| 465 | "string", |
| 466 | after="string", |
| 467 | before="string", |
| 468 | limit=0, |
| 469 | order="asc", |
| 470 | ) |
| 471 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 472 | |
| 473 | @parametrize |
| 474 | def test_raw_response_list(self, client: OpenAI) -> None: |
| 475 | response = client.beta.threads.runs.with_raw_response.list( |
| 476 | "string", |
| 477 | ) |
| 478 | |
| 479 | assert response.is_closed is True |
| 480 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 481 | run = response.parse() |
| 482 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 483 | |
| 484 | @parametrize |
| 485 | def test_streaming_response_list(self, client: OpenAI) -> None: |
| 486 | with client.beta.threads.runs.with_streaming_response.list( |
| 487 | "string", |
| 488 | ) as response: |
| 489 | assert not response.is_closed |
| 490 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 491 | |
| 492 | run = response.parse() |
| 493 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 494 | |
| 495 | assert cast(Any, response.is_closed) is True |
| 496 | |
| 497 | @parametrize |
| 498 | def test_path_params_list(self, client: OpenAI) -> None: |
| 499 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 500 | client.beta.threads.runs.with_raw_response.list( |
| 501 | "", |
| 502 | ) |
| 503 | |
| 504 | @parametrize |
| 505 | def test_method_cancel(self, client: OpenAI) -> None: |
| 506 | run = client.beta.threads.runs.cancel( |
| 507 | "string", |
| 508 | thread_id="string", |
| 509 | ) |
| 510 | assert_matches_type(Run, run, path=["response"]) |
| 511 | |
| 512 | @parametrize |
| 513 | def test_raw_response_cancel(self, client: OpenAI) -> None: |
| 514 | response = client.beta.threads.runs.with_raw_response.cancel( |
| 515 | "string", |
| 516 | thread_id="string", |
| 517 | ) |
| 518 | |
| 519 | assert response.is_closed is True |
| 520 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 521 | run = response.parse() |
| 522 | assert_matches_type(Run, run, path=["response"]) |
| 523 | |
| 524 | @parametrize |
| 525 | def test_streaming_response_cancel(self, client: OpenAI) -> None: |
| 526 | with client.beta.threads.runs.with_streaming_response.cancel( |
| 527 | "string", |
| 528 | thread_id="string", |
| 529 | ) as response: |
| 530 | assert not response.is_closed |
| 531 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 532 | |
| 533 | run = response.parse() |
| 534 | assert_matches_type(Run, run, path=["response"]) |
| 535 | |
| 536 | assert cast(Any, response.is_closed) is True |
| 537 | |
| 538 | @parametrize |
| 539 | def test_path_params_cancel(self, client: OpenAI) -> None: |
| 540 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 541 | client.beta.threads.runs.with_raw_response.cancel( |
| 542 | "string", |
| 543 | thread_id="", |
| 544 | ) |
| 545 | |
| 546 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 547 | client.beta.threads.runs.with_raw_response.cancel( |
| 548 | "", |
| 549 | thread_id="string", |
| 550 | ) |
| 551 | |
| 552 | @parametrize |
| 553 | def test_method_submit_tool_outputs_overload_1(self, client: OpenAI) -> None: |
| 554 | run = client.beta.threads.runs.submit_tool_outputs( |
| 555 | "string", |
| 556 | thread_id="string", |
| 557 | tool_outputs=[{}, {}, {}], |
| 558 | ) |
| 559 | assert_matches_type(Run, run, path=["response"]) |
| 560 | |
| 561 | @parametrize |
| 562 | def test_method_submit_tool_outputs_with_all_params_overload_1(self, client: OpenAI) -> None: |
| 563 | run = client.beta.threads.runs.submit_tool_outputs( |
| 564 | "string", |
| 565 | thread_id="string", |
| 566 | tool_outputs=[ |
| 567 | { |
| 568 | "tool_call_id": "string", |
| 569 | "output": "string", |
| 570 | }, |
| 571 | { |
| 572 | "tool_call_id": "string", |
| 573 | "output": "string", |
| 574 | }, |
| 575 | { |
| 576 | "tool_call_id": "string", |
| 577 | "output": "string", |
| 578 | }, |
| 579 | ], |
| 580 | stream=False, |
| 581 | ) |
| 582 | assert_matches_type(Run, run, path=["response"]) |
| 583 | |
| 584 | @parametrize |
| 585 | def test_raw_response_submit_tool_outputs_overload_1(self, client: OpenAI) -> None: |
| 586 | response = client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 587 | "string", |
| 588 | thread_id="string", |
| 589 | tool_outputs=[{}, {}, {}], |
| 590 | ) |
| 591 | |
| 592 | assert response.is_closed is True |
| 593 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 594 | run = response.parse() |
| 595 | assert_matches_type(Run, run, path=["response"]) |
| 596 | |
| 597 | @parametrize |
| 598 | def test_streaming_response_submit_tool_outputs_overload_1(self, client: OpenAI) -> None: |
| 599 | with client.beta.threads.runs.with_streaming_response.submit_tool_outputs( |
| 600 | "string", |
| 601 | thread_id="string", |
| 602 | tool_outputs=[{}, {}, {}], |
| 603 | ) as response: |
| 604 | assert not response.is_closed |
| 605 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 606 | |
| 607 | run = response.parse() |
| 608 | assert_matches_type(Run, run, path=["response"]) |
| 609 | |
| 610 | assert cast(Any, response.is_closed) is True |
| 611 | |
| 612 | @parametrize |
| 613 | def test_path_params_submit_tool_outputs_overload_1(self, client: OpenAI) -> None: |
| 614 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 615 | client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 616 | "string", |
| 617 | thread_id="", |
| 618 | tool_outputs=[{}, {}, {}], |
| 619 | ) |
| 620 | |
| 621 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 622 | client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 623 | "", |
| 624 | thread_id="string", |
| 625 | tool_outputs=[{}, {}, {}], |
| 626 | ) |
| 627 | |
| 628 | @parametrize |
| 629 | def test_method_submit_tool_outputs_overload_2(self, client: OpenAI) -> None: |
| 630 | run_stream = client.beta.threads.runs.submit_tool_outputs( |
| 631 | "string", |
| 632 | thread_id="string", |
| 633 | stream=True, |
| 634 | tool_outputs=[{}, {}, {}], |
| 635 | ) |
| 636 | run_stream.response.close() |
| 637 | |
| 638 | @parametrize |
| 639 | def test_raw_response_submit_tool_outputs_overload_2(self, client: OpenAI) -> None: |
| 640 | response = client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 641 | "string", |
| 642 | thread_id="string", |
| 643 | stream=True, |
| 644 | tool_outputs=[{}, {}, {}], |
| 645 | ) |
| 646 | |
| 647 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 648 | stream = response.parse() |
| 649 | stream.close() |
| 650 | |
| 651 | @parametrize |
| 652 | def test_streaming_response_submit_tool_outputs_overload_2(self, client: OpenAI) -> None: |
| 653 | with client.beta.threads.runs.with_streaming_response.submit_tool_outputs( |
| 654 | "string", |
| 655 | thread_id="string", |
| 656 | stream=True, |
| 657 | tool_outputs=[{}, {}, {}], |
| 658 | ) as response: |
| 659 | assert not response.is_closed |
| 660 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 661 | |
| 662 | stream = response.parse() |
| 663 | stream.close() |
| 664 | |
| 665 | assert cast(Any, response.is_closed) is True |
| 666 | |
| 667 | @parametrize |
| 668 | def test_path_params_submit_tool_outputs_overload_2(self, client: OpenAI) -> None: |
| 669 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 670 | client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 671 | "string", |
| 672 | thread_id="", |
| 673 | stream=True, |
| 674 | tool_outputs=[{}, {}, {}], |
| 675 | ) |
| 676 | |
| 677 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 678 | client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 679 | "", |
| 680 | thread_id="string", |
| 681 | stream=True, |
| 682 | tool_outputs=[{}, {}, {}], |
| 683 | ) |
| 684 | |
| 685 | |
| 686 | class TestAsyncRuns: |
| 687 | parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) |
| 688 | |
| 689 | @parametrize |
| 690 | async def test_method_create_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 691 | run = await async_client.beta.threads.runs.create( |
| 692 | "string", |
| 693 | assistant_id="string", |
| 694 | ) |
| 695 | assert_matches_type(Run, run, path=["response"]) |
| 696 | |
| 697 | @parametrize |
| 698 | async def test_method_create_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 699 | run = await async_client.beta.threads.runs.create( |
| 700 | "string", |
| 701 | assistant_id="string", |
| 702 | additional_instructions="string", |
| 703 | additional_messages=[ |
| 704 | { |
| 705 | "role": "user", |
| 706 | "content": "x", |
| 707 | "attachments": [ |
| 708 | { |
| 709 | "file_id": "string", |
| 710 | "tools": [ |
| 711 | {"type": "code_interpreter"}, |
| 712 | {"type": "code_interpreter"}, |
| 713 | {"type": "code_interpreter"}, |
| 714 | ], |
| 715 | }, |
| 716 | { |
| 717 | "file_id": "string", |
| 718 | "tools": [ |
| 719 | {"type": "code_interpreter"}, |
| 720 | {"type": "code_interpreter"}, |
| 721 | {"type": "code_interpreter"}, |
| 722 | ], |
| 723 | }, |
| 724 | { |
| 725 | "file_id": "string", |
| 726 | "tools": [ |
| 727 | {"type": "code_interpreter"}, |
| 728 | {"type": "code_interpreter"}, |
| 729 | {"type": "code_interpreter"}, |
| 730 | ], |
| 731 | }, |
| 732 | ], |
| 733 | "metadata": {}, |
| 734 | }, |
| 735 | { |
| 736 | "role": "user", |
| 737 | "content": "x", |
| 738 | "attachments": [ |
| 739 | { |
| 740 | "file_id": "string", |
| 741 | "tools": [ |
| 742 | {"type": "code_interpreter"}, |
| 743 | {"type": "code_interpreter"}, |
| 744 | {"type": "code_interpreter"}, |
| 745 | ], |
| 746 | }, |
| 747 | { |
| 748 | "file_id": "string", |
| 749 | "tools": [ |
| 750 | {"type": "code_interpreter"}, |
| 751 | {"type": "code_interpreter"}, |
| 752 | {"type": "code_interpreter"}, |
| 753 | ], |
| 754 | }, |
| 755 | { |
| 756 | "file_id": "string", |
| 757 | "tools": [ |
| 758 | {"type": "code_interpreter"}, |
| 759 | {"type": "code_interpreter"}, |
| 760 | {"type": "code_interpreter"}, |
| 761 | ], |
| 762 | }, |
| 763 | ], |
| 764 | "metadata": {}, |
| 765 | }, |
| 766 | { |
| 767 | "role": "user", |
| 768 | "content": "x", |
| 769 | "attachments": [ |
| 770 | { |
| 771 | "file_id": "string", |
| 772 | "tools": [ |
| 773 | {"type": "code_interpreter"}, |
| 774 | {"type": "code_interpreter"}, |
| 775 | {"type": "code_interpreter"}, |
| 776 | ], |
| 777 | }, |
| 778 | { |
| 779 | "file_id": "string", |
| 780 | "tools": [ |
| 781 | {"type": "code_interpreter"}, |
| 782 | {"type": "code_interpreter"}, |
| 783 | {"type": "code_interpreter"}, |
| 784 | ], |
| 785 | }, |
| 786 | { |
| 787 | "file_id": "string", |
| 788 | "tools": [ |
| 789 | {"type": "code_interpreter"}, |
| 790 | {"type": "code_interpreter"}, |
| 791 | {"type": "code_interpreter"}, |
| 792 | ], |
| 793 | }, |
| 794 | ], |
| 795 | "metadata": {}, |
| 796 | }, |
| 797 | ], |
| 798 | instructions="string", |
| 799 | max_completion_tokens=256, |
| 800 | max_prompt_tokens=256, |
| 801 | metadata={}, |
| 802 | model="gpt-4-turbo", |
| 803 | response_format="none", |
| 804 | stream=False, |
| 805 | temperature=1, |
| 806 | tool_choice="none", |
| 807 | tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}], |
| 808 | top_p=1, |
| 809 | truncation_strategy={ |
| 810 | "type": "auto", |
| 811 | "last_messages": 1, |
| 812 | }, |
| 813 | ) |
| 814 | assert_matches_type(Run, run, path=["response"]) |
| 815 | |
| 816 | @parametrize |
| 817 | async def test_raw_response_create_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 818 | response = await async_client.beta.threads.runs.with_raw_response.create( |
| 819 | "string", |
| 820 | assistant_id="string", |
| 821 | ) |
| 822 | |
| 823 | assert response.is_closed is True |
| 824 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 825 | run = response.parse() |
| 826 | assert_matches_type(Run, run, path=["response"]) |
| 827 | |
| 828 | @parametrize |
| 829 | async def test_streaming_response_create_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 830 | async with async_client.beta.threads.runs.with_streaming_response.create( |
| 831 | "string", |
| 832 | assistant_id="string", |
| 833 | ) as response: |
| 834 | assert not response.is_closed |
| 835 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 836 | |
| 837 | run = await response.parse() |
| 838 | assert_matches_type(Run, run, path=["response"]) |
| 839 | |
| 840 | assert cast(Any, response.is_closed) is True |
| 841 | |
| 842 | @parametrize |
| 843 | async def test_path_params_create_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 844 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 845 | await async_client.beta.threads.runs.with_raw_response.create( |
| 846 | "", |
| 847 | assistant_id="string", |
| 848 | ) |
| 849 | |
| 850 | @parametrize |
| 851 | async def test_method_create_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 852 | run_stream = await async_client.beta.threads.runs.create( |
| 853 | "string", |
| 854 | assistant_id="string", |
| 855 | stream=True, |
| 856 | ) |
| 857 | await run_stream.response.aclose() |
| 858 | |
| 859 | @parametrize |
| 860 | async def test_method_create_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 861 | run_stream = await async_client.beta.threads.runs.create( |
| 862 | "string", |
| 863 | assistant_id="string", |
| 864 | stream=True, |
| 865 | additional_instructions="string", |
| 866 | additional_messages=[ |
| 867 | { |
| 868 | "role": "user", |
| 869 | "content": "x", |
| 870 | "attachments": [ |
| 871 | { |
| 872 | "file_id": "string", |
| 873 | "tools": [ |
| 874 | {"type": "code_interpreter"}, |
| 875 | {"type": "code_interpreter"}, |
| 876 | {"type": "code_interpreter"}, |
| 877 | ], |
| 878 | }, |
| 879 | { |
| 880 | "file_id": "string", |
| 881 | "tools": [ |
| 882 | {"type": "code_interpreter"}, |
| 883 | {"type": "code_interpreter"}, |
| 884 | {"type": "code_interpreter"}, |
| 885 | ], |
| 886 | }, |
| 887 | { |
| 888 | "file_id": "string", |
| 889 | "tools": [ |
| 890 | {"type": "code_interpreter"}, |
| 891 | {"type": "code_interpreter"}, |
| 892 | {"type": "code_interpreter"}, |
| 893 | ], |
| 894 | }, |
| 895 | ], |
| 896 | "metadata": {}, |
| 897 | }, |
| 898 | { |
| 899 | "role": "user", |
| 900 | "content": "x", |
| 901 | "attachments": [ |
| 902 | { |
| 903 | "file_id": "string", |
| 904 | "tools": [ |
| 905 | {"type": "code_interpreter"}, |
| 906 | {"type": "code_interpreter"}, |
| 907 | {"type": "code_interpreter"}, |
| 908 | ], |
| 909 | }, |
| 910 | { |
| 911 | "file_id": "string", |
| 912 | "tools": [ |
| 913 | {"type": "code_interpreter"}, |
| 914 | {"type": "code_interpreter"}, |
| 915 | {"type": "code_interpreter"}, |
| 916 | ], |
| 917 | }, |
| 918 | { |
| 919 | "file_id": "string", |
| 920 | "tools": [ |
| 921 | {"type": "code_interpreter"}, |
| 922 | {"type": "code_interpreter"}, |
| 923 | {"type": "code_interpreter"}, |
| 924 | ], |
| 925 | }, |
| 926 | ], |
| 927 | "metadata": {}, |
| 928 | }, |
| 929 | { |
| 930 | "role": "user", |
| 931 | "content": "x", |
| 932 | "attachments": [ |
| 933 | { |
| 934 | "file_id": "string", |
| 935 | "tools": [ |
| 936 | {"type": "code_interpreter"}, |
| 937 | {"type": "code_interpreter"}, |
| 938 | {"type": "code_interpreter"}, |
| 939 | ], |
| 940 | }, |
| 941 | { |
| 942 | "file_id": "string", |
| 943 | "tools": [ |
| 944 | {"type": "code_interpreter"}, |
| 945 | {"type": "code_interpreter"}, |
| 946 | {"type": "code_interpreter"}, |
| 947 | ], |
| 948 | }, |
| 949 | { |
| 950 | "file_id": "string", |
| 951 | "tools": [ |
| 952 | {"type": "code_interpreter"}, |
| 953 | {"type": "code_interpreter"}, |
| 954 | {"type": "code_interpreter"}, |
| 955 | ], |
| 956 | }, |
| 957 | ], |
| 958 | "metadata": {}, |
| 959 | }, |
| 960 | ], |
| 961 | instructions="string", |
| 962 | max_completion_tokens=256, |
| 963 | max_prompt_tokens=256, |
| 964 | metadata={}, |
| 965 | model="gpt-4-turbo", |
| 966 | response_format="none", |
| 967 | temperature=1, |
| 968 | tool_choice="none", |
| 969 | tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}], |
| 970 | top_p=1, |
| 971 | truncation_strategy={ |
| 972 | "type": "auto", |
| 973 | "last_messages": 1, |
| 974 | }, |
| 975 | ) |
| 976 | await run_stream.response.aclose() |
| 977 | |
| 978 | @parametrize |
| 979 | async def test_raw_response_create_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 980 | response = await async_client.beta.threads.runs.with_raw_response.create( |
| 981 | "string", |
| 982 | assistant_id="string", |
| 983 | stream=True, |
| 984 | ) |
| 985 | |
| 986 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 987 | stream = response.parse() |
| 988 | await stream.close() |
| 989 | |
| 990 | @parametrize |
| 991 | async def test_streaming_response_create_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 992 | async with async_client.beta.threads.runs.with_streaming_response.create( |
| 993 | "string", |
| 994 | assistant_id="string", |
| 995 | stream=True, |
| 996 | ) as response: |
| 997 | assert not response.is_closed |
| 998 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 999 | |
| 1000 | stream = await response.parse() |
| 1001 | await stream.close() |
| 1002 | |
| 1003 | assert cast(Any, response.is_closed) is True |
| 1004 | |
| 1005 | @parametrize |
| 1006 | async def test_path_params_create_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 1007 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 1008 | await async_client.beta.threads.runs.with_raw_response.create( |
| 1009 | "", |
| 1010 | assistant_id="string", |
| 1011 | stream=True, |
| 1012 | ) |
| 1013 | |
| 1014 | @parametrize |
| 1015 | async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 1016 | run = await async_client.beta.threads.runs.retrieve( |
| 1017 | "string", |
| 1018 | thread_id="string", |
| 1019 | ) |
| 1020 | assert_matches_type(Run, run, path=["response"]) |
| 1021 | |
| 1022 | @parametrize |
| 1023 | async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 1024 | response = await async_client.beta.threads.runs.with_raw_response.retrieve( |
| 1025 | "string", |
| 1026 | thread_id="string", |
| 1027 | ) |
| 1028 | |
| 1029 | assert response.is_closed is True |
| 1030 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 1031 | run = response.parse() |
| 1032 | assert_matches_type(Run, run, path=["response"]) |
| 1033 | |
| 1034 | @parametrize |
| 1035 | async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 1036 | async with async_client.beta.threads.runs.with_streaming_response.retrieve( |
| 1037 | "string", |
| 1038 | thread_id="string", |
| 1039 | ) as response: |
| 1040 | assert not response.is_closed |
| 1041 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 1042 | |
| 1043 | run = await response.parse() |
| 1044 | assert_matches_type(Run, run, path=["response"]) |
| 1045 | |
| 1046 | assert cast(Any, response.is_closed) is True |
| 1047 | |
| 1048 | @parametrize |
| 1049 | async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 1050 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 1051 | await async_client.beta.threads.runs.with_raw_response.retrieve( |
| 1052 | "string", |
| 1053 | thread_id="", |
| 1054 | ) |
| 1055 | |
| 1056 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 1057 | await async_client.beta.threads.runs.with_raw_response.retrieve( |
| 1058 | "", |
| 1059 | thread_id="string", |
| 1060 | ) |
| 1061 | |
| 1062 | @parametrize |
| 1063 | async def test_method_update(self, async_client: AsyncOpenAI) -> None: |
| 1064 | run = await async_client.beta.threads.runs.update( |
| 1065 | "string", |
| 1066 | thread_id="string", |
| 1067 | ) |
| 1068 | assert_matches_type(Run, run, path=["response"]) |
| 1069 | |
| 1070 | @parametrize |
| 1071 | async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 1072 | run = await async_client.beta.threads.runs.update( |
| 1073 | "string", |
| 1074 | thread_id="string", |
| 1075 | metadata={}, |
| 1076 | ) |
| 1077 | assert_matches_type(Run, run, path=["response"]) |
| 1078 | |
| 1079 | @parametrize |
| 1080 | async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None: |
| 1081 | response = await async_client.beta.threads.runs.with_raw_response.update( |
| 1082 | "string", |
| 1083 | thread_id="string", |
| 1084 | ) |
| 1085 | |
| 1086 | assert response.is_closed is True |
| 1087 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 1088 | run = response.parse() |
| 1089 | assert_matches_type(Run, run, path=["response"]) |
| 1090 | |
| 1091 | @parametrize |
| 1092 | async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None: |
| 1093 | async with async_client.beta.threads.runs.with_streaming_response.update( |
| 1094 | "string", |
| 1095 | thread_id="string", |
| 1096 | ) as response: |
| 1097 | assert not response.is_closed |
| 1098 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 1099 | |
| 1100 | run = await response.parse() |
| 1101 | assert_matches_type(Run, run, path=["response"]) |
| 1102 | |
| 1103 | assert cast(Any, response.is_closed) is True |
| 1104 | |
| 1105 | @parametrize |
| 1106 | async def test_path_params_update(self, async_client: AsyncOpenAI) -> None: |
| 1107 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 1108 | await async_client.beta.threads.runs.with_raw_response.update( |
| 1109 | "string", |
| 1110 | thread_id="", |
| 1111 | ) |
| 1112 | |
| 1113 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 1114 | await async_client.beta.threads.runs.with_raw_response.update( |
| 1115 | "", |
| 1116 | thread_id="string", |
| 1117 | ) |
| 1118 | |
| 1119 | @parametrize |
| 1120 | async def test_method_list(self, async_client: AsyncOpenAI) -> None: |
| 1121 | run = await async_client.beta.threads.runs.list( |
| 1122 | "string", |
| 1123 | ) |
| 1124 | assert_matches_type(AsyncCursorPage[Run], run, path=["response"]) |
| 1125 | |
| 1126 | @parametrize |
| 1127 | async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 1128 | run = await async_client.beta.threads.runs.list( |
| 1129 | "string", |
| 1130 | after="string", |
| 1131 | before="string", |
| 1132 | limit=0, |
| 1133 | order="asc", |
| 1134 | ) |
| 1135 | assert_matches_type(AsyncCursorPage[Run], run, path=["response"]) |
| 1136 | |
| 1137 | @parametrize |
| 1138 | async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None: |
| 1139 | response = await async_client.beta.threads.runs.with_raw_response.list( |
| 1140 | "string", |
| 1141 | ) |
| 1142 | |
| 1143 | assert response.is_closed is True |
| 1144 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 1145 | run = response.parse() |
| 1146 | assert_matches_type(AsyncCursorPage[Run], run, path=["response"]) |
| 1147 | |
| 1148 | @parametrize |
| 1149 | async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None: |
| 1150 | async with async_client.beta.threads.runs.with_streaming_response.list( |
| 1151 | "string", |
| 1152 | ) as response: |
| 1153 | assert not response.is_closed |
| 1154 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 1155 | |
| 1156 | run = await response.parse() |
| 1157 | assert_matches_type(AsyncCursorPage[Run], run, path=["response"]) |
| 1158 | |
| 1159 | assert cast(Any, response.is_closed) is True |
| 1160 | |
| 1161 | @parametrize |
| 1162 | async def test_path_params_list(self, async_client: AsyncOpenAI) -> None: |
| 1163 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 1164 | await async_client.beta.threads.runs.with_raw_response.list( |
| 1165 | "", |
| 1166 | ) |
| 1167 | |
| 1168 | @parametrize |
| 1169 | async def test_method_cancel(self, async_client: AsyncOpenAI) -> None: |
| 1170 | run = await async_client.beta.threads.runs.cancel( |
| 1171 | "string", |
| 1172 | thread_id="string", |
| 1173 | ) |
| 1174 | assert_matches_type(Run, run, path=["response"]) |
| 1175 | |
| 1176 | @parametrize |
| 1177 | async def test_raw_response_cancel(self, async_client: AsyncOpenAI) -> None: |
| 1178 | response = await async_client.beta.threads.runs.with_raw_response.cancel( |
| 1179 | "string", |
| 1180 | thread_id="string", |
| 1181 | ) |
| 1182 | |
| 1183 | assert response.is_closed is True |
| 1184 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 1185 | run = response.parse() |
| 1186 | assert_matches_type(Run, run, path=["response"]) |
| 1187 | |
| 1188 | @parametrize |
| 1189 | async def test_streaming_response_cancel(self, async_client: AsyncOpenAI) -> None: |
| 1190 | async with async_client.beta.threads.runs.with_streaming_response.cancel( |
| 1191 | "string", |
| 1192 | thread_id="string", |
| 1193 | ) as response: |
| 1194 | assert not response.is_closed |
| 1195 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 1196 | |
| 1197 | run = await response.parse() |
| 1198 | assert_matches_type(Run, run, path=["response"]) |
| 1199 | |
| 1200 | assert cast(Any, response.is_closed) is True |
| 1201 | |
| 1202 | @parametrize |
| 1203 | async def test_path_params_cancel(self, async_client: AsyncOpenAI) -> None: |
| 1204 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 1205 | await async_client.beta.threads.runs.with_raw_response.cancel( |
| 1206 | "string", |
| 1207 | thread_id="", |
| 1208 | ) |
| 1209 | |
| 1210 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 1211 | await async_client.beta.threads.runs.with_raw_response.cancel( |
| 1212 | "", |
| 1213 | thread_id="string", |
| 1214 | ) |
| 1215 | |
| 1216 | @parametrize |
| 1217 | async def test_method_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 1218 | run = await async_client.beta.threads.runs.submit_tool_outputs( |
| 1219 | "string", |
| 1220 | thread_id="string", |
| 1221 | tool_outputs=[{}, {}, {}], |
| 1222 | ) |
| 1223 | assert_matches_type(Run, run, path=["response"]) |
| 1224 | |
| 1225 | @parametrize |
| 1226 | async def test_method_submit_tool_outputs_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 1227 | run = await async_client.beta.threads.runs.submit_tool_outputs( |
| 1228 | "string", |
| 1229 | thread_id="string", |
| 1230 | tool_outputs=[ |
| 1231 | { |
| 1232 | "tool_call_id": "string", |
| 1233 | "output": "string", |
| 1234 | }, |
| 1235 | { |
| 1236 | "tool_call_id": "string", |
| 1237 | "output": "string", |
| 1238 | }, |
| 1239 | { |
| 1240 | "tool_call_id": "string", |
| 1241 | "output": "string", |
| 1242 | }, |
| 1243 | ], |
| 1244 | stream=False, |
| 1245 | ) |
| 1246 | assert_matches_type(Run, run, path=["response"]) |
| 1247 | |
| 1248 | @parametrize |
| 1249 | async def test_raw_response_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 1250 | response = await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 1251 | "string", |
| 1252 | thread_id="string", |
| 1253 | tool_outputs=[{}, {}, {}], |
| 1254 | ) |
| 1255 | |
| 1256 | assert response.is_closed is True |
| 1257 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 1258 | run = response.parse() |
| 1259 | assert_matches_type(Run, run, path=["response"]) |
| 1260 | |
| 1261 | @parametrize |
| 1262 | async def test_streaming_response_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 1263 | async with async_client.beta.threads.runs.with_streaming_response.submit_tool_outputs( |
| 1264 | "string", |
| 1265 | thread_id="string", |
| 1266 | tool_outputs=[{}, {}, {}], |
| 1267 | ) as response: |
| 1268 | assert not response.is_closed |
| 1269 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 1270 | |
| 1271 | run = await response.parse() |
| 1272 | assert_matches_type(Run, run, path=["response"]) |
| 1273 | |
| 1274 | assert cast(Any, response.is_closed) is True |
| 1275 | |
| 1276 | @parametrize |
| 1277 | async def test_path_params_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None: |
| 1278 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 1279 | await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 1280 | "string", |
| 1281 | thread_id="", |
| 1282 | tool_outputs=[{}, {}, {}], |
| 1283 | ) |
| 1284 | |
| 1285 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 1286 | await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 1287 | "", |
| 1288 | thread_id="string", |
| 1289 | tool_outputs=[{}, {}, {}], |
| 1290 | ) |
| 1291 | |
| 1292 | @parametrize |
| 1293 | async def test_method_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 1294 | run_stream = await async_client.beta.threads.runs.submit_tool_outputs( |
| 1295 | "string", |
| 1296 | thread_id="string", |
| 1297 | stream=True, |
| 1298 | tool_outputs=[{}, {}, {}], |
| 1299 | ) |
| 1300 | await run_stream.response.aclose() |
| 1301 | |
| 1302 | @parametrize |
| 1303 | async def test_raw_response_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 1304 | response = await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 1305 | "string", |
| 1306 | thread_id="string", |
| 1307 | stream=True, |
| 1308 | tool_outputs=[{}, {}, {}], |
| 1309 | ) |
| 1310 | |
| 1311 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 1312 | stream = response.parse() |
| 1313 | await stream.close() |
| 1314 | |
| 1315 | @parametrize |
| 1316 | async def test_streaming_response_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 1317 | async with async_client.beta.threads.runs.with_streaming_response.submit_tool_outputs( |
| 1318 | "string", |
| 1319 | thread_id="string", |
| 1320 | stream=True, |
| 1321 | tool_outputs=[{}, {}, {}], |
| 1322 | ) as response: |
| 1323 | assert not response.is_closed |
| 1324 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 1325 | |
| 1326 | stream = await response.parse() |
| 1327 | await stream.close() |
| 1328 | |
| 1329 | assert cast(Any, response.is_closed) is True |
| 1330 | |
| 1331 | @parametrize |
| 1332 | async def test_path_params_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None: |
| 1333 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
| 1334 | await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 1335 | "string", |
| 1336 | thread_id="", |
| 1337 | stream=True, |
| 1338 | tool_outputs=[{}, {}, {}], |
| 1339 | ) |
| 1340 | |
| 1341 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 1342 | await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 1343 | "", |
| 1344 | thread_id="string", |
| 1345 | stream=True, |
| 1346 | tool_outputs=[{}, {}, {}], |
| 1347 | ) |
| 1348 | |