openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
tests/api_resources/beta/threads/runs/test_steps.py
317lines · 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 | |
4a0f0fa0Stainless Bot2 years ago | 13 | from openai.types.beta.threads.runs import RunStep |
baa9f07fRobert Craigie2 years ago | 14 | |
cca09707stainless-app[bot]1 years ago | 15 | # pyright: reportDeprecated=false |
| 16 | | |
baa9f07fRobert Craigie2 years ago | 17 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 18 | | |
| 19 | | |
| 20 | class TestSteps: | |
98d779fbStainless Bot2 years ago | 21 | parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
baa9f07fRobert Craigie2 years ago | 22 | |
| 23 | @parametrize | |
| 24 | def test_method_retrieve(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 25 | with pytest.warns(DeprecationWarning): |
| 26 | step = client.beta.threads.runs.steps.retrieve( | |
| 27 | step_id="step_id", | |
| 28 | thread_id="thread_id", | |
| 29 | run_id="run_id", | |
| 30 | ) | |
| 31 | | |
baa9f07fRobert Craigie2 years ago | 32 | assert_matches_type(RunStep, step, path=["response"]) |
| 33 | | |
5d3111a8Stainless Bot1 years ago | 34 | @parametrize |
| 35 | def test_method_retrieve_with_all_params(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 36 | with pytest.warns(DeprecationWarning): |
| 37 | step = client.beta.threads.runs.steps.retrieve( | |
| 38 | step_id="step_id", | |
| 39 | thread_id="thread_id", | |
| 40 | run_id="run_id", | |
| 41 | include=["step_details.tool_calls[*].file_search.results[*].content"], | |
| 42 | ) | |
| 43 | | |
5d3111a8Stainless Bot1 years ago | 44 | assert_matches_type(RunStep, step, path=["response"]) |
| 45 | | |
baa9f07fRobert Craigie2 years ago | 46 | @parametrize |
| 47 | def test_raw_response_retrieve(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 48 | with pytest.warns(DeprecationWarning): |
| 49 | response = client.beta.threads.runs.steps.with_raw_response.retrieve( | |
| 50 | step_id="step_id", | |
| 51 | thread_id="thread_id", | |
| 52 | run_id="run_id", | |
| 53 | ) | |
86379b44Stainless Bot2 years ago | 54 | |
| 55 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 56 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 57 | step = response.parse() | |
| 58 | assert_matches_type(RunStep, step, path=["response"]) | |
| 59 | | |
86379b44Stainless Bot2 years ago | 60 | @parametrize |
| 61 | def test_streaming_response_retrieve(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 62 | with pytest.warns(DeprecationWarning): |
| 63 | with client.beta.threads.runs.steps.with_streaming_response.retrieve( | |
| 64 | step_id="step_id", | |
| 65 | thread_id="thread_id", | |
| 66 | run_id="run_id", | |
| 67 | ) as response: | |
| 68 | assert not response.is_closed | |
| 69 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 70 | | |
| 71 | step = response.parse() | |
| 72 | assert_matches_type(RunStep, step, path=["response"]) | |
86379b44Stainless Bot2 years ago | 73 | |
| 74 | assert cast(Any, response.is_closed) is True | |
| 75 | | |
023a4e66Stainless Bot2 years ago | 76 | @parametrize |
| 77 | def test_path_params_retrieve(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 78 | with pytest.warns(DeprecationWarning): |
| 79 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 80 | client.beta.threads.runs.steps.with_raw_response.retrieve( | |
| 81 | step_id="step_id", | |
| 82 | thread_id="", | |
| 83 | run_id="run_id", | |
| 84 | ) | |
| 85 | | |
| 86 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): | |
| 87 | client.beta.threads.runs.steps.with_raw_response.retrieve( | |
| 88 | step_id="step_id", | |
| 89 | thread_id="thread_id", | |
| 90 | run_id="", | |
| 91 | ) | |
| 92 | | |
| 93 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `step_id` but received ''"): | |
| 94 | client.beta.threads.runs.steps.with_raw_response.retrieve( | |
| 95 | step_id="", | |
| 96 | thread_id="thread_id", | |
| 97 | run_id="run_id", | |
| 98 | ) | |
023a4e66Stainless Bot2 years ago | 99 | |
baa9f07fRobert Craigie2 years ago | 100 | @parametrize |
| 101 | def test_method_list(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 102 | with pytest.warns(DeprecationWarning): |
| 103 | step = client.beta.threads.runs.steps.list( | |
| 104 | run_id="run_id", | |
| 105 | thread_id="thread_id", | |
| 106 | ) | |
| 107 | | |
baa9f07fRobert Craigie2 years ago | 108 | assert_matches_type(SyncCursorPage[RunStep], step, path=["response"]) |
| 109 | | |
| 110 | @parametrize | |
| 111 | def test_method_list_with_all_params(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 112 | with pytest.warns(DeprecationWarning): |
| 113 | step = client.beta.threads.runs.steps.list( | |
| 114 | run_id="run_id", | |
| 115 | thread_id="thread_id", | |
| 116 | after="after", | |
| 117 | before="before", | |
| 118 | include=["step_details.tool_calls[*].file_search.results[*].content"], | |
| 119 | limit=0, | |
| 120 | order="asc", | |
| 121 | ) | |
| 122 | | |
baa9f07fRobert Craigie2 years ago | 123 | assert_matches_type(SyncCursorPage[RunStep], step, path=["response"]) |
| 124 | | |
| 125 | @parametrize | |
| 126 | def test_raw_response_list(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 127 | with pytest.warns(DeprecationWarning): |
| 128 | response = client.beta.threads.runs.steps.with_raw_response.list( | |
| 129 | run_id="run_id", | |
| 130 | thread_id="thread_id", | |
| 131 | ) | |
86379b44Stainless Bot2 years ago | 132 | |
| 133 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 134 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 135 | step = response.parse() | |
| 136 | assert_matches_type(SyncCursorPage[RunStep], step, path=["response"]) | |
| 137 | | |
86379b44Stainless Bot2 years ago | 138 | @parametrize |
| 139 | def test_streaming_response_list(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 140 | with pytest.warns(DeprecationWarning): |
| 141 | with client.beta.threads.runs.steps.with_streaming_response.list( | |
| 142 | run_id="run_id", | |
| 143 | thread_id="thread_id", | |
| 144 | ) as response: | |
| 145 | assert not response.is_closed | |
| 146 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 147 | |
cca09707stainless-app[bot]1 years ago | 148 | step = response.parse() |
| 149 | assert_matches_type(SyncCursorPage[RunStep], step, path=["response"]) | |
86379b44Stainless Bot2 years ago | 150 | |
| 151 | assert cast(Any, response.is_closed) is True | |
| 152 | | |
023a4e66Stainless Bot2 years ago | 153 | @parametrize |
| 154 | def test_path_params_list(self, client: OpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 155 | with pytest.warns(DeprecationWarning): |
| 156 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 157 | client.beta.threads.runs.steps.with_raw_response.list( | |
| 158 | run_id="run_id", | |
| 159 | thread_id="", | |
| 160 | ) | |
023a4e66Stainless Bot2 years ago | 161 | |
cca09707stainless-app[bot]1 years ago | 162 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): |
| 163 | client.beta.threads.runs.steps.with_raw_response.list( | |
| 164 | run_id="", | |
| 165 | thread_id="thread_id", | |
| 166 | ) | |
023a4e66Stainless Bot2 years ago | 167 | |
baa9f07fRobert Craigie2 years ago | 168 | |
| 169 | class TestAsyncSteps: | |
c62e9907stainless-app[bot]1 years ago | 170 | parametrize = pytest.mark.parametrize( |
| 171 | "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] | |
| 172 | ) | |
baa9f07fRobert Craigie2 years ago | 173 | |
| 174 | @parametrize | |
98d779fbStainless Bot2 years ago | 175 | async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 176 | with pytest.warns(DeprecationWarning): |
| 177 | step = await async_client.beta.threads.runs.steps.retrieve( | |
| 178 | step_id="step_id", | |
| 179 | thread_id="thread_id", | |
| 180 | run_id="run_id", | |
| 181 | ) | |
| 182 | | |
baa9f07fRobert Craigie2 years ago | 183 | assert_matches_type(RunStep, step, path=["response"]) |
| 184 | | |
5d3111a8Stainless Bot1 years ago | 185 | @parametrize |
| 186 | async def test_method_retrieve_with_all_params(self, async_client: AsyncOpenAI) -> None: | |
cca09707stainless-app[bot]1 years ago | 187 | with pytest.warns(DeprecationWarning): |
| 188 | step = await async_client.beta.threads.runs.steps.retrieve( | |
| 189 | step_id="step_id", | |
| 190 | thread_id="thread_id", | |
| 191 | run_id="run_id", | |
| 192 | include=["step_details.tool_calls[*].file_search.results[*].content"], | |
| 193 | ) | |
| 194 | | |
5d3111a8Stainless Bot1 years ago | 195 | assert_matches_type(RunStep, step, path=["response"]) |
| 196 | | |
baa9f07fRobert Craigie2 years ago | 197 | @parametrize |
98d779fbStainless Bot2 years ago | 198 | async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 199 | with pytest.warns(DeprecationWarning): |
| 200 | response = await async_client.beta.threads.runs.steps.with_raw_response.retrieve( | |
| 201 | step_id="step_id", | |
| 202 | thread_id="thread_id", | |
| 203 | run_id="run_id", | |
| 204 | ) | |
86379b44Stainless Bot2 years ago | 205 | |
| 206 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 207 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 208 | step = response.parse() | |
| 209 | assert_matches_type(RunStep, step, path=["response"]) | |
| 210 | | |
86379b44Stainless Bot2 years ago | 211 | @parametrize |
98d779fbStainless Bot2 years ago | 212 | async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 213 | with pytest.warns(DeprecationWarning): |
| 214 | async with async_client.beta.threads.runs.steps.with_streaming_response.retrieve( | |
| 215 | step_id="step_id", | |
| 216 | thread_id="thread_id", | |
| 217 | run_id="run_id", | |
| 218 | ) as response: | |
| 219 | assert not response.is_closed | |
| 220 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 221 | | |
| 222 | step = await response.parse() | |
| 223 | assert_matches_type(RunStep, step, path=["response"]) | |
86379b44Stainless Bot2 years ago | 224 | |
| 225 | assert cast(Any, response.is_closed) is True | |
| 226 | | |
023a4e66Stainless Bot2 years ago | 227 | @parametrize |
98d779fbStainless Bot2 years ago | 228 | async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 229 | with pytest.warns(DeprecationWarning): |
| 230 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 231 | await async_client.beta.threads.runs.steps.with_raw_response.retrieve( | |
| 232 | step_id="step_id", | |
| 233 | thread_id="", | |
| 234 | run_id="run_id", | |
| 235 | ) | |
| 236 | | |
| 237 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): | |
| 238 | await async_client.beta.threads.runs.steps.with_raw_response.retrieve( | |
| 239 | step_id="step_id", | |
| 240 | thread_id="thread_id", | |
| 241 | run_id="", | |
| 242 | ) | |
| 243 | | |
| 244 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `step_id` but received ''"): | |
| 245 | await async_client.beta.threads.runs.steps.with_raw_response.retrieve( | |
| 246 | step_id="", | |
| 247 | thread_id="thread_id", | |
| 248 | run_id="run_id", | |
| 249 | ) | |
023a4e66Stainless Bot2 years ago | 250 | |
baa9f07fRobert Craigie2 years ago | 251 | @parametrize |
98d779fbStainless Bot2 years ago | 252 | async def test_method_list(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 253 | with pytest.warns(DeprecationWarning): |
| 254 | step = await async_client.beta.threads.runs.steps.list( | |
| 255 | run_id="run_id", | |
| 256 | thread_id="thread_id", | |
| 257 | ) | |
| 258 | | |
baa9f07fRobert Craigie2 years ago | 259 | assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"]) |
| 260 | | |
| 261 | @parametrize | |
98d779fbStainless Bot2 years ago | 262 | async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 263 | with pytest.warns(DeprecationWarning): |
| 264 | step = await async_client.beta.threads.runs.steps.list( | |
| 265 | run_id="run_id", | |
| 266 | thread_id="thread_id", | |
| 267 | after="after", | |
| 268 | before="before", | |
| 269 | include=["step_details.tool_calls[*].file_search.results[*].content"], | |
| 270 | limit=0, | |
| 271 | order="asc", | |
| 272 | ) | |
| 273 | | |
baa9f07fRobert Craigie2 years ago | 274 | assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"]) |
| 275 | | |
| 276 | @parametrize | |
98d779fbStainless Bot2 years ago | 277 | async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 278 | with pytest.warns(DeprecationWarning): |
| 279 | response = await async_client.beta.threads.runs.steps.with_raw_response.list( | |
| 280 | run_id="run_id", | |
| 281 | thread_id="thread_id", | |
| 282 | ) | |
86379b44Stainless Bot2 years ago | 283 | |
| 284 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 285 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 286 | step = response.parse() | |
| 287 | assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"]) | |
86379b44Stainless Bot2 years ago | 288 | |
| 289 | @parametrize | |
98d779fbStainless Bot2 years ago | 290 | async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 291 | with pytest.warns(DeprecationWarning): |
| 292 | async with async_client.beta.threads.runs.steps.with_streaming_response.list( | |
| 293 | run_id="run_id", | |
| 294 | thread_id="thread_id", | |
| 295 | ) as response: | |
| 296 | assert not response.is_closed | |
| 297 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
86379b44Stainless Bot2 years ago | 298 | |
cca09707stainless-app[bot]1 years ago | 299 | step = await response.parse() |
| 300 | assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"]) | |
86379b44Stainless Bot2 years ago | 301 | |
| 302 | assert cast(Any, response.is_closed) is True | |
023a4e66Stainless Bot2 years ago | 303 | |
| 304 | @parametrize | |
98d779fbStainless Bot2 years ago | 305 | async def test_path_params_list(self, async_client: AsyncOpenAI) -> None: |
cca09707stainless-app[bot]1 years ago | 306 | with pytest.warns(DeprecationWarning): |
| 307 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 308 | await async_client.beta.threads.runs.steps.with_raw_response.list( | |
| 309 | run_id="run_id", | |
| 310 | thread_id="", | |
| 311 | ) | |
| 312 | | |
| 313 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): | |
| 314 | await async_client.beta.threads.runs.steps.with_raw_response.list( | |
| 315 | run_id="", | |
| 316 | thread_id="thread_id", | |
| 317 | ) |