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