openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
tests/api_resources/beta/threads/test_messages.py
622lines · 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 | |
| 12 | from openai.pagination import SyncCursorPage, AsyncCursorPage | |
d2738d42Stainless Bot2 years ago | 13 | from openai.types.beta.threads import ( |
| 14 | Message, | |
| 15 | MessageDeleted, | |
| 16 | ) | |
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 TestMessages: | |
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 | message = client.beta.threads.messages.create( | |
| 30 | thread_id="thread_id", | |
| 31 | content="string", | |
| 32 | role="user", | |
| 33 | ) | |
| 34 | | |
5429f696Stainless Bot2 years ago | 35 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 36 | |
| 37 | @parametrize | |
| 38 | def test_method_create_with_all_params(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 39 | with pytest.warns(DeprecationWarning): |
| 40 | message = client.beta.threads.messages.create( | |
| 41 | thread_id="thread_id", | |
| 42 | content="string", | |
| 43 | role="user", | |
| 44 | attachments=[ | |
| 45 | { | |
| 46 | "file_id": "file_id", | |
| 47 | "tools": [{"type": "code_interpreter"}], | |
| 48 | } | |
| 49 | ], | |
| 50 | metadata={"foo": "string"}, | |
| 51 | ) | |
| 52 | | |
5429f696Stainless Bot2 years ago | 53 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 54 | |
| 55 | @parametrize | |
| 56 | def test_raw_response_create(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 57 | with pytest.warns(DeprecationWarning): |
| 58 | response = client.beta.threads.messages.with_raw_response.create( | |
| 59 | thread_id="thread_id", | |
| 60 | content="string", | |
| 61 | role="user", | |
| 62 | ) | |
86379b44Stainless Bot2 years ago | 63 | |
| 64 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 65 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 66 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 67 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 68 | |
86379b44Stainless Bot2 years ago | 69 | @parametrize |
| 70 | def test_streaming_response_create(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 71 | with pytest.warns(DeprecationWarning): |
| 72 | with client.beta.threads.messages.with_streaming_response.create( | |
| 73 | thread_id="thread_id", | |
| 74 | content="string", | |
| 75 | role="user", | |
| 76 | ) as response: | |
| 77 | assert not response.is_closed | |
| 78 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 79 | |
cca09707stainless-app[bot]1 years ago | 80 | message = response.parse() |
| 81 | assert_matches_type(Message, message, path=["response"]) | |
86379b44Stainless Bot2 years ago | 82 | |
| 83 | assert cast(Any, response.is_closed) is True | |
| 84 | | |
023a4e66Stainless Bot2 years ago | 85 | @parametrize |
| 86 | def test_path_params_create(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 87 | with pytest.warns(DeprecationWarning): |
| 88 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 89 | client.beta.threads.messages.with_raw_response.create( | |
| 90 | thread_id="", | |
| 91 | content="string", | |
| 92 | role="user", | |
| 93 | ) | |
023a4e66Stainless Bot2 years ago | 94 | |
baa9f07fRobert Craigie2 years ago | 95 | @parametrize |
| 96 | def test_method_retrieve(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 97 | with pytest.warns(DeprecationWarning): |
| 98 | message = client.beta.threads.messages.retrieve( | |
| 99 | message_id="message_id", | |
| 100 | thread_id="thread_id", | |
| 101 | ) | |
| 102 | | |
5429f696Stainless Bot2 years ago | 103 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 104 | |
| 105 | @parametrize | |
| 106 | def test_raw_response_retrieve(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 107 | with pytest.warns(DeprecationWarning): |
| 108 | response = client.beta.threads.messages.with_raw_response.retrieve( | |
| 109 | message_id="message_id", | |
| 110 | thread_id="thread_id", | |
| 111 | ) | |
86379b44Stainless Bot2 years ago | 112 | |
| 113 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 114 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 115 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 116 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 117 | |
86379b44Stainless Bot2 years ago | 118 | @parametrize |
| 119 | def test_streaming_response_retrieve(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 120 | with pytest.warns(DeprecationWarning): |
| 121 | with client.beta.threads.messages.with_streaming_response.retrieve( | |
| 122 | message_id="message_id", | |
| 123 | thread_id="thread_id", | |
| 124 | ) as response: | |
| 125 | assert not response.is_closed | |
| 126 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 127 | |
cca09707stainless-app[bot]1 years ago | 128 | message = response.parse() |
| 129 | assert_matches_type(Message, message, path=["response"]) | |
86379b44Stainless Bot2 years ago | 130 | |
| 131 | assert cast(Any, response.is_closed) is True | |
| 132 | | |
023a4e66Stainless Bot2 years ago | 133 | @parametrize |
| 134 | def test_path_params_retrieve(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 135 | with pytest.warns(DeprecationWarning): |
| 136 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 137 | client.beta.threads.messages.with_raw_response.retrieve( | |
| 138 | message_id="message_id", | |
| 139 | thread_id="", | |
| 140 | ) | |
023a4e66Stainless Bot2 years ago | 141 | |
cca09707stainless-app[bot]1 years ago | 142 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"): |
| 143 | client.beta.threads.messages.with_raw_response.retrieve( | |
| 144 | message_id="", | |
| 145 | thread_id="thread_id", | |
| 146 | ) | |
023a4e66Stainless Bot2 years ago | 147 | |
baa9f07fRobert Craigie2 years ago | 148 | @parametrize |
| 149 | def test_method_update(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 150 | with pytest.warns(DeprecationWarning): |
| 151 | message = client.beta.threads.messages.update( | |
| 152 | message_id="message_id", | |
| 153 | thread_id="thread_id", | |
| 154 | ) | |
| 155 | | |
5429f696Stainless Bot2 years ago | 156 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 157 | |
| 158 | @parametrize | |
| 159 | def test_method_update_with_all_params(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 160 | with pytest.warns(DeprecationWarning): |
| 161 | message = client.beta.threads.messages.update( | |
| 162 | message_id="message_id", | |
| 163 | thread_id="thread_id", | |
| 164 | metadata={"foo": "string"}, | |
| 165 | ) | |
| 166 | | |
5429f696Stainless Bot2 years ago | 167 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 168 | |
| 169 | @parametrize | |
| 170 | def test_raw_response_update(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 171 | with pytest.warns(DeprecationWarning): |
| 172 | response = client.beta.threads.messages.with_raw_response.update( | |
| 173 | message_id="message_id", | |
| 174 | thread_id="thread_id", | |
| 175 | ) | |
86379b44Stainless Bot2 years ago | 176 | |
| 177 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 178 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 179 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 180 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 181 | |
86379b44Stainless Bot2 years ago | 182 | @parametrize |
| 183 | def test_streaming_response_update(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 184 | with pytest.warns(DeprecationWarning): |
| 185 | with client.beta.threads.messages.with_streaming_response.update( | |
| 186 | message_id="message_id", | |
| 187 | thread_id="thread_id", | |
| 188 | ) as response: | |
| 189 | assert not response.is_closed | |
| 190 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 191 | |
cca09707stainless-app[bot]1 years ago | 192 | message = response.parse() |
| 193 | assert_matches_type(Message, message, path=["response"]) | |
86379b44Stainless Bot2 years ago | 194 | |
| 195 | assert cast(Any, response.is_closed) is True | |
| 196 | | |
023a4e66Stainless Bot2 years ago | 197 | @parametrize |
| 198 | def test_path_params_update(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 199 | with pytest.warns(DeprecationWarning): |
| 200 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 201 | client.beta.threads.messages.with_raw_response.update( | |
| 202 | message_id="message_id", | |
| 203 | thread_id="", | |
| 204 | ) | |
023a4e66Stainless Bot2 years ago | 205 | |
cca09707stainless-app[bot]1 years ago | 206 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"): |
| 207 | client.beta.threads.messages.with_raw_response.update( | |
| 208 | message_id="", | |
| 209 | thread_id="thread_id", | |
| 210 | ) | |
023a4e66Stainless Bot2 years ago | 211 | |
baa9f07fRobert Craigie2 years ago | 212 | @parametrize |
| 213 | def test_method_list(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 214 | with pytest.warns(DeprecationWarning): |
| 215 | message = client.beta.threads.messages.list( | |
| 216 | thread_id="thread_id", | |
| 217 | ) | |
| 218 | | |
5429f696Stainless Bot2 years ago | 219 | assert_matches_type(SyncCursorPage[Message], message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 220 | |
| 221 | @parametrize | |
| 222 | def test_method_list_with_all_params(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 223 | with pytest.warns(DeprecationWarning): |
| 224 | message = client.beta.threads.messages.list( | |
| 225 | thread_id="thread_id", | |
| 226 | after="after", | |
| 227 | before="before", | |
| 228 | limit=0, | |
| 229 | order="asc", | |
| 230 | run_id="run_id", | |
| 231 | ) | |
| 232 | | |
5429f696Stainless Bot2 years ago | 233 | assert_matches_type(SyncCursorPage[Message], message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 234 | |
| 235 | @parametrize | |
| 236 | def test_raw_response_list(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 237 | with pytest.warns(DeprecationWarning): |
| 238 | response = client.beta.threads.messages.with_raw_response.list( | |
| 239 | thread_id="thread_id", | |
| 240 | ) | |
86379b44Stainless Bot2 years ago | 241 | |
| 242 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 243 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 244 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 245 | assert_matches_type(SyncCursorPage[Message], message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 246 | |
86379b44Stainless Bot2 years ago | 247 | @parametrize |
| 248 | def test_streaming_response_list(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 249 | with pytest.warns(DeprecationWarning): |
| 250 | with client.beta.threads.messages.with_streaming_response.list( | |
| 251 | thread_id="thread_id", | |
| 252 | ) as response: | |
| 253 | assert not response.is_closed | |
| 254 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 255 | |
cca09707stainless-app[bot]1 years ago | 256 | message = response.parse() |
| 257 | assert_matches_type(SyncCursorPage[Message], message, path=["response"]) | |
86379b44Stainless Bot2 years ago | 258 | |
| 259 | assert cast(Any, response.is_closed) is True | |
| 260 | | |
023a4e66Stainless Bot2 years ago | 261 | @parametrize |
| 262 | def test_path_params_list(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 263 | with pytest.warns(DeprecationWarning): |
| 264 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 265 | client.beta.threads.messages.with_raw_response.list( | |
| 266 | thread_id="", | |
| 267 | ) | |
023a4e66Stainless Bot2 years ago | 268 | |
d2738d42Stainless Bot2 years ago | 269 | @parametrize |
| 270 | def test_method_delete(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 271 | with pytest.warns(DeprecationWarning): |
| 272 | message = client.beta.threads.messages.delete( | |
| 273 | message_id="message_id", | |
| 274 | thread_id="thread_id", | |
| 275 | ) | |
| 276 | | |
d2738d42Stainless Bot2 years ago | 277 | assert_matches_type(MessageDeleted, message, path=["response"]) |
| 278 | | |
| 279 | @parametrize | |
| 280 | def test_raw_response_delete(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 281 | with pytest.warns(DeprecationWarning): |
| 282 | response = client.beta.threads.messages.with_raw_response.delete( | |
| 283 | message_id="message_id", | |
| 284 | thread_id="thread_id", | |
| 285 | ) | |
d2738d42Stainless Bot2 years ago | 286 | |
| 287 | assert response.is_closed is True | |
| 288 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 289 | message = response.parse() | |
| 290 | assert_matches_type(MessageDeleted, message, path=["response"]) | |
| 291 | | |
| 292 | @parametrize | |
| 293 | def test_streaming_response_delete(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 294 | with pytest.warns(DeprecationWarning): |
| 295 | with client.beta.threads.messages.with_streaming_response.delete( | |
| 296 | message_id="message_id", | |
| 297 | thread_id="thread_id", | |
| 298 | ) as response: | |
| 299 | assert not response.is_closed | |
| 300 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
d2738d42Stainless Bot2 years ago | 301 | |
cca09707stainless-app[bot]1 years ago | 302 | message = response.parse() |
| 303 | assert_matches_type(MessageDeleted, message, path=["response"]) | |
d2738d42Stainless Bot2 years ago | 304 | |
| 305 | assert cast(Any, response.is_closed) is True | |
| 306 | | |
| 307 | @parametrize | |
| 308 | def test_path_params_delete(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 309 | with pytest.warns(DeprecationWarning): |
| 310 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 311 | client.beta.threads.messages.with_raw_response.delete( | |
| 312 | message_id="message_id", | |
| 313 | thread_id="", | |
| 314 | ) | |
d2738d42Stainless Bot2 years ago | 315 | |
cca09707stainless-app[bot]1 years ago | 316 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"): |
| 317 | client.beta.threads.messages.with_raw_response.delete( | |
| 318 | message_id="", | |
| 319 | thread_id="thread_id", | |
| 320 | ) | |
d2738d42Stainless Bot2 years ago | 321 | |
baa9f07fRobert Craigie2 years ago | 322 | |
| 323 | class TestAsyncMessages: | |
c62e9907stainless-app[bot]1 years ago | 324 | parametrize = pytest.mark.parametrize( |
| 325 | "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] | |
| 326 | ) | |
baa9f07fRobert Craigie2 years ago | 327 | |
| 328 | @parametrize | |
98d779fbStainless Bot2 years ago | 329 | async def test_method_create(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 330 | with pytest.warns(DeprecationWarning): |
| 331 | message = await async_client.beta.threads.messages.create( | |
| 332 | thread_id="thread_id", | |
| 333 | content="string", | |
| 334 | role="user", | |
| 335 | ) | |
| 336 | | |
5429f696Stainless Bot2 years ago | 337 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 338 | |
| 339 | @parametrize | |
98d779fbStainless Bot2 years ago | 340 | async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 341 | with pytest.warns(DeprecationWarning): |
| 342 | message = await async_client.beta.threads.messages.create( | |
| 343 | thread_id="thread_id", | |
| 344 | content="string", | |
| 345 | role="user", | |
| 346 | attachments=[ | |
| 347 | { | |
| 348 | "file_id": "file_id", | |
| 349 | "tools": [{"type": "code_interpreter"}], | |
| 350 | } | |
| 351 | ], | |
| 352 | metadata={"foo": "string"}, | |
| 353 | ) | |
| 354 | | |
5429f696Stainless Bot2 years ago | 355 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 356 | |
| 357 | @parametrize | |
98d779fbStainless Bot2 years ago | 358 | async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 359 | with pytest.warns(DeprecationWarning): |
| 360 | response = await async_client.beta.threads.messages.with_raw_response.create( | |
| 361 | thread_id="thread_id", | |
| 362 | content="string", | |
| 363 | role="user", | |
| 364 | ) | |
86379b44Stainless Bot2 years ago | 365 | |
| 366 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 367 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 368 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 369 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 370 | |
86379b44Stainless Bot2 years ago | 371 | @parametrize |
98d779fbStainless Bot2 years ago | 372 | async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 373 | with pytest.warns(DeprecationWarning): |
| 374 | async with async_client.beta.threads.messages.with_streaming_response.create( | |
| 375 | thread_id="thread_id", | |
| 376 | content="string", | |
| 377 | role="user", | |
| 378 | ) as response: | |
| 379 | assert not response.is_closed | |
| 380 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 381 | |
cca09707stainless-app[bot]1 years ago | 382 | message = await response.parse() |
| 383 | assert_matches_type(Message, message, path=["response"]) | |
86379b44Stainless Bot2 years ago | 384 | |
| 385 | assert cast(Any, response.is_closed) is True | |
| 386 | | |
023a4e66Stainless Bot2 years ago | 387 | @parametrize |
98d779fbStainless Bot2 years ago | 388 | async def test_path_params_create(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 389 | with pytest.warns(DeprecationWarning): |
| 390 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 391 | await async_client.beta.threads.messages.with_raw_response.create( | |
| 392 | thread_id="", | |
| 393 | content="string", | |
| 394 | role="user", | |
| 395 | ) | |
023a4e66Stainless Bot2 years ago | 396 | |
baa9f07fRobert Craigie2 years ago | 397 | @parametrize |
98d779fbStainless Bot2 years ago | 398 | async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 399 | with pytest.warns(DeprecationWarning): |
| 400 | message = await async_client.beta.threads.messages.retrieve( | |
| 401 | message_id="message_id", | |
| 402 | thread_id="thread_id", | |
| 403 | ) | |
| 404 | | |
5429f696Stainless Bot2 years ago | 405 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 406 | |
| 407 | @parametrize | |
98d779fbStainless Bot2 years ago | 408 | async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 409 | with pytest.warns(DeprecationWarning): |
| 410 | response = await async_client.beta.threads.messages.with_raw_response.retrieve( | |
| 411 | message_id="message_id", | |
| 412 | thread_id="thread_id", | |
| 413 | ) | |
86379b44Stainless Bot2 years ago | 414 | |
| 415 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 416 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 417 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 418 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 419 | |
86379b44Stainless Bot2 years ago | 420 | @parametrize |
98d779fbStainless Bot2 years ago | 421 | async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 422 | with pytest.warns(DeprecationWarning): |
| 423 | async with async_client.beta.threads.messages.with_streaming_response.retrieve( | |
| 424 | message_id="message_id", | |
| 425 | thread_id="thread_id", | |
| 426 | ) as response: | |
| 427 | assert not response.is_closed | |
| 428 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 429 | |
cca09707stainless-app[bot]1 years ago | 430 | message = await response.parse() |
| 431 | assert_matches_type(Message, message, path=["response"]) | |
86379b44Stainless Bot2 years ago | 432 | |
| 433 | assert cast(Any, response.is_closed) is True | |
| 434 | | |
023a4e66Stainless Bot2 years ago | 435 | @parametrize |
98d779fbStainless Bot2 years ago | 436 | async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 437 | with pytest.warns(DeprecationWarning): |
| 438 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 439 | await async_client.beta.threads.messages.with_raw_response.retrieve( | |
| 440 | message_id="message_id", | |
| 441 | thread_id="", | |
| 442 | ) | |
023a4e66Stainless Bot2 years ago | 443 | |
cca09707stainless-app[bot]1 years ago | 444 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"): |
| 445 | await async_client.beta.threads.messages.with_raw_response.retrieve( | |
| 446 | message_id="", | |
| 447 | thread_id="thread_id", | |
| 448 | ) | |
023a4e66Stainless Bot2 years ago | 449 | |
baa9f07fRobert Craigie2 years ago | 450 | @parametrize |
98d779fbStainless Bot2 years ago | 451 | async def test_method_update(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 452 | with pytest.warns(DeprecationWarning): |
| 453 | message = await async_client.beta.threads.messages.update( | |
| 454 | message_id="message_id", | |
| 455 | thread_id="thread_id", | |
| 456 | ) | |
| 457 | | |
5429f696Stainless Bot2 years ago | 458 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 459 | |
| 460 | @parametrize | |
98d779fbStainless Bot2 years ago | 461 | async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 462 | with pytest.warns(DeprecationWarning): |
| 463 | message = await async_client.beta.threads.messages.update( | |
| 464 | message_id="message_id", | |
| 465 | thread_id="thread_id", | |
| 466 | metadata={"foo": "string"}, | |
| 467 | ) | |
| 468 | | |
5429f696Stainless Bot2 years ago | 469 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 470 | |
| 471 | @parametrize | |
98d779fbStainless Bot2 years ago | 472 | async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 473 | with pytest.warns(DeprecationWarning): |
| 474 | response = await async_client.beta.threads.messages.with_raw_response.update( | |
| 475 | message_id="message_id", | |
| 476 | thread_id="thread_id", | |
| 477 | ) | |
86379b44Stainless Bot2 years ago | 478 | |
| 479 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 480 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 481 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 482 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 483 | |
86379b44Stainless Bot2 years ago | 484 | @parametrize |
98d779fbStainless Bot2 years ago | 485 | async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 486 | with pytest.warns(DeprecationWarning): |
| 487 | async with async_client.beta.threads.messages.with_streaming_response.update( | |
| 488 | message_id="message_id", | |
| 489 | thread_id="thread_id", | |
| 490 | ) as response: | |
| 491 | assert not response.is_closed | |
| 492 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 493 | |
cca09707stainless-app[bot]1 years ago | 494 | message = await response.parse() |
| 495 | assert_matches_type(Message, message, path=["response"]) | |
86379b44Stainless Bot2 years ago | 496 | |
| 497 | assert cast(Any, response.is_closed) is True | |
| 498 | | |
023a4e66Stainless Bot2 years ago | 499 | @parametrize |
98d779fbStainless Bot2 years ago | 500 | async def test_path_params_update(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 501 | with pytest.warns(DeprecationWarning): |
| 502 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 503 | await async_client.beta.threads.messages.with_raw_response.update( | |
| 504 | message_id="message_id", | |
| 505 | thread_id="", | |
| 506 | ) | |
023a4e66Stainless Bot2 years ago | 507 | |
cca09707stainless-app[bot]1 years ago | 508 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"): |
| 509 | await async_client.beta.threads.messages.with_raw_response.update( | |
| 510 | message_id="", | |
| 511 | thread_id="thread_id", | |
| 512 | ) | |
023a4e66Stainless Bot2 years ago | 513 | |
baa9f07fRobert Craigie2 years ago | 514 | @parametrize |
98d779fbStainless Bot2 years ago | 515 | async def test_method_list(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 516 | with pytest.warns(DeprecationWarning): |
| 517 | message = await async_client.beta.threads.messages.list( | |
| 518 | thread_id="thread_id", | |
| 519 | ) | |
| 520 | | |
5429f696Stainless Bot2 years ago | 521 | assert_matches_type(AsyncCursorPage[Message], message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 522 | |
| 523 | @parametrize | |
98d779fbStainless Bot2 years ago | 524 | async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 525 | with pytest.warns(DeprecationWarning): |
| 526 | message = await async_client.beta.threads.messages.list( | |
| 527 | thread_id="thread_id", | |
| 528 | after="after", | |
| 529 | before="before", | |
| 530 | limit=0, | |
| 531 | order="asc", | |
| 532 | run_id="run_id", | |
| 533 | ) | |
| 534 | | |
5429f696Stainless Bot2 years ago | 535 | assert_matches_type(AsyncCursorPage[Message], message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 536 | |
| 537 | @parametrize | |
98d779fbStainless Bot2 years ago | 538 | async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 539 | with pytest.warns(DeprecationWarning): |
| 540 | response = await async_client.beta.threads.messages.with_raw_response.list( | |
| 541 | thread_id="thread_id", | |
| 542 | ) | |
86379b44Stainless Bot2 years ago | 543 | |
| 544 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 545 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 546 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 547 | assert_matches_type(AsyncCursorPage[Message], message, path=["response"]) |
86379b44Stainless Bot2 years ago | 548 | |
| 549 | @parametrize | |
98d779fbStainless Bot2 years ago | 550 | async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 551 | with pytest.warns(DeprecationWarning): |
| 552 | async with async_client.beta.threads.messages.with_streaming_response.list( | |
| 553 | thread_id="thread_id", | |
| 554 | ) as response: | |
| 555 | assert not response.is_closed | |
| 556 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 557 | |
cca09707stainless-app[bot]1 years ago | 558 | message = await response.parse() |
| 559 | assert_matches_type(AsyncCursorPage[Message], message, path=["response"]) | |
86379b44Stainless Bot2 years ago | 560 | |
| 561 | assert cast(Any, response.is_closed) is True | |
023a4e66Stainless Bot2 years ago | 562 | |
| 563 | @parametrize | |
98d779fbStainless Bot2 years ago | 564 | async def test_path_params_list(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 565 | with pytest.warns(DeprecationWarning): |
| 566 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 567 | await async_client.beta.threads.messages.with_raw_response.list( | |
| 568 | thread_id="", | |
| 569 | ) | |
d2738d42Stainless Bot2 years ago | 570 | |
| 571 | @parametrize | |
| 572 | async def test_method_delete(self, async_client: AsyncOpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 573 | with pytest.warns(DeprecationWarning): |
| 574 | message = await async_client.beta.threads.messages.delete( | |
| 575 | message_id="message_id", | |
| 576 | thread_id="thread_id", | |
| 577 | ) | |
| 578 | | |
d2738d42Stainless Bot2 years ago | 579 | assert_matches_type(MessageDeleted, message, path=["response"]) |
| 580 | | |
| 581 | @parametrize | |
| 582 | async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 583 | with pytest.warns(DeprecationWarning): |
| 584 | response = await async_client.beta.threads.messages.with_raw_response.delete( | |
| 585 | message_id="message_id", | |
| 586 | thread_id="thread_id", | |
| 587 | ) | |
d2738d42Stainless Bot2 years ago | 588 | |
| 589 | assert response.is_closed is True | |
| 590 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 591 | message = response.parse() | |
| 592 | assert_matches_type(MessageDeleted, message, path=["response"]) | |
| 593 | | |
| 594 | @parametrize | |
| 595 | async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 596 | with pytest.warns(DeprecationWarning): |
| 597 | async with async_client.beta.threads.messages.with_streaming_response.delete( | |
| 598 | message_id="message_id", | |
| 599 | thread_id="thread_id", | |
| 600 | ) as response: | |
| 601 | assert not response.is_closed | |
| 602 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
d2738d42Stainless Bot2 years ago | 603 | |
cca09707stainless-app[bot]1 years ago | 604 | message = await response.parse() |
| 605 | assert_matches_type(MessageDeleted, message, path=["response"]) | |
d2738d42Stainless Bot2 years ago | 606 | |
| 607 | assert cast(Any, response.is_closed) is True | |
| 608 | | |
| 609 | @parametrize | |
| 610 | async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 611 | with pytest.warns(DeprecationWarning): |
| 612 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 613 | await async_client.beta.threads.messages.with_raw_response.delete( | |
| 614 | message_id="message_id", | |
| 615 | thread_id="", | |
| 616 | ) | |
| 617 | | |
| 618 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"): | |
| 619 | await async_client.beta.threads.messages.with_raw_response.delete( | |
| 620 | message_id="", | |
| 621 | thread_id="thread_id", | |
| 622 | ) |