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