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