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