From d4a2ab959585b9ccb9396eac79d631757aa5f1e5 Mon Sep 17 00:00:00 2001 From: Manuel Ruck Date: Sun, 11 Aug 2024 21:55:47 +0200 Subject: [PATCH] fix: ensure vectorStore is ready Signed-off-by: Manuel Ruck --- services/non-named-votes-ai/src/utils.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/non-named-votes-ai/src/utils.ts b/services/non-named-votes-ai/src/utils.ts index 4037ba23..f2e8bc0e 100644 --- a/services/non-named-votes-ai/src/utils.ts +++ b/services/non-named-votes-ai/src/utils.ts @@ -63,10 +63,14 @@ export const ensureFile = async ({ pdfUrl, file_id }: { pdfUrl: string; file_id? export const retriveVectorStore = async (vectorStoreId: string) => await openai.beta.vectorStores.retrieve(vectorStoreId); -export const createVectorStore = async ({ file_ids }: { file_ids: string[] }) => - await openai.beta.vectorStores.create({ +export const createVectorStore = async ({ file_ids }: { file_ids: string[] }) => { + const vectorStore = await openai.beta.vectorStores.create({}); + + await openai.beta.vectorStores.fileBatches.createAndPoll(vectorStore.id, { file_ids, }); + return vectorStore; +}; export const ensureVectorStore = async ({ file_id, vector_store_id,