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