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