openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
tests/api_resources/beta/test_threads.py
818lines · 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 | |
cca09707stainless-app[bot]1 years ago | 18 | # pyright: reportDeprecated=false |
| 19 | | |
baa9f07fRobert Craigie2 years ago | 20 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 21 | | |
| 22 | | |
| 23 | class TestThreads: | |
98d779fbStainless Bot2 years ago | 24 | parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
baa9f07fRobert Craigie2 years ago | 25 | |
| 26 | @parametrize | |
| 27 | def test_method_create(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 28 | with pytest.warns(DeprecationWarning): |
| 29 | thread = client.beta.threads.create() | |
| 30 | | |
baa9f07fRobert Craigie2 years ago | 31 | assert_matches_type(Thread, thread, path=["response"]) |
| 32 | | |
| 33 | @parametrize | |
| 34 | def test_method_create_with_all_params(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 35 | with pytest.warns(DeprecationWarning): |
| 36 | thread = client.beta.threads.create( | |
| 37 | messages=[ | |
| 38 | { | |
| 39 | "content": "string", | |
| 40 | "role": "user", | |
| 41 | "attachments": [ | |
| 42 | { | |
| 43 | "file_id": "file_id", | |
| 44 | "tools": [{"type": "code_interpreter"}], | |
| 45 | } | |
| 46 | ], | |
| 47 | "metadata": {"foo": "string"}, | |
| 48 | } | |
| 49 | ], | |
| 50 | metadata={"foo": "string"}, | |
| 51 | tool_resources={ | |
| 52 | "code_interpreter": {"file_ids": ["string"]}, | |
| 53 | "file_search": { | |
| 54 | "vector_store_ids": ["string"], | |
| 55 | "vector_stores": [ | |
| 56 | { | |
| 57 | "chunking_strategy": {"type": "auto"}, | |
| 58 | "file_ids": ["string"], | |
| 59 | "metadata": {"foo": "string"}, | |
| 60 | } | |
| 61 | ], | |
| 62 | }, | |
5b20698dStainless Bot2 years ago | 63 | }, |
cca09707stainless-app[bot]1 years ago | 64 | ) |
| 65 | | |
baa9f07fRobert Craigie2 years ago | 66 | assert_matches_type(Thread, thread, path=["response"]) |
| 67 | | |
| 68 | @parametrize | |
| 69 | def test_raw_response_create(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 70 | with pytest.warns(DeprecationWarning): |
| 71 | response = client.beta.threads.with_raw_response.create() | |
86379b44Stainless Bot2 years ago | 72 | |
| 73 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 74 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 75 | thread = response.parse() | |
| 76 | assert_matches_type(Thread, thread, path=["response"]) | |
| 77 | | |
86379b44Stainless Bot2 years ago | 78 | @parametrize |
| 79 | def test_streaming_response_create(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 80 | with pytest.warns(DeprecationWarning): |
| 81 | with client.beta.threads.with_streaming_response.create() as response: | |
| 82 | assert not response.is_closed | |
| 83 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 84 | |
cca09707stainless-app[bot]1 years ago | 85 | thread = response.parse() |
| 86 | assert_matches_type(Thread, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 87 | |
| 88 | assert cast(Any, response.is_closed) is True | |
| 89 | | |
baa9f07fRobert Craigie2 years ago | 90 | @parametrize |
| 91 | def test_method_retrieve(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 92 | with pytest.warns(DeprecationWarning): |
| 93 | thread = client.beta.threads.retrieve( | |
| 94 | "thread_id", | |
| 95 | ) | |
| 96 | | |
baa9f07fRobert Craigie2 years ago | 97 | assert_matches_type(Thread, thread, path=["response"]) |
| 98 | | |
| 99 | @parametrize | |
| 100 | def test_raw_response_retrieve(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 101 | with pytest.warns(DeprecationWarning): |
| 102 | response = client.beta.threads.with_raw_response.retrieve( | |
| 103 | "thread_id", | |
| 104 | ) | |
86379b44Stainless Bot2 years ago | 105 | |
| 106 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 107 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 108 | thread = response.parse() | |
| 109 | assert_matches_type(Thread, thread, path=["response"]) | |
| 110 | | |
86379b44Stainless Bot2 years ago | 111 | @parametrize |
| 112 | def test_streaming_response_retrieve(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 113 | with pytest.warns(DeprecationWarning): |
| 114 | with client.beta.threads.with_streaming_response.retrieve( | |
| 115 | "thread_id", | |
| 116 | ) as response: | |
| 117 | assert not response.is_closed | |
| 118 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 119 | |
cca09707stainless-app[bot]1 years ago | 120 | thread = response.parse() |
| 121 | assert_matches_type(Thread, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 122 | |
| 123 | assert cast(Any, response.is_closed) is True | |
| 124 | | |
023a4e66Stainless Bot2 years ago | 125 | @parametrize |
| 126 | def test_path_params_retrieve(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 127 | with pytest.warns(DeprecationWarning): |
| 128 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 129 | client.beta.threads.with_raw_response.retrieve( | |
| 130 | "", | |
| 131 | ) | |
023a4e66Stainless Bot2 years ago | 132 | |
baa9f07fRobert Craigie2 years ago | 133 | @parametrize |
| 134 | def test_method_update(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 135 | with pytest.warns(DeprecationWarning): |
| 136 | thread = client.beta.threads.update( | |
| 137 | thread_id="thread_id", | |
| 138 | ) | |
| 139 | | |
baa9f07fRobert Craigie2 years ago | 140 | assert_matches_type(Thread, thread, path=["response"]) |
| 141 | | |
| 142 | @parametrize | |
| 143 | def test_method_update_with_all_params(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 144 | with pytest.warns(DeprecationWarning): |
| 145 | thread = client.beta.threads.update( | |
| 146 | thread_id="thread_id", | |
| 147 | metadata={"foo": "string"}, | |
| 148 | tool_resources={ | |
| 149 | "code_interpreter": {"file_ids": ["string"]}, | |
| 150 | "file_search": {"vector_store_ids": ["string"]}, | |
| 151 | }, | |
| 152 | ) | |
| 153 | | |
baa9f07fRobert Craigie2 years ago | 154 | assert_matches_type(Thread, thread, path=["response"]) |
| 155 | | |
| 156 | @parametrize | |
| 157 | def test_raw_response_update(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 158 | with pytest.warns(DeprecationWarning): |
| 159 | response = client.beta.threads.with_raw_response.update( | |
| 160 | thread_id="thread_id", | |
| 161 | ) | |
86379b44Stainless Bot2 years ago | 162 | |
| 163 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 164 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 165 | thread = response.parse() | |
| 166 | assert_matches_type(Thread, thread, path=["response"]) | |
| 167 | | |
86379b44Stainless Bot2 years ago | 168 | @parametrize |
| 169 | def test_streaming_response_update(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 170 | with pytest.warns(DeprecationWarning): |
| 171 | with client.beta.threads.with_streaming_response.update( | |
| 172 | thread_id="thread_id", | |
| 173 | ) as response: | |
| 174 | assert not response.is_closed | |
| 175 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 176 | |
cca09707stainless-app[bot]1 years ago | 177 | thread = response.parse() |
| 178 | assert_matches_type(Thread, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 179 | |
| 180 | assert cast(Any, response.is_closed) is True | |
| 181 | | |
023a4e66Stainless Bot2 years ago | 182 | @parametrize |
| 183 | def test_path_params_update(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 184 | with pytest.warns(DeprecationWarning): |
| 185 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 186 | client.beta.threads.with_raw_response.update( | |
| 187 | thread_id="", | |
| 188 | ) | |
023a4e66Stainless Bot2 years ago | 189 | |
baa9f07fRobert Craigie2 years ago | 190 | @parametrize |
| 191 | def test_method_delete(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 192 | with pytest.warns(DeprecationWarning): |
| 193 | thread = client.beta.threads.delete( | |
| 194 | "thread_id", | |
| 195 | ) | |
| 196 | | |
baa9f07fRobert Craigie2 years ago | 197 | assert_matches_type(ThreadDeleted, thread, path=["response"]) |
| 198 | | |
| 199 | @parametrize | |
| 200 | def test_raw_response_delete(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 201 | with pytest.warns(DeprecationWarning): |
| 202 | response = client.beta.threads.with_raw_response.delete( | |
| 203 | "thread_id", | |
| 204 | ) | |
86379b44Stainless Bot2 years ago | 205 | |
| 206 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 207 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 208 | thread = response.parse() | |
| 209 | assert_matches_type(ThreadDeleted, thread, path=["response"]) | |
| 210 | | |
86379b44Stainless Bot2 years ago | 211 | @parametrize |
| 212 | def test_streaming_response_delete(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 213 | with pytest.warns(DeprecationWarning): |
| 214 | with client.beta.threads.with_streaming_response.delete( | |
| 215 | "thread_id", | |
| 216 | ) as response: | |
| 217 | assert not response.is_closed | |
| 218 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 219 | |
cca09707stainless-app[bot]1 years ago | 220 | thread = response.parse() |
| 221 | assert_matches_type(ThreadDeleted, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 222 | |
| 223 | assert cast(Any, response.is_closed) is True | |
| 224 | | |
023a4e66Stainless Bot2 years ago | 225 | @parametrize |
| 226 | def test_path_params_delete(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 227 | with pytest.warns(DeprecationWarning): |
| 228 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 229 | client.beta.threads.with_raw_response.delete( | |
| 230 | "", | |
| 231 | ) | |
023a4e66Stainless Bot2 years ago | 232 | |
baa9f07fRobert Craigie2 years ago | 233 | @parametrize |
5429f696Stainless Bot2 years ago | 234 | def test_method_create_and_run_overload_1(self, client: OpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 235 | with pytest.warns(DeprecationWarning): |
| 236 | thread = client.beta.threads.create_and_run( | |
| 237 | assistant_id="assistant_id", | |
| 238 | ) | |
| 239 | | |
baa9f07fRobert Craigie2 years ago | 240 | assert_matches_type(Run, thread, path=["response"]) |
| 241 | | |
| 242 | @parametrize | |
5429f696Stainless Bot2 years ago | 243 | def test_method_create_and_run_with_all_params_overload_1(self, client: OpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 244 | with pytest.warns(DeprecationWarning): |
| 245 | thread = client.beta.threads.create_and_run( | |
| 246 | assistant_id="assistant_id", | |
| 247 | instructions="instructions", | |
| 248 | max_completion_tokens=256, | |
| 249 | max_prompt_tokens=256, | |
| 250 | metadata={"foo": "string"}, | |
| 251 | model="string", | |
| 252 | parallel_tool_calls=True, | |
| 253 | response_format="auto", | |
| 254 | stream=False, | |
| 255 | temperature=1, | |
| 256 | thread={ | |
| 257 | "messages": [ | |
| 258 | { | |
| 259 | "content": "string", | |
| 260 | "role": "user", | |
| 261 | "attachments": [ | |
| 262 | { | |
| 263 | "file_id": "file_id", | |
| 264 | "tools": [{"type": "code_interpreter"}], | |
| 265 | } | |
| 266 | ], | |
| 267 | "metadata": {"foo": "string"}, | |
| 268 | } | |
| 269 | ], | |
| 270 | "metadata": {"foo": "string"}, | |
| 271 | "tool_resources": { | |
| 272 | "code_interpreter": {"file_ids": ["string"]}, | |
| 273 | "file_search": { | |
| 274 | "vector_store_ids": ["string"], | |
| 275 | "vector_stores": [ | |
| 276 | { | |
| 277 | "chunking_strategy": {"type": "auto"}, | |
| 278 | "file_ids": ["string"], | |
| 279 | "metadata": {"foo": "string"}, | |
| 280 | } | |
| 281 | ], | |
| 282 | }, | |
5b20698dStainless Bot2 years ago | 283 | }, |
| 284 | }, | |
cca09707stainless-app[bot]1 years ago | 285 | tool_choice="none", |
| 286 | tool_resources={ | |
| 287 | "code_interpreter": {"file_ids": ["string"]}, | |
| 288 | "file_search": {"vector_store_ids": ["string"]}, | |
| 289 | }, | |
| 290 | tools=[{"type": "code_interpreter"}], | |
| 291 | top_p=1, | |
| 292 | truncation_strategy={ | |
| 293 | "type": "auto", | |
| 294 | "last_messages": 1, | |
| 295 | }, | |
| 296 | ) | |
| 297 | | |
baa9f07fRobert Craigie2 years ago | 298 | assert_matches_type(Run, thread, path=["response"]) |
| 299 | | |
| 300 | @parametrize | |
5429f696Stainless Bot2 years ago | 301 | def test_raw_response_create_and_run_overload_1(self, client: OpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 302 | with pytest.warns(DeprecationWarning): |
| 303 | response = client.beta.threads.with_raw_response.create_and_run( | |
| 304 | assistant_id="assistant_id", | |
| 305 | ) | |
86379b44Stainless Bot2 years ago | 306 | |
| 307 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 308 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 309 | thread = response.parse() | |
| 310 | assert_matches_type(Run, thread, path=["response"]) | |
| 311 | | |
86379b44Stainless Bot2 years ago | 312 | @parametrize |
5429f696Stainless Bot2 years ago | 313 | def test_streaming_response_create_and_run_overload_1(self, client: OpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 314 | with pytest.warns(DeprecationWarning): |
| 315 | with client.beta.threads.with_streaming_response.create_and_run( | |
| 316 | assistant_id="assistant_id", | |
| 317 | ) as response: | |
| 318 | assert not response.is_closed | |
| 319 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 320 | |
cca09707stainless-app[bot]1 years ago | 321 | thread = response.parse() |
| 322 | assert_matches_type(Run, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 323 | |
| 324 | assert cast(Any, response.is_closed) is True | |
| 325 | | |
5429f696Stainless Bot2 years ago | 326 | @parametrize |
| 327 | def test_method_create_and_run_overload_2(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 328 | with pytest.warns(DeprecationWarning): |
| 329 | thread_stream = client.beta.threads.create_and_run( | |
| 330 | assistant_id="assistant_id", | |
| 331 | stream=True, | |
| 332 | ) | |
| 333 | | |
5429f696Stainless Bot2 years ago | 334 | thread_stream.response.close() |
| 335 | | |
| 336 | @parametrize | |
| 337 | def test_method_create_and_run_with_all_params_overload_2(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 338 | with pytest.warns(DeprecationWarning): |
| 339 | thread_stream = client.beta.threads.create_and_run( | |
| 340 | assistant_id="assistant_id", | |
| 341 | stream=True, | |
| 342 | instructions="instructions", | |
| 343 | max_completion_tokens=256, | |
| 344 | max_prompt_tokens=256, | |
| 345 | metadata={"foo": "string"}, | |
| 346 | model="string", | |
| 347 | parallel_tool_calls=True, | |
| 348 | response_format="auto", | |
| 349 | temperature=1, | |
| 350 | thread={ | |
| 351 | "messages": [ | |
| 352 | { | |
| 353 | "content": "string", | |
| 354 | "role": "user", | |
| 355 | "attachments": [ | |
| 356 | { | |
| 357 | "file_id": "file_id", | |
| 358 | "tools": [{"type": "code_interpreter"}], | |
| 359 | } | |
| 360 | ], | |
| 361 | "metadata": {"foo": "string"}, | |
| 362 | } | |
| 363 | ], | |
| 364 | "metadata": {"foo": "string"}, | |
| 365 | "tool_resources": { | |
| 366 | "code_interpreter": {"file_ids": ["string"]}, | |
| 367 | "file_search": { | |
| 368 | "vector_store_ids": ["string"], | |
| 369 | "vector_stores": [ | |
| 370 | { | |
| 371 | "chunking_strategy": {"type": "auto"}, | |
| 372 | "file_ids": ["string"], | |
| 373 | "metadata": {"foo": "string"}, | |
| 374 | } | |
| 375 | ], | |
| 376 | }, | |
5b20698dStainless Bot2 years ago | 377 | }, |
| 378 | }, | |
cca09707stainless-app[bot]1 years ago | 379 | tool_choice="none", |
| 380 | tool_resources={ | |
| 381 | "code_interpreter": {"file_ids": ["string"]}, | |
| 382 | "file_search": {"vector_store_ids": ["string"]}, | |
| 383 | }, | |
| 384 | tools=[{"type": "code_interpreter"}], | |
| 385 | top_p=1, | |
| 386 | truncation_strategy={ | |
| 387 | "type": "auto", | |
| 388 | "last_messages": 1, | |
| 389 | }, | |
| 390 | ) | |
| 391 | | |
5429f696Stainless Bot2 years ago | 392 | thread_stream.response.close() |
| 393 | | |
| 394 | @parametrize | |
| 395 | def test_raw_response_create_and_run_overload_2(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 396 | with pytest.warns(DeprecationWarning): |
| 397 | response = client.beta.threads.with_raw_response.create_and_run( | |
| 398 | assistant_id="assistant_id", | |
| 399 | stream=True, | |
| 400 | ) | |
5429f696Stainless Bot2 years ago | 401 | |
| 402 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 403 | stream = response.parse() | |
| 404 | stream.close() | |
| 405 | | |
| 406 | @parametrize | |
| 407 | def test_streaming_response_create_and_run_overload_2(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 408 | with pytest.warns(DeprecationWarning): |
| 409 | with client.beta.threads.with_streaming_response.create_and_run( | |
| 410 | assistant_id="assistant_id", | |
| 411 | stream=True, | |
| 412 | ) as response: | |
| 413 | assert not response.is_closed | |
| 414 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
5429f696Stainless Bot2 years ago | 415 | |
cca09707stainless-app[bot]1 years ago | 416 | stream = response.parse() |
| 417 | stream.close() | |
5429f696Stainless Bot2 years ago | 418 | |
| 419 | assert cast(Any, response.is_closed) is True | |
| 420 | | |
baa9f07fRobert Craigie2 years ago | 421 | |
| 422 | class TestAsyncThreads: | |
98d779fbStainless Bot2 years ago | 423 | parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) |
baa9f07fRobert Craigie2 years ago | 424 | |
| 425 | @parametrize | |
98d779fbStainless Bot2 years ago | 426 | async def test_method_create(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 427 | with pytest.warns(DeprecationWarning): |
| 428 | thread = await async_client.beta.threads.create() | |
| 429 | | |
baa9f07fRobert Craigie2 years ago | 430 | assert_matches_type(Thread, thread, path=["response"]) |
| 431 | | |
| 432 | @parametrize | |
98d779fbStainless Bot2 years ago | 433 | async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 434 | with pytest.warns(DeprecationWarning): |
| 435 | thread = await async_client.beta.threads.create( | |
| 436 | messages=[ | |
| 437 | { | |
| 438 | "content": "string", | |
| 439 | "role": "user", | |
| 440 | "attachments": [ | |
| 441 | { | |
| 442 | "file_id": "file_id", | |
| 443 | "tools": [{"type": "code_interpreter"}], | |
| 444 | } | |
| 445 | ], | |
| 446 | "metadata": {"foo": "string"}, | |
| 447 | } | |
| 448 | ], | |
| 449 | metadata={"foo": "string"}, | |
| 450 | tool_resources={ | |
| 451 | "code_interpreter": {"file_ids": ["string"]}, | |
| 452 | "file_search": { | |
| 453 | "vector_store_ids": ["string"], | |
| 454 | "vector_stores": [ | |
| 455 | { | |
| 456 | "chunking_strategy": {"type": "auto"}, | |
| 457 | "file_ids": ["string"], | |
| 458 | "metadata": {"foo": "string"}, | |
| 459 | } | |
| 460 | ], | |
| 461 | }, | |
5b20698dStainless Bot2 years ago | 462 | }, |
cca09707stainless-app[bot]1 years ago | 463 | ) |
| 464 | | |
baa9f07fRobert Craigie2 years ago | 465 | assert_matches_type(Thread, thread, path=["response"]) |
| 466 | | |
| 467 | @parametrize | |
98d779fbStainless Bot2 years ago | 468 | async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 469 | with pytest.warns(DeprecationWarning): |
| 470 | response = await async_client.beta.threads.with_raw_response.create() | |
86379b44Stainless Bot2 years ago | 471 | |
| 472 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 473 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 474 | thread = response.parse() | |
| 475 | assert_matches_type(Thread, thread, path=["response"]) | |
| 476 | | |
86379b44Stainless Bot2 years ago | 477 | @parametrize |
98d779fbStainless Bot2 years ago | 478 | async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 479 | with pytest.warns(DeprecationWarning): |
| 480 | async with async_client.beta.threads.with_streaming_response.create() as response: | |
| 481 | assert not response.is_closed | |
| 482 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 483 | |
cca09707stainless-app[bot]1 years ago | 484 | thread = await response.parse() |
| 485 | assert_matches_type(Thread, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 486 | |
| 487 | assert cast(Any, response.is_closed) is True | |
| 488 | | |
baa9f07fRobert Craigie2 years ago | 489 | @parametrize |
98d779fbStainless Bot2 years ago | 490 | async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 491 | with pytest.warns(DeprecationWarning): |
| 492 | thread = await async_client.beta.threads.retrieve( | |
| 493 | "thread_id", | |
| 494 | ) | |
| 495 | | |
baa9f07fRobert Craigie2 years ago | 496 | assert_matches_type(Thread, thread, path=["response"]) |
| 497 | | |
| 498 | @parametrize | |
98d779fbStainless Bot2 years ago | 499 | async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 500 | with pytest.warns(DeprecationWarning): |
| 501 | response = await async_client.beta.threads.with_raw_response.retrieve( | |
| 502 | "thread_id", | |
| 503 | ) | |
86379b44Stainless Bot2 years ago | 504 | |
| 505 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 506 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 507 | thread = response.parse() | |
| 508 | assert_matches_type(Thread, thread, path=["response"]) | |
| 509 | | |
86379b44Stainless Bot2 years ago | 510 | @parametrize |
98d779fbStainless Bot2 years ago | 511 | async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 512 | with pytest.warns(DeprecationWarning): |
| 513 | async with async_client.beta.threads.with_streaming_response.retrieve( | |
| 514 | "thread_id", | |
| 515 | ) as response: | |
| 516 | assert not response.is_closed | |
| 517 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 518 | |
cca09707stainless-app[bot]1 years ago | 519 | thread = await response.parse() |
| 520 | assert_matches_type(Thread, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 521 | |
| 522 | assert cast(Any, response.is_closed) is True | |
| 523 | | |
023a4e66Stainless Bot2 years ago | 524 | @parametrize |
98d779fbStainless Bot2 years ago | 525 | async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 526 | with pytest.warns(DeprecationWarning): |
| 527 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 528 | await async_client.beta.threads.with_raw_response.retrieve( | |
| 529 | "", | |
| 530 | ) | |
023a4e66Stainless Bot2 years ago | 531 | |
baa9f07fRobert Craigie2 years ago | 532 | @parametrize |
98d779fbStainless Bot2 years ago | 533 | async def test_method_update(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 534 | with pytest.warns(DeprecationWarning): |
| 535 | thread = await async_client.beta.threads.update( | |
| 536 | thread_id="thread_id", | |
| 537 | ) | |
| 538 | | |
baa9f07fRobert Craigie2 years ago | 539 | assert_matches_type(Thread, thread, path=["response"]) |
| 540 | | |
| 541 | @parametrize | |
98d779fbStainless Bot2 years ago | 542 | async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 543 | with pytest.warns(DeprecationWarning): |
| 544 | thread = await async_client.beta.threads.update( | |
| 545 | thread_id="thread_id", | |
| 546 | metadata={"foo": "string"}, | |
| 547 | tool_resources={ | |
| 548 | "code_interpreter": {"file_ids": ["string"]}, | |
| 549 | "file_search": {"vector_store_ids": ["string"]}, | |
| 550 | }, | |
| 551 | ) | |
| 552 | | |
baa9f07fRobert Craigie2 years ago | 553 | assert_matches_type(Thread, thread, path=["response"]) |
| 554 | | |
| 555 | @parametrize | |
98d779fbStainless Bot2 years ago | 556 | async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 557 | with pytest.warns(DeprecationWarning): |
| 558 | response = await async_client.beta.threads.with_raw_response.update( | |
| 559 | thread_id="thread_id", | |
| 560 | ) | |
86379b44Stainless Bot2 years ago | 561 | |
| 562 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 563 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 564 | thread = response.parse() | |
| 565 | assert_matches_type(Thread, thread, path=["response"]) | |
| 566 | | |
86379b44Stainless Bot2 years ago | 567 | @parametrize |
98d779fbStainless Bot2 years ago | 568 | async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 569 | with pytest.warns(DeprecationWarning): |
| 570 | async with async_client.beta.threads.with_streaming_response.update( | |
| 571 | thread_id="thread_id", | |
| 572 | ) as response: | |
| 573 | assert not response.is_closed | |
| 574 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 575 | |
cca09707stainless-app[bot]1 years ago | 576 | thread = await response.parse() |
| 577 | assert_matches_type(Thread, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 578 | |
| 579 | assert cast(Any, response.is_closed) is True | |
| 580 | | |
023a4e66Stainless Bot2 years ago | 581 | @parametrize |
98d779fbStainless Bot2 years ago | 582 | async def test_path_params_update(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 583 | with pytest.warns(DeprecationWarning): |
| 584 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 585 | await async_client.beta.threads.with_raw_response.update( | |
| 586 | thread_id="", | |
| 587 | ) | |
023a4e66Stainless Bot2 years ago | 588 | |
baa9f07fRobert Craigie2 years ago | 589 | @parametrize |
98d779fbStainless Bot2 years ago | 590 | async def test_method_delete(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 591 | with pytest.warns(DeprecationWarning): |
| 592 | thread = await async_client.beta.threads.delete( | |
| 593 | "thread_id", | |
| 594 | ) | |
| 595 | | |
baa9f07fRobert Craigie2 years ago | 596 | assert_matches_type(ThreadDeleted, thread, path=["response"]) |
| 597 | | |
| 598 | @parametrize | |
98d779fbStainless Bot2 years ago | 599 | async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 600 | with pytest.warns(DeprecationWarning): |
| 601 | response = await async_client.beta.threads.with_raw_response.delete( | |
| 602 | "thread_id", | |
| 603 | ) | |
86379b44Stainless Bot2 years ago | 604 | |
| 605 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 606 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 607 | thread = response.parse() | |
| 608 | assert_matches_type(ThreadDeleted, thread, path=["response"]) | |
| 609 | | |
86379b44Stainless Bot2 years ago | 610 | @parametrize |
98d779fbStainless Bot2 years ago | 611 | async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 612 | with pytest.warns(DeprecationWarning): |
| 613 | async with async_client.beta.threads.with_streaming_response.delete( | |
| 614 | "thread_id", | |
| 615 | ) as response: | |
| 616 | assert not response.is_closed | |
| 617 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 618 | |
cca09707stainless-app[bot]1 years ago | 619 | thread = await response.parse() |
| 620 | assert_matches_type(ThreadDeleted, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 621 | |
| 622 | assert cast(Any, response.is_closed) is True | |
| 623 | | |
023a4e66Stainless Bot2 years ago | 624 | @parametrize |
98d779fbStainless Bot2 years ago | 625 | async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 626 | with pytest.warns(DeprecationWarning): |
| 627 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 628 | await async_client.beta.threads.with_raw_response.delete( | |
| 629 | "", | |
| 630 | ) | |
023a4e66Stainless Bot2 years ago | 631 | |
baa9f07fRobert Craigie2 years ago | 632 | @parametrize |
5429f696Stainless Bot2 years ago | 633 | async def test_method_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 634 | with pytest.warns(DeprecationWarning): |
| 635 | thread = await async_client.beta.threads.create_and_run( | |
| 636 | assistant_id="assistant_id", | |
| 637 | ) | |
| 638 | | |
baa9f07fRobert Craigie2 years ago | 639 | assert_matches_type(Run, thread, path=["response"]) |
| 640 | | |
| 641 | @parametrize | |
5429f696Stainless Bot2 years ago | 642 | async def test_method_create_and_run_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 643 | with pytest.warns(DeprecationWarning): |
| 644 | thread = await async_client.beta.threads.create_and_run( | |
| 645 | assistant_id="assistant_id", | |
| 646 | instructions="instructions", | |
| 647 | max_completion_tokens=256, | |
| 648 | max_prompt_tokens=256, | |
| 649 | metadata={"foo": "string"}, | |
| 650 | model="string", | |
| 651 | parallel_tool_calls=True, | |
| 652 | response_format="auto", | |
| 653 | stream=False, | |
| 654 | temperature=1, | |
| 655 | thread={ | |
| 656 | "messages": [ | |
| 657 | { | |
| 658 | "content": "string", | |
| 659 | "role": "user", | |
| 660 | "attachments": [ | |
| 661 | { | |
| 662 | "file_id": "file_id", | |
| 663 | "tools": [{"type": "code_interpreter"}], | |
| 664 | } | |
| 665 | ], | |
| 666 | "metadata": {"foo": "string"}, | |
| 667 | } | |
| 668 | ], | |
| 669 | "metadata": {"foo": "string"}, | |
| 670 | "tool_resources": { | |
| 671 | "code_interpreter": {"file_ids": ["string"]}, | |
| 672 | "file_search": { | |
| 673 | "vector_store_ids": ["string"], | |
| 674 | "vector_stores": [ | |
| 675 | { | |
| 676 | "chunking_strategy": {"type": "auto"}, | |
| 677 | "file_ids": ["string"], | |
| 678 | "metadata": {"foo": "string"}, | |
| 679 | } | |
| 680 | ], | |
| 681 | }, | |
5b20698dStainless Bot2 years ago | 682 | }, |
| 683 | }, | |
cca09707stainless-app[bot]1 years ago | 684 | tool_choice="none", |
| 685 | tool_resources={ | |
| 686 | "code_interpreter": {"file_ids": ["string"]}, | |
| 687 | "file_search": {"vector_store_ids": ["string"]}, | |
| 688 | }, | |
| 689 | tools=[{"type": "code_interpreter"}], | |
| 690 | top_p=1, | |
| 691 | truncation_strategy={ | |
| 692 | "type": "auto", | |
| 693 | "last_messages": 1, | |
| 694 | }, | |
| 695 | ) | |
| 696 | | |
baa9f07fRobert Craigie2 years ago | 697 | assert_matches_type(Run, thread, path=["response"]) |
| 698 | | |
| 699 | @parametrize | |
5429f696Stainless Bot2 years ago | 700 | async def test_raw_response_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 701 | with pytest.warns(DeprecationWarning): |
| 702 | response = await async_client.beta.threads.with_raw_response.create_and_run( | |
| 703 | assistant_id="assistant_id", | |
| 704 | ) | |
86379b44Stainless Bot2 years ago | 705 | |
| 706 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 707 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 708 | thread = response.parse() | |
| 709 | assert_matches_type(Run, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 710 | |
| 711 | @parametrize | |
5429f696Stainless Bot2 years ago | 712 | async def test_streaming_response_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 713 | with pytest.warns(DeprecationWarning): |
| 714 | async with async_client.beta.threads.with_streaming_response.create_and_run( | |
| 715 | assistant_id="assistant_id", | |
| 716 | ) as response: | |
| 717 | assert not response.is_closed | |
| 718 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 719 | |
cca09707stainless-app[bot]1 years ago | 720 | thread = await response.parse() |
| 721 | assert_matches_type(Run, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 722 | |
| 723 | assert cast(Any, response.is_closed) is True | |
5429f696Stainless Bot2 years ago | 724 | |
| 725 | @parametrize | |
| 726 | async def test_method_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 727 | with pytest.warns(DeprecationWarning): |
| 728 | thread_stream = await async_client.beta.threads.create_and_run( | |
| 729 | assistant_id="assistant_id", | |
| 730 | stream=True, | |
| 731 | ) | |
| 732 | | |
5429f696Stainless Bot2 years ago | 733 | await thread_stream.response.aclose() |
| 734 | | |
| 735 | @parametrize | |
| 736 | async def test_method_create_and_run_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 737 | with pytest.warns(DeprecationWarning): |
| 738 | thread_stream = await async_client.beta.threads.create_and_run( | |
| 739 | assistant_id="assistant_id", | |
| 740 | stream=True, | |
| 741 | instructions="instructions", | |
| 742 | max_completion_tokens=256, | |
| 743 | max_prompt_tokens=256, | |
| 744 | metadata={"foo": "string"}, | |
| 745 | model="string", | |
| 746 | parallel_tool_calls=True, | |
| 747 | response_format="auto", | |
| 748 | temperature=1, | |
| 749 | thread={ | |
| 750 | "messages": [ | |
| 751 | { | |
| 752 | "content": "string", | |
| 753 | "role": "user", | |
| 754 | "attachments": [ | |
| 755 | { | |
| 756 | "file_id": "file_id", | |
| 757 | "tools": [{"type": "code_interpreter"}], | |
| 758 | } | |
| 759 | ], | |
| 760 | "metadata": {"foo": "string"}, | |
| 761 | } | |
| 762 | ], | |
| 763 | "metadata": {"foo": "string"}, | |
| 764 | "tool_resources": { | |
| 765 | "code_interpreter": {"file_ids": ["string"]}, | |
| 766 | "file_search": { | |
| 767 | "vector_store_ids": ["string"], | |
| 768 | "vector_stores": [ | |
| 769 | { | |
| 770 | "chunking_strategy": {"type": "auto"}, | |
| 771 | "file_ids": ["string"], | |
| 772 | "metadata": {"foo": "string"}, | |
| 773 | } | |
| 774 | ], | |
| 775 | }, | |
5b20698dStainless Bot2 years ago | 776 | }, |
| 777 | }, | |
cca09707stainless-app[bot]1 years ago | 778 | tool_choice="none", |
| 779 | tool_resources={ | |
| 780 | "code_interpreter": {"file_ids": ["string"]}, | |
| 781 | "file_search": {"vector_store_ids": ["string"]}, | |
| 782 | }, | |
| 783 | tools=[{"type": "code_interpreter"}], | |
| 784 | top_p=1, | |
| 785 | truncation_strategy={ | |
| 786 | "type": "auto", | |
| 787 | "last_messages": 1, | |
| 788 | }, | |
| 789 | ) | |
| 790 | | |
5429f696Stainless Bot2 years ago | 791 | await thread_stream.response.aclose() |
| 792 | | |
| 793 | @parametrize | |
| 794 | async def test_raw_response_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 795 | with pytest.warns(DeprecationWarning): |
| 796 | response = await async_client.beta.threads.with_raw_response.create_and_run( | |
| 797 | assistant_id="assistant_id", | |
| 798 | stream=True, | |
| 799 | ) | |
5429f696Stainless Bot2 years ago | 800 | |
| 801 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 802 | stream = response.parse() | |
| 803 | await stream.close() | |
| 804 | | |
| 805 | @parametrize | |
| 806 | async def test_streaming_response_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 807 | with pytest.warns(DeprecationWarning): |
| 808 | async with async_client.beta.threads.with_streaming_response.create_and_run( | |
| 809 | assistant_id="assistant_id", | |
| 810 | stream=True, | |
| 811 | ) as response: | |
| 812 | assert not response.is_closed | |
| 813 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 814 | | |
| 815 | stream = await response.parse() | |
| 816 | await stream.close() | |
5429f696Stainless Bot2 years ago | 817 | |
| 818 | assert cast(Any, response.is_closed) is True |