Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/resources/vector-stores/file-batches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class FileBatches extends APIResource {
body: FileBatchCreateParams,
options?: RequestOptions & { pollIntervalMs?: number },
): Promise<VectorStoreFileBatch> {
const batch = await this.create(vectorStoreId, body);
const batch = await this.create(vectorStoreId, body, options);
return await this.poll(vectorStoreId, batch.id, options);
}

Expand Down Expand Up @@ -182,9 +182,13 @@ export class FileBatches extends APIResource {
// Wait for all processing to complete.
await allSettledWithThrow(workers);

return await this.createAndPoll(vectorStoreId, {
file_ids: allFileIds,
});
return await this.createAndPoll(
vectorStoreId,
{
file_ids: allFileIds,
},
options,
);
}
}

Expand Down
53 changes: 53 additions & 0 deletions tests/api-resources/vector-stores/file-batches.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,57 @@ describe('resource fileBatches', () => {
order: 'asc',
});
});

test('uploadAndPoll passes options through to batch creation and polling', async () => {
const requests: Array<{ url: string; init: RequestInit | undefined }> = [];
const batch = {
id: 'vsfb_abc123',
object: 'vector_store.files_batch',
created_at: 0,
vector_store_id: 'vs_abc123',
status: 'completed',
file_counts: { in_progress: 0, completed: 1, failed: 0, cancelled: 0, total: 1 },
};
const testClient = new OpenAI({
apiKey: 'My API Key',
baseURL: 'http://127.0.0.1:4010',
fetch: async (url, init) => {
requests.push({ url: String(url), init });
const pathname = new URL(String(url)).pathname;
const body =
pathname === '/files' ?
{
id: 'file_abc123',
object: 'file',
bytes: 0,
created_at: 0,
filename: 'README.md',
purpose: 'assistants',
}
: batch;

return new Response(JSON.stringify(body), {
headers: { 'Content-Type': 'application/json' },
});
},
});

const response = await testClient.vectorStores.fileBatches.uploadAndPoll(
'vs_abc123',
{ files: [new File(['Example data'], 'README.md')] },
{ pollIntervalMs: 1, headers: { 'X-Test-Header': 'present' } },
);

const apiRequests = requests.filter(({ url }) => url.startsWith('http://127.0.0.1'));

expect(response.id).toBe('vsfb_abc123');
expect(apiRequests.map(({ url }) => new URL(url).pathname)).toEqual([
'/files',
'/vector_stores/vs_abc123/file_batches',
'/vector_stores/vs_abc123/file_batches/vsfb_abc123',
]);
expect(new Headers(apiRequests[1]?.init?.headers).get('x-test-header')).toBe('present');
expect(new Headers(apiRequests[2]?.init?.headers).get('x-test-header')).toBe('present');
expect(new Headers(apiRequests[2]?.init?.headers).get('x-stainless-custom-poll-interval')).toBe('1');
});
});