Skip to content

Commit db4e1f7

Browse files
committed
feat(api): adding chunking_strategy to polling helpers
1 parent 178afa0 commit db4e1f7

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Diff for: src/openai/resources/beta/vector_stores/file_batches.py

+8
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,13 @@ def create_and_poll(
174174
*,
175175
file_ids: List[str],
176176
poll_interval_ms: int | NotGiven = NOT_GIVEN,
177+
chunking_strategy: file_batch_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
177178
) -> VectorStoreFileBatch:
178179
"""Create a vector store batch and poll until all files have been processed."""
179180
batch = self.create(
180181
vector_store_id=vector_store_id,
181182
file_ids=file_ids,
183+
chunking_strategy=chunking_strategy,
182184
)
183185
# TODO: don't poll unless necessary??
184186
return self.poll(
@@ -306,6 +308,7 @@ def upload_and_poll(
306308
max_concurrency: int = 5,
307309
file_ids: List[str] = [],
308310
poll_interval_ms: int | NotGiven = NOT_GIVEN,
311+
chunking_strategy: file_batch_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
309312
) -> VectorStoreFileBatch:
310313
"""Uploads the given files concurrently and then creates a vector store file batch.
311314
@@ -343,6 +346,7 @@ def upload_and_poll(
343346
vector_store_id=vector_store_id,
344347
file_ids=[*file_ids, *(f.id for f in results)],
345348
poll_interval_ms=poll_interval_ms,
349+
chunking_strategy=chunking_strategy,
346350
)
347351
return batch
348352

@@ -488,11 +492,13 @@ async def create_and_poll(
488492
*,
489493
file_ids: List[str],
490494
poll_interval_ms: int | NotGiven = NOT_GIVEN,
495+
chunking_strategy: file_batch_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
491496
) -> VectorStoreFileBatch:
492497
"""Create a vector store batch and poll until all files have been processed."""
493498
batch = await self.create(
494499
vector_store_id=vector_store_id,
495500
file_ids=file_ids,
501+
chunking_strategy=chunking_strategy,
496502
)
497503
# TODO: don't poll unless necessary??
498504
return await self.poll(
@@ -620,6 +626,7 @@ async def upload_and_poll(
620626
max_concurrency: int = 5,
621627
file_ids: List[str] = [],
622628
poll_interval_ms: int | NotGiven = NOT_GIVEN,
629+
chunking_strategy: file_batch_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
623630
) -> VectorStoreFileBatch:
624631
"""Uploads the given files concurrently and then creates a vector store file batch.
625632
@@ -680,6 +687,7 @@ async def trio_upload_file(limiter: trio.CapacityLimiter, file: FileTypes) -> No
680687
vector_store_id=vector_store_id,
681688
file_ids=[*file_ids, *(f.id for f in uploaded_files)],
682689
poll_interval_ms=poll_interval_ms,
690+
chunking_strategy=chunking_strategy,
683691
)
684692
return batch
685693

Diff for: src/openai/resources/beta/vector_stores/files.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,10 @@ def create_and_poll(
245245
*,
246246
vector_store_id: str,
247247
poll_interval_ms: int | NotGiven = NOT_GIVEN,
248+
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
248249
) -> VectorStoreFile:
249250
"""Attach a file to the given vector store and wait for it to be processed."""
250-
self.create(vector_store_id=vector_store_id, file_id=file_id)
251+
self.create(vector_store_id=vector_store_id, file_id=file_id, chunking_strategy=chunking_strategy)
251252

252253
return self.poll(
253254
file_id,
@@ -301,27 +302,30 @@ def upload(
301302
*,
302303
vector_store_id: str,
303304
file: FileTypes,
305+
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
304306
) -> VectorStoreFile:
305307
"""Upload a file to the `files` API and then attach it to the given vector store.
306308
307309
Note the file will be asynchronously processed (you can use the alternative
308310
polling helper method to wait for processing to complete).
309311
"""
310312
file_obj = self._client.files.create(file=file, purpose="assistants")
311-
return self.create(vector_store_id=vector_store_id, file_id=file_obj.id)
313+
return self.create(vector_store_id=vector_store_id, file_id=file_obj.id, chunking_strategy=chunking_strategy)
312314

313315
def upload_and_poll(
314316
self,
315317
*,
316318
vector_store_id: str,
317319
file: FileTypes,
318320
poll_interval_ms: int | NotGiven = NOT_GIVEN,
321+
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
319322
) -> VectorStoreFile:
320323
"""Add a file to a vector store and poll until processing is complete."""
321324
file_obj = self._client.files.create(file=file, purpose="assistants")
322325
return self.create_and_poll(
323326
vector_store_id=vector_store_id,
324327
file_id=file_obj.id,
328+
chunking_strategy=chunking_strategy,
325329
poll_interval_ms=poll_interval_ms,
326330
)
327331

@@ -542,9 +546,10 @@ async def create_and_poll(
542546
*,
543547
vector_store_id: str,
544548
poll_interval_ms: int | NotGiven = NOT_GIVEN,
549+
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
545550
) -> VectorStoreFile:
546551
"""Attach a file to the given vector store and wait for it to be processed."""
547-
await self.create(vector_store_id=vector_store_id, file_id=file_id)
552+
await self.create(vector_store_id=vector_store_id, file_id=file_id, chunking_strategy=chunking_strategy)
548553

549554
return await self.poll(
550555
file_id,
@@ -598,28 +603,31 @@ async def upload(
598603
*,
599604
vector_store_id: str,
600605
file: FileTypes,
606+
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
601607
) -> VectorStoreFile:
602608
"""Upload a file to the `files` API and then attach it to the given vector store.
603609
604610
Note the file will be asynchronously processed (you can use the alternative
605611
polling helper method to wait for processing to complete).
606612
"""
607613
file_obj = await self._client.files.create(file=file, purpose="assistants")
608-
return await self.create(vector_store_id=vector_store_id, file_id=file_obj.id)
614+
return await self.create(vector_store_id=vector_store_id, file_id=file_obj.id, chunking_strategy=chunking_strategy)
609615

610616
async def upload_and_poll(
611617
self,
612618
*,
613619
vector_store_id: str,
614620
file: FileTypes,
615621
poll_interval_ms: int | NotGiven = NOT_GIVEN,
622+
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
616623
) -> VectorStoreFile:
617624
"""Add a file to a vector store and poll until processing is complete."""
618625
file_obj = await self._client.files.create(file=file, purpose="assistants")
619626
return await self.create_and_poll(
620627
vector_store_id=vector_store_id,
621628
file_id=file_obj.id,
622629
poll_interval_ms=poll_interval_ms,
630+
chunking_strategy=chunking_strategy
623631
)
624632

625633

0 commit comments

Comments
 (0)