Pārlūkot izejas kodu

update vector store with new attachments

kevin 1 gadu atpakaļ
vecāks
revīzija
3a517c8739
1 mainītis faili ar 5 papildinājumiem un 2 dzēšanām
  1. 5 2
      main.py

+ 5 - 2
main.py

@@ -398,7 +398,7 @@ def assistant_att():
     file_batch_id = request.form.get('file_batch_id', '')
     attachments: list[str] = []
     try:
-        if not vector_store_id or not file_batch_id:
+        if not file_batch_id:
             if 'attachment1' not in request.files:
                 return {"status": "error", "message": "No file for attachments"}
             else:
@@ -416,7 +416,10 @@ def assistant_att():
                         n = n + 1
                     else:
                         has_attachments = False
-            vector_store = app.openai_client.beta.vector_stores.create()
+            if vector_store_id:
+                vector_store = app.openai_client.beta.vector_stores.retrieve(vector_store_id=vector_store_id)
+            else:
+                vector_store = app.openai_client.beta.vector_stores.create()
             file_batch = app.openai_client.beta.vector_stores.file_batches.create_and_poll(
                 vector_store_id=vector_store.id,
                 file_ids=attachments