openai-php / client

⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.
MIT License
4.56k stars 465 forks source link

[Bug]: \OpenAI\Resources\VectorStoresFileBatches::cancel should POST, missing `cancel` path component #433

Open jhariani opened 1 week ago

jhariani commented 1 week ago

Description

If you attempt to use \OpenAI\Resources\VectorStoresFileBatches::cancel to cancel a vector store file batch, the OAI API will return this error:

Invalid method for URL (DELETE /v1/vector_stores/vs_id/file_batches/vsfb_id)

This is because the payload is constructed with this HTTP method and URL pattern:

$payload = Payload::delete("vector_stores/$vectorStoreId/file_batches", $fileBatchId);

Per the OAI cancel batch documentation it should POST to cancel the batch, and construct the URL with this pattern:

https://api.openai.com/v1/vector_stores/{vector_store_id}/file_batches/{batch_id}/cancel

Solution: Change this to use the Payload's cancel helper method:

$payload = Payload::cancel("vector_stores/$vectorStoreId/file_batches", $fileBatchId);

Steps To Reproduce

  1. Create a file$file = app(\OpenAI\Client::class)->files()->upload($data);
  2. Create a vector store file batch $batch = app(\OpenAI\Client::class)->vectorStores()->batches()->create($vectorStoreId, ['file_ids' => [$file->id]);
  3. Cancel it with app((\OpenAI\Client::class)->vectorStores()->batches()->cancel($vectorStoreId, $batch->id)
Screenshot 2024-06-20 at 1 39 56 PM

OpenAI PHP Client Version

v0.10.1

PHP Version

8.2.17

Notes

No response