openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
tests/api_resources/beta/test_threads.py
820lines · 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: | |
c62e9907stainless-app[bot]1 years ago | 423 | parametrize = pytest.mark.parametrize( |
| 424 | "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] | |
| 425 | ) | |
baa9f07fRobert Craigie2 years ago | 426 | |
| 427 | @parametrize | |
98d779fbStainless Bot2 years ago | 428 | async def test_method_create(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 429 | with pytest.warns(DeprecationWarning): |
| 430 | thread = await async_client.beta.threads.create() | |
| 431 | | |
baa9f07fRobert Craigie2 years ago | 432 | assert_matches_type(Thread, thread, path=["response"]) |
| 433 | | |
| 434 | @parametrize | |
98d779fbStainless Bot2 years ago | 435 | async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 436 | with pytest.warns(DeprecationWarning): |
| 437 | thread = await async_client.beta.threads.create( | |
| 438 | messages=[ | |
| 439 | { | |
| 440 | "content": "string", | |
| 441 | "role": "user", | |
| 442 | "attachments": [ | |
| 443 | { | |
| 444 | "file_id": "file_id", | |
| 445 | "tools": [{"type": "code_interpreter"}], | |
| 446 | } | |
| 447 | ], | |
| 448 | "metadata": {"foo": "string"}, | |
| 449 | } | |
| 450 | ], | |
| 451 | metadata={"foo": "string"}, | |
| 452 | tool_resources={ | |
| 453 | "code_interpreter": {"file_ids": ["string"]}, | |
| 454 | "file_search": { | |
| 455 | "vector_store_ids": ["string"], | |
| 456 | "vector_stores": [ | |
| 457 | { | |
| 458 | "chunking_strategy": {"type": "auto"}, | |
| 459 | "file_ids": ["string"], | |
| 460 | "metadata": {"foo": "string"}, | |
| 461 | } | |
| 462 | ], | |
| 463 | }, | |
5b20698dStainless Bot2 years ago | 464 | }, |
cca09707stainless-app[bot]1 years ago | 465 | ) |
| 466 | | |
baa9f07fRobert Craigie2 years ago | 467 | assert_matches_type(Thread, thread, path=["response"]) |
| 468 | | |
| 469 | @parametrize | |
98d779fbStainless Bot2 years ago | 470 | async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 471 | with pytest.warns(DeprecationWarning): |
| 472 | response = await async_client.beta.threads.with_raw_response.create() | |
86379b44Stainless Bot2 years ago | 473 | |
| 474 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 475 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 476 | thread = response.parse() | |
| 477 | assert_matches_type(Thread, thread, path=["response"]) | |
| 478 | | |
86379b44Stainless Bot2 years ago | 479 | @parametrize |
98d779fbStainless Bot2 years ago | 480 | async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 481 | with pytest.warns(DeprecationWarning): |
| 482 | async with async_client.beta.threads.with_streaming_response.create() as response: | |
| 483 | assert not response.is_closed | |
| 484 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 485 | |
cca09707stainless-app[bot]1 years ago | 486 | thread = await response.parse() |
| 487 | assert_matches_type(Thread, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 488 | |
| 489 | assert cast(Any, response.is_closed) is True | |
| 490 | | |
baa9f07fRobert Craigie2 years ago | 491 | @parametrize |
98d779fbStainless Bot2 years ago | 492 | async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 493 | with pytest.warns(DeprecationWarning): |
| 494 | thread = await async_client.beta.threads.retrieve( | |
| 495 | "thread_id", | |
| 496 | ) | |
| 497 | | |
baa9f07fRobert Craigie2 years ago | 498 | assert_matches_type(Thread, thread, path=["response"]) |
| 499 | | |
| 500 | @parametrize | |
98d779fbStainless Bot2 years ago | 501 | async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 502 | with pytest.warns(DeprecationWarning): |
| 503 | response = await async_client.beta.threads.with_raw_response.retrieve( | |
| 504 | "thread_id", | |
| 505 | ) | |
86379b44Stainless Bot2 years ago | 506 | |
| 507 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 508 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 509 | thread = response.parse() | |
| 510 | assert_matches_type(Thread, thread, path=["response"]) | |
| 511 | | |
86379b44Stainless Bot2 years ago | 512 | @parametrize |
98d779fbStainless Bot2 years ago | 513 | async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 514 | with pytest.warns(DeprecationWarning): |
| 515 | async with async_client.beta.threads.with_streaming_response.retrieve( | |
| 516 | "thread_id", | |
| 517 | ) as response: | |
| 518 | assert not response.is_closed | |
| 519 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 520 | |
cca09707stainless-app[bot]1 years ago | 521 | thread = await response.parse() |
| 522 | assert_matches_type(Thread, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 523 | |
| 524 | assert cast(Any, response.is_closed) is True | |
| 525 | | |
023a4e66Stainless Bot2 years ago | 526 | @parametrize |
98d779fbStainless Bot2 years ago | 527 | async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 528 | with pytest.warns(DeprecationWarning): |
| 529 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 530 | await async_client.beta.threads.with_raw_response.retrieve( | |
| 531 | "", | |
| 532 | ) | |
023a4e66Stainless Bot2 years ago | 533 | |
baa9f07fRobert Craigie2 years ago | 534 | @parametrize |
98d779fbStainless Bot2 years ago | 535 | async def test_method_update(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 536 | with pytest.warns(DeprecationWarning): |
| 537 | thread = await async_client.beta.threads.update( | |
| 538 | thread_id="thread_id", | |
| 539 | ) | |
| 540 | | |
baa9f07fRobert Craigie2 years ago | 541 | assert_matches_type(Thread, thread, path=["response"]) |
| 542 | | |
| 543 | @parametrize | |
98d779fbStainless Bot2 years ago | 544 | async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 545 | with pytest.warns(DeprecationWarning): |
| 546 | thread = await async_client.beta.threads.update( | |
| 547 | thread_id="thread_id", | |
| 548 | metadata={"foo": "string"}, | |
| 549 | tool_resources={ | |
| 550 | "code_interpreter": {"file_ids": ["string"]}, | |
| 551 | "file_search": {"vector_store_ids": ["string"]}, | |
| 552 | }, | |
| 553 | ) | |
| 554 | | |
baa9f07fRobert Craigie2 years ago | 555 | assert_matches_type(Thread, thread, path=["response"]) |
| 556 | | |
| 557 | @parametrize | |
98d779fbStainless Bot2 years ago | 558 | async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 559 | with pytest.warns(DeprecationWarning): |
| 560 | response = await async_client.beta.threads.with_raw_response.update( | |
| 561 | thread_id="thread_id", | |
| 562 | ) | |
86379b44Stainless Bot2 years ago | 563 | |
| 564 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 565 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 566 | thread = response.parse() | |
| 567 | assert_matches_type(Thread, thread, path=["response"]) | |
| 568 | | |
86379b44Stainless Bot2 years ago | 569 | @parametrize |
98d779fbStainless Bot2 years ago | 570 | async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 571 | with pytest.warns(DeprecationWarning): |
| 572 | async with async_client.beta.threads.with_streaming_response.update( | |
| 573 | thread_id="thread_id", | |
| 574 | ) as response: | |
| 575 | assert not response.is_closed | |
| 576 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 577 | |
cca09707stainless-app[bot]1 years ago | 578 | thread = await response.parse() |
| 579 | assert_matches_type(Thread, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 580 | |
| 581 | assert cast(Any, response.is_closed) is True | |
| 582 | | |
023a4e66Stainless Bot2 years ago | 583 | @parametrize |
98d779fbStainless Bot2 years ago | 584 | async def test_path_params_update(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 585 | with pytest.warns(DeprecationWarning): |
| 586 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 587 | await async_client.beta.threads.with_raw_response.update( | |
| 588 | thread_id="", | |
| 589 | ) | |
023a4e66Stainless Bot2 years ago | 590 | |
baa9f07fRobert Craigie2 years ago | 591 | @parametrize |
98d779fbStainless Bot2 years ago | 592 | async def test_method_delete(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 593 | with pytest.warns(DeprecationWarning): |
| 594 | thread = await async_client.beta.threads.delete( | |
| 595 | "thread_id", | |
| 596 | ) | |
| 597 | | |
baa9f07fRobert Craigie2 years ago | 598 | assert_matches_type(ThreadDeleted, thread, path=["response"]) |
| 599 | | |
| 600 | @parametrize | |
98d779fbStainless Bot2 years ago | 601 | async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 602 | with pytest.warns(DeprecationWarning): |
| 603 | response = await async_client.beta.threads.with_raw_response.delete( | |
| 604 | "thread_id", | |
| 605 | ) | |
86379b44Stainless Bot2 years ago | 606 | |
| 607 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 608 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 609 | thread = response.parse() | |
| 610 | assert_matches_type(ThreadDeleted, thread, path=["response"]) | |
| 611 | | |
86379b44Stainless Bot2 years ago | 612 | @parametrize |
98d779fbStainless Bot2 years ago | 613 | async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 614 | with pytest.warns(DeprecationWarning): |
| 615 | async with async_client.beta.threads.with_streaming_response.delete( | |
| 616 | "thread_id", | |
| 617 | ) as response: | |
| 618 | assert not response.is_closed | |
| 619 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 620 | |
cca09707stainless-app[bot]1 years ago | 621 | thread = await response.parse() |
| 622 | assert_matches_type(ThreadDeleted, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 623 | |
| 624 | assert cast(Any, response.is_closed) is True | |
| 625 | | |
023a4e66Stainless Bot2 years ago | 626 | @parametrize |
98d779fbStainless Bot2 years ago | 627 | async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 628 | with pytest.warns(DeprecationWarning): |
| 629 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 630 | await async_client.beta.threads.with_raw_response.delete( | |
| 631 | "", | |
| 632 | ) | |
023a4e66Stainless Bot2 years ago | 633 | |
baa9f07fRobert Craigie2 years ago | 634 | @parametrize |
5429f696Stainless Bot2 years ago | 635 | async def test_method_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 636 | with pytest.warns(DeprecationWarning): |
| 637 | thread = await async_client.beta.threads.create_and_run( | |
| 638 | assistant_id="assistant_id", | |
| 639 | ) | |
| 640 | | |
baa9f07fRobert Craigie2 years ago | 641 | assert_matches_type(Run, thread, path=["response"]) |
| 642 | | |
| 643 | @parametrize | |
5429f696Stainless Bot2 years ago | 644 | async def test_method_create_and_run_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 645 | with pytest.warns(DeprecationWarning): |
| 646 | thread = await async_client.beta.threads.create_and_run( | |
| 647 | assistant_id="assistant_id", | |
| 648 | instructions="instructions", | |
| 649 | max_completion_tokens=256, | |
| 650 | max_prompt_tokens=256, | |
| 651 | metadata={"foo": "string"}, | |
| 652 | model="string", | |
| 653 | parallel_tool_calls=True, | |
| 654 | response_format="auto", | |
| 655 | stream=False, | |
| 656 | temperature=1, | |
| 657 | thread={ | |
| 658 | "messages": [ | |
| 659 | { | |
| 660 | "content": "string", | |
| 661 | "role": "user", | |
| 662 | "attachments": [ | |
| 663 | { | |
| 664 | "file_id": "file_id", | |
| 665 | "tools": [{"type": "code_interpreter"}], | |
| 666 | } | |
| 667 | ], | |
| 668 | "metadata": {"foo": "string"}, | |
| 669 | } | |
| 670 | ], | |
| 671 | "metadata": {"foo": "string"}, | |
| 672 | "tool_resources": { | |
| 673 | "code_interpreter": {"file_ids": ["string"]}, | |
| 674 | "file_search": { | |
| 675 | "vector_store_ids": ["string"], | |
| 676 | "vector_stores": [ | |
| 677 | { | |
| 678 | "chunking_strategy": {"type": "auto"}, | |
| 679 | "file_ids": ["string"], | |
| 680 | "metadata": {"foo": "string"}, | |
| 681 | } | |
| 682 | ], | |
| 683 | }, | |
5b20698dStainless Bot2 years ago | 684 | }, |
| 685 | }, | |
cca09707stainless-app[bot]1 years ago | 686 | tool_choice="none", |
| 687 | tool_resources={ | |
| 688 | "code_interpreter": {"file_ids": ["string"]}, | |
| 689 | "file_search": {"vector_store_ids": ["string"]}, | |
| 690 | }, | |
| 691 | tools=[{"type": "code_interpreter"}], | |
| 692 | top_p=1, | |
| 693 | truncation_strategy={ | |
| 694 | "type": "auto", | |
| 695 | "last_messages": 1, | |
| 696 | }, | |
| 697 | ) | |
| 698 | | |
baa9f07fRobert Craigie2 years ago | 699 | assert_matches_type(Run, thread, path=["response"]) |
| 700 | | |
| 701 | @parametrize | |
5429f696Stainless Bot2 years ago | 702 | async def test_raw_response_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 703 | with pytest.warns(DeprecationWarning): |
| 704 | response = await async_client.beta.threads.with_raw_response.create_and_run( | |
| 705 | assistant_id="assistant_id", | |
| 706 | ) | |
86379b44Stainless Bot2 years ago | 707 | |
| 708 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 709 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 710 | thread = response.parse() | |
| 711 | assert_matches_type(Run, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 712 | |
| 713 | @parametrize | |
5429f696Stainless Bot2 years ago | 714 | async def test_streaming_response_create_and_run_overload_1(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 715 | with pytest.warns(DeprecationWarning): |
| 716 | async with async_client.beta.threads.with_streaming_response.create_and_run( | |
| 717 | assistant_id="assistant_id", | |
| 718 | ) as response: | |
| 719 | assert not response.is_closed | |
| 720 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 721 | |
cca09707stainless-app[bot]1 years ago | 722 | thread = await response.parse() |
| 723 | assert_matches_type(Run, thread, path=["response"]) | |
86379b44Stainless Bot2 years ago | 724 | |
| 725 | assert cast(Any, response.is_closed) is True | |
5429f696Stainless Bot2 years ago | 726 | |
| 727 | @parametrize | |
| 728 | async def test_method_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 729 | with pytest.warns(DeprecationWarning): |
| 730 | thread_stream = await async_client.beta.threads.create_and_run( | |
| 731 | assistant_id="assistant_id", | |
| 732 | stream=True, | |
| 733 | ) | |
| 734 | | |
5429f696Stainless Bot2 years ago | 735 | await thread_stream.response.aclose() |
| 736 | | |
| 737 | @parametrize | |
| 738 | async def test_method_create_and_run_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 739 | with pytest.warns(DeprecationWarning): |
| 740 | thread_stream = await async_client.beta.threads.create_and_run( | |
| 741 | assistant_id="assistant_id", | |
| 742 | stream=True, | |
| 743 | instructions="instructions", | |
| 744 | max_completion_tokens=256, | |
| 745 | max_prompt_tokens=256, | |
| 746 | metadata={"foo": "string"}, | |
| 747 | model="string", | |
| 748 | parallel_tool_calls=True, | |
| 749 | response_format="auto", | |
| 750 | temperature=1, | |
| 751 | thread={ | |
| 752 | "messages": [ | |
| 753 | { | |
| 754 | "content": "string", | |
| 755 | "role": "user", | |
| 756 | "attachments": [ | |
| 757 | { | |
| 758 | "file_id": "file_id", | |
| 759 | "tools": [{"type": "code_interpreter"}], | |
| 760 | } | |
| 761 | ], | |
| 762 | "metadata": {"foo": "string"}, | |
| 763 | } | |
| 764 | ], | |
| 765 | "metadata": {"foo": "string"}, | |
| 766 | "tool_resources": { | |
| 767 | "code_interpreter": {"file_ids": ["string"]}, | |
| 768 | "file_search": { | |
| 769 | "vector_store_ids": ["string"], | |
| 770 | "vector_stores": [ | |
| 771 | { | |
| 772 | "chunking_strategy": {"type": "auto"}, | |
| 773 | "file_ids": ["string"], | |
| 774 | "metadata": {"foo": "string"}, | |
| 775 | } | |
| 776 | ], | |
| 777 | }, | |
5b20698dStainless Bot2 years ago | 778 | }, |
| 779 | }, | |
cca09707stainless-app[bot]1 years ago | 780 | tool_choice="none", |
| 781 | tool_resources={ | |
| 782 | "code_interpreter": {"file_ids": ["string"]}, | |
| 783 | "file_search": {"vector_store_ids": ["string"]}, | |
| 784 | }, | |
| 785 | tools=[{"type": "code_interpreter"}], | |
| 786 | top_p=1, | |
| 787 | truncation_strategy={ | |
| 788 | "type": "auto", | |
| 789 | "last_messages": 1, | |
| 790 | }, | |
| 791 | ) | |
| 792 | | |
5429f696Stainless Bot2 years ago | 793 | await thread_stream.response.aclose() |
| 794 | | |
| 795 | @parametrize | |
| 796 | async def test_raw_response_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 797 | with pytest.warns(DeprecationWarning): |
| 798 | response = await async_client.beta.threads.with_raw_response.create_and_run( | |
| 799 | assistant_id="assistant_id", | |
| 800 | stream=True, | |
| 801 | ) | |
5429f696Stainless Bot2 years ago | 802 | |
| 803 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 804 | stream = response.parse() | |
| 805 | await stream.close() | |
| 806 | | |
| 807 | @parametrize | |
| 808 | async def test_streaming_response_create_and_run_overload_2(self, async_client: AsyncOpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 809 | with pytest.warns(DeprecationWarning): |
| 810 | async with async_client.beta.threads.with_streaming_response.create_and_run( | |
| 811 | assistant_id="assistant_id", | |
| 812 | stream=True, | |
| 813 | ) as response: | |
| 814 | assert not response.is_closed | |
| 815 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 816 | | |
| 817 | stream = await response.parse() | |
| 818 | await stream.close() | |
5429f696Stainless Bot2 years ago | 819 | |
| 820 | assert cast(Any, response.is_closed) is True |