openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
tests/api_resources/beta/threads/test_runs.py
310lines · modecode
| 1 | # File generated from our OpenAPI spec by Stainless. |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import os |
| 6 | |
| 7 | import pytest |
| 8 | |
| 9 | from openai import OpenAI, AsyncOpenAI |
| 10 | from tests.utils import assert_matches_type |
| 11 | from openai._client import OpenAI, AsyncOpenAI |
| 12 | from openai.pagination import SyncCursorPage, AsyncCursorPage |
| 13 | from openai.types.beta.threads import Run |
| 14 | |
| 15 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 16 | api_key = "My API Key" |
| 17 | |
| 18 | |
| 19 | class TestRuns: |
| 20 | strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True) |
| 21 | loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False) |
| 22 | parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"]) |
| 23 | |
| 24 | @parametrize |
| 25 | def test_method_create(self, client: OpenAI) -> None: |
| 26 | run = client.beta.threads.runs.create( |
| 27 | "string", |
| 28 | assistant_id="string", |
| 29 | ) |
| 30 | assert_matches_type(Run, run, path=["response"]) |
| 31 | |
| 32 | @parametrize |
| 33 | def test_method_create_with_all_params(self, client: OpenAI) -> None: |
| 34 | run = client.beta.threads.runs.create( |
| 35 | "string", |
| 36 | assistant_id="string", |
| 37 | additional_instructions="string", |
| 38 | instructions="string", |
| 39 | metadata={}, |
| 40 | model="string", |
| 41 | tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}], |
| 42 | ) |
| 43 | assert_matches_type(Run, run, path=["response"]) |
| 44 | |
| 45 | @parametrize |
| 46 | def test_raw_response_create(self, client: OpenAI) -> None: |
| 47 | response = client.beta.threads.runs.with_raw_response.create( |
| 48 | "string", |
| 49 | assistant_id="string", |
| 50 | ) |
| 51 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 52 | run = response.parse() |
| 53 | assert_matches_type(Run, run, path=["response"]) |
| 54 | |
| 55 | @parametrize |
| 56 | def test_method_retrieve(self, client: OpenAI) -> None: |
| 57 | run = client.beta.threads.runs.retrieve( |
| 58 | "string", |
| 59 | thread_id="string", |
| 60 | ) |
| 61 | assert_matches_type(Run, run, path=["response"]) |
| 62 | |
| 63 | @parametrize |
| 64 | def test_raw_response_retrieve(self, client: OpenAI) -> None: |
| 65 | response = client.beta.threads.runs.with_raw_response.retrieve( |
| 66 | "string", |
| 67 | thread_id="string", |
| 68 | ) |
| 69 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 70 | run = response.parse() |
| 71 | assert_matches_type(Run, run, path=["response"]) |
| 72 | |
| 73 | @parametrize |
| 74 | def test_method_update(self, client: OpenAI) -> None: |
| 75 | run = client.beta.threads.runs.update( |
| 76 | "string", |
| 77 | thread_id="string", |
| 78 | ) |
| 79 | assert_matches_type(Run, run, path=["response"]) |
| 80 | |
| 81 | @parametrize |
| 82 | def test_method_update_with_all_params(self, client: OpenAI) -> None: |
| 83 | run = client.beta.threads.runs.update( |
| 84 | "string", |
| 85 | thread_id="string", |
| 86 | metadata={}, |
| 87 | ) |
| 88 | assert_matches_type(Run, run, path=["response"]) |
| 89 | |
| 90 | @parametrize |
| 91 | def test_raw_response_update(self, client: OpenAI) -> None: |
| 92 | response = client.beta.threads.runs.with_raw_response.update( |
| 93 | "string", |
| 94 | thread_id="string", |
| 95 | ) |
| 96 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 97 | run = response.parse() |
| 98 | assert_matches_type(Run, run, path=["response"]) |
| 99 | |
| 100 | @parametrize |
| 101 | def test_method_list(self, client: OpenAI) -> None: |
| 102 | run = client.beta.threads.runs.list( |
| 103 | "string", |
| 104 | ) |
| 105 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 106 | |
| 107 | @parametrize |
| 108 | def test_method_list_with_all_params(self, client: OpenAI) -> None: |
| 109 | run = client.beta.threads.runs.list( |
| 110 | "string", |
| 111 | after="string", |
| 112 | before="string", |
| 113 | limit=0, |
| 114 | order="asc", |
| 115 | ) |
| 116 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 117 | |
| 118 | @parametrize |
| 119 | def test_raw_response_list(self, client: OpenAI) -> None: |
| 120 | response = client.beta.threads.runs.with_raw_response.list( |
| 121 | "string", |
| 122 | ) |
| 123 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 124 | run = response.parse() |
| 125 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 126 | |
| 127 | @parametrize |
| 128 | def test_method_cancel(self, client: OpenAI) -> None: |
| 129 | run = client.beta.threads.runs.cancel( |
| 130 | "string", |
| 131 | thread_id="string", |
| 132 | ) |
| 133 | assert_matches_type(Run, run, path=["response"]) |
| 134 | |
| 135 | @parametrize |
| 136 | def test_raw_response_cancel(self, client: OpenAI) -> None: |
| 137 | response = client.beta.threads.runs.with_raw_response.cancel( |
| 138 | "string", |
| 139 | thread_id="string", |
| 140 | ) |
| 141 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 142 | run = response.parse() |
| 143 | assert_matches_type(Run, run, path=["response"]) |
| 144 | |
| 145 | @parametrize |
| 146 | def test_method_submit_tool_outputs(self, client: OpenAI) -> None: |
| 147 | run = client.beta.threads.runs.submit_tool_outputs( |
| 148 | "string", |
| 149 | thread_id="string", |
| 150 | tool_outputs=[{}, {}, {}], |
| 151 | ) |
| 152 | assert_matches_type(Run, run, path=["response"]) |
| 153 | |
| 154 | @parametrize |
| 155 | def test_raw_response_submit_tool_outputs(self, client: OpenAI) -> None: |
| 156 | response = client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 157 | "string", |
| 158 | thread_id="string", |
| 159 | tool_outputs=[{}, {}, {}], |
| 160 | ) |
| 161 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 162 | run = response.parse() |
| 163 | assert_matches_type(Run, run, path=["response"]) |
| 164 | |
| 165 | |
| 166 | class TestAsyncRuns: |
| 167 | strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True) |
| 168 | loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False) |
| 169 | parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"]) |
| 170 | |
| 171 | @parametrize |
| 172 | async def test_method_create(self, client: AsyncOpenAI) -> None: |
| 173 | run = await client.beta.threads.runs.create( |
| 174 | "string", |
| 175 | assistant_id="string", |
| 176 | ) |
| 177 | assert_matches_type(Run, run, path=["response"]) |
| 178 | |
| 179 | @parametrize |
| 180 | async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None: |
| 181 | run = await client.beta.threads.runs.create( |
| 182 | "string", |
| 183 | assistant_id="string", |
| 184 | additional_instructions="string", |
| 185 | instructions="string", |
| 186 | metadata={}, |
| 187 | model="string", |
| 188 | tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}], |
| 189 | ) |
| 190 | assert_matches_type(Run, run, path=["response"]) |
| 191 | |
| 192 | @parametrize |
| 193 | async def test_raw_response_create(self, client: AsyncOpenAI) -> None: |
| 194 | response = await client.beta.threads.runs.with_raw_response.create( |
| 195 | "string", |
| 196 | assistant_id="string", |
| 197 | ) |
| 198 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 199 | run = response.parse() |
| 200 | assert_matches_type(Run, run, path=["response"]) |
| 201 | |
| 202 | @parametrize |
| 203 | async def test_method_retrieve(self, client: AsyncOpenAI) -> None: |
| 204 | run = await client.beta.threads.runs.retrieve( |
| 205 | "string", |
| 206 | thread_id="string", |
| 207 | ) |
| 208 | assert_matches_type(Run, run, path=["response"]) |
| 209 | |
| 210 | @parametrize |
| 211 | async def test_raw_response_retrieve(self, client: AsyncOpenAI) -> None: |
| 212 | response = await client.beta.threads.runs.with_raw_response.retrieve( |
| 213 | "string", |
| 214 | thread_id="string", |
| 215 | ) |
| 216 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 217 | run = response.parse() |
| 218 | assert_matches_type(Run, run, path=["response"]) |
| 219 | |
| 220 | @parametrize |
| 221 | async def test_method_update(self, client: AsyncOpenAI) -> None: |
| 222 | run = await client.beta.threads.runs.update( |
| 223 | "string", |
| 224 | thread_id="string", |
| 225 | ) |
| 226 | assert_matches_type(Run, run, path=["response"]) |
| 227 | |
| 228 | @parametrize |
| 229 | async def test_method_update_with_all_params(self, client: AsyncOpenAI) -> None: |
| 230 | run = await client.beta.threads.runs.update( |
| 231 | "string", |
| 232 | thread_id="string", |
| 233 | metadata={}, |
| 234 | ) |
| 235 | assert_matches_type(Run, run, path=["response"]) |
| 236 | |
| 237 | @parametrize |
| 238 | async def test_raw_response_update(self, client: AsyncOpenAI) -> None: |
| 239 | response = await client.beta.threads.runs.with_raw_response.update( |
| 240 | "string", |
| 241 | thread_id="string", |
| 242 | ) |
| 243 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 244 | run = response.parse() |
| 245 | assert_matches_type(Run, run, path=["response"]) |
| 246 | |
| 247 | @parametrize |
| 248 | async def test_method_list(self, client: AsyncOpenAI) -> None: |
| 249 | run = await client.beta.threads.runs.list( |
| 250 | "string", |
| 251 | ) |
| 252 | assert_matches_type(AsyncCursorPage[Run], run, path=["response"]) |
| 253 | |
| 254 | @parametrize |
| 255 | async def test_method_list_with_all_params(self, client: AsyncOpenAI) -> None: |
| 256 | run = await client.beta.threads.runs.list( |
| 257 | "string", |
| 258 | after="string", |
| 259 | before="string", |
| 260 | limit=0, |
| 261 | order="asc", |
| 262 | ) |
| 263 | assert_matches_type(AsyncCursorPage[Run], run, path=["response"]) |
| 264 | |
| 265 | @parametrize |
| 266 | async def test_raw_response_list(self, client: AsyncOpenAI) -> None: |
| 267 | response = await client.beta.threads.runs.with_raw_response.list( |
| 268 | "string", |
| 269 | ) |
| 270 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 271 | run = response.parse() |
| 272 | assert_matches_type(AsyncCursorPage[Run], run, path=["response"]) |
| 273 | |
| 274 | @parametrize |
| 275 | async def test_method_cancel(self, client: AsyncOpenAI) -> None: |
| 276 | run = await client.beta.threads.runs.cancel( |
| 277 | "string", |
| 278 | thread_id="string", |
| 279 | ) |
| 280 | assert_matches_type(Run, run, path=["response"]) |
| 281 | |
| 282 | @parametrize |
| 283 | async def test_raw_response_cancel(self, client: AsyncOpenAI) -> None: |
| 284 | response = await client.beta.threads.runs.with_raw_response.cancel( |
| 285 | "string", |
| 286 | thread_id="string", |
| 287 | ) |
| 288 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 289 | run = response.parse() |
| 290 | assert_matches_type(Run, run, path=["response"]) |
| 291 | |
| 292 | @parametrize |
| 293 | async def test_method_submit_tool_outputs(self, client: AsyncOpenAI) -> None: |
| 294 | run = await client.beta.threads.runs.submit_tool_outputs( |
| 295 | "string", |
| 296 | thread_id="string", |
| 297 | tool_outputs=[{}, {}, {}], |
| 298 | ) |
| 299 | assert_matches_type(Run, run, path=["response"]) |
| 300 | |
| 301 | @parametrize |
| 302 | async def test_raw_response_submit_tool_outputs(self, client: AsyncOpenAI) -> None: |
| 303 | response = await client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 304 | "string", |
| 305 | thread_id="string", |
| 306 | tool_outputs=[{}, {}, {}], |
| 307 | ) |
| 308 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 309 | run = response.parse() |
| 310 | assert_matches_type(Run, run, path=["response"]) |
| 311 | |