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