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