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 ( |
| 14 | Run, |
| 15 | ) |
| 16 | |
| 17 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 18 | api_key = "My API Key" |
| 19 | |
| 20 | |
| 21 | class TestRuns: |
| 22 | strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True) |
| 23 | loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False) |
| 24 | parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"]) |
| 25 | |
| 26 | @parametrize |
| 27 | def test_method_create(self, client: OpenAI) -> None: |
| 28 | run = client.beta.threads.runs.create( |
| 29 | "string", |
| 30 | assistant_id="string", |
| 31 | ) |
| 32 | assert_matches_type(Run, run, path=["response"]) |
| 33 | |
| 34 | @parametrize |
| 35 | def test_method_create_with_all_params(self, client: OpenAI) -> None: |
| 36 | run = client.beta.threads.runs.create( |
| 37 | "string", |
| 38 | assistant_id="string", |
| 39 | instructions="string", |
| 40 | metadata={}, |
| 41 | model="string", |
| 42 | tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}], |
| 43 | ) |
| 44 | assert_matches_type(Run, run, path=["response"]) |
| 45 | |
| 46 | @parametrize |
| 47 | def test_raw_response_create(self, client: OpenAI) -> None: |
| 48 | response = client.beta.threads.runs.with_raw_response.create( |
| 49 | "string", |
| 50 | assistant_id="string", |
| 51 | ) |
| 52 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 53 | run = response.parse() |
| 54 | assert_matches_type(Run, run, path=["response"]) |
| 55 | |
| 56 | @parametrize |
| 57 | def test_method_retrieve(self, client: OpenAI) -> None: |
| 58 | run = client.beta.threads.runs.retrieve( |
| 59 | "string", |
| 60 | thread_id="string", |
| 61 | ) |
| 62 | assert_matches_type(Run, run, path=["response"]) |
| 63 | |
| 64 | @parametrize |
| 65 | def test_raw_response_retrieve(self, client: OpenAI) -> None: |
| 66 | response = client.beta.threads.runs.with_raw_response.retrieve( |
| 67 | "string", |
| 68 | thread_id="string", |
| 69 | ) |
| 70 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 71 | run = response.parse() |
| 72 | assert_matches_type(Run, run, path=["response"]) |
| 73 | |
| 74 | @parametrize |
| 75 | def test_method_update(self, client: OpenAI) -> None: |
| 76 | run = client.beta.threads.runs.update( |
| 77 | "string", |
| 78 | thread_id="string", |
| 79 | ) |
| 80 | assert_matches_type(Run, run, path=["response"]) |
| 81 | |
| 82 | @parametrize |
| 83 | def test_method_update_with_all_params(self, client: OpenAI) -> None: |
| 84 | run = client.beta.threads.runs.update( |
| 85 | "string", |
| 86 | thread_id="string", |
| 87 | metadata={}, |
| 88 | ) |
| 89 | assert_matches_type(Run, run, path=["response"]) |
| 90 | |
| 91 | @parametrize |
| 92 | def test_raw_response_update(self, client: OpenAI) -> None: |
| 93 | response = client.beta.threads.runs.with_raw_response.update( |
| 94 | "string", |
| 95 | thread_id="string", |
| 96 | ) |
| 97 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 98 | run = response.parse() |
| 99 | assert_matches_type(Run, run, path=["response"]) |
| 100 | |
| 101 | @parametrize |
| 102 | def test_method_list(self, client: OpenAI) -> None: |
| 103 | run = client.beta.threads.runs.list( |
| 104 | "string", |
| 105 | ) |
| 106 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 107 | |
| 108 | @parametrize |
| 109 | def test_method_list_with_all_params(self, client: OpenAI) -> None: |
| 110 | run = client.beta.threads.runs.list( |
| 111 | "string", |
| 112 | after="string", |
| 113 | before="string", |
| 114 | limit=0, |
| 115 | order="asc", |
| 116 | ) |
| 117 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 118 | |
| 119 | @parametrize |
| 120 | def test_raw_response_list(self, client: OpenAI) -> None: |
| 121 | response = client.beta.threads.runs.with_raw_response.list( |
| 122 | "string", |
| 123 | ) |
| 124 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 125 | run = response.parse() |
| 126 | assert_matches_type(SyncCursorPage[Run], run, path=["response"]) |
| 127 | |
| 128 | @parametrize |
| 129 | def test_method_cancel(self, client: OpenAI) -> None: |
| 130 | run = client.beta.threads.runs.cancel( |
| 131 | "string", |
| 132 | thread_id="string", |
| 133 | ) |
| 134 | assert_matches_type(Run, run, path=["response"]) |
| 135 | |
| 136 | @parametrize |
| 137 | def test_raw_response_cancel(self, client: OpenAI) -> None: |
| 138 | response = client.beta.threads.runs.with_raw_response.cancel( |
| 139 | "string", |
| 140 | thread_id="string", |
| 141 | ) |
| 142 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 143 | run = response.parse() |
| 144 | assert_matches_type(Run, run, path=["response"]) |
| 145 | |
| 146 | @parametrize |
| 147 | def test_method_submit_tool_outputs(self, client: OpenAI) -> None: |
| 148 | run = client.beta.threads.runs.submit_tool_outputs( |
| 149 | "string", |
| 150 | thread_id="string", |
| 151 | tool_outputs=[{}, {}, {}], |
| 152 | ) |
| 153 | assert_matches_type(Run, run, path=["response"]) |
| 154 | |
| 155 | @parametrize |
| 156 | def test_raw_response_submit_tool_outputs(self, client: OpenAI) -> None: |
| 157 | response = client.beta.threads.runs.with_raw_response.submit_tool_outputs( |
| 158 | "string", |
| 159 | thread_id="string", |
| 160 | tool_outputs=[{}, {}, {}], |
| 161 | ) |
| 162 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 163 | run = response.parse() |
| 164 | assert_matches_type(Run, run, path=["response"]) |
| 165 | |
| 166 | |
| 167 | class TestAsyncRuns: |
| 168 | strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True) |
| 169 | loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False) |
| 170 | parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"]) |
| 171 | |
| 172 | @parametrize |
| 173 | async def test_method_create(self, client: AsyncOpenAI) -> None: |
| 174 | run = await client.beta.threads.runs.create( |
| 175 | "string", |
| 176 | assistant_id="string", |
| 177 | ) |
| 178 | assert_matches_type(Run, run, path=["response"]) |
| 179 | |
| 180 | @parametrize |
| 181 | async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None: |
| 182 | run = await client.beta.threads.runs.create( |
| 183 | "string", |
| 184 | assistant_id="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"]) |