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