Wait for the vector store file to finish processing. Note: this will return even if the file failed to process, you need to check file.last_error and file.status to handle these cases
(
self,
file_id: str,
*,
vector_store_id: str,
poll_interval_ms: int | Omit = omit,
)
| 358 | ) |
| 359 | |
| 360 | def poll( |
| 361 | self, |
| 362 | file_id: str, |
| 363 | *, |
| 364 | vector_store_id: str, |
| 365 | poll_interval_ms: int | Omit = omit, |
| 366 | ) -> VectorStoreFile: |
| 367 | class="st">"""Wait for the vector store file to finish processing. |
| 368 | |
| 369 | Note: this will return even if the file failed to process, you need to check |
| 370 | file.last_error and file.status to handle these cases |
| 371 | class="st">""" |
| 372 | headers: dict[str, str] = {class="st">"X-Stainless-Poll-Helper": class="st">"true"} |
| 373 | if is_given(poll_interval_ms): |
| 374 | headers[class="st">"X-Stainless-Custom-Poll-Interval"] = str(poll_interval_ms) |
| 375 | |
| 376 | while True: |
| 377 | response = self.with_raw_response.retrieve( |
| 378 | file_id, |
| 379 | vector_store_id=vector_store_id, |
| 380 | extra_headers=headers, |
| 381 | ) |
| 382 | |
| 383 | file = response.parse() |
| 384 | if file.status == class="st">"in_progress": |
| 385 | if not is_given(poll_interval_ms): |
| 386 | from_header = response.headers.get(class="st">"openai-poll-after-ms") |
| 387 | if from_header is not None: |
| 388 | poll_interval_ms = int(from_header) |
| 389 | else: |
| 390 | poll_interval_ms = 1000 |
| 391 | |
| 392 | self._sleep(poll_interval_ms / 1000) |
| 393 | elif file.status == class="st">"cancelled" or file.status == class="st">"completed" or file.status == class="st">"failed": |
| 394 | return file |
| 395 | else: |
| 396 | if TYPE_CHECKING: class="cm"># type: ignore[unreachable] |
| 397 | assert_never(file.status) |
| 398 | else: |
| 399 | return file |
| 400 | |
| 401 | def upload( |
| 402 | self, |