Deepakkori45 commited on
Commit
ce5b2c7
·
verified ·
1 Parent(s): a906f89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -38
app.py CHANGED
@@ -67,46 +67,46 @@ def stream_generator(prompt, thread_id):
67
  except Exception as e:
68
  print(f"Error during streaming: {str(e)}")
69
 
70
- # def upload_and_add_to_vector_store(uploaded_file):
71
- # """Upload a file to OpenAI and add it to the specified vector store."""
72
- # try:
73
- # # Convert the uploaded file to a BytesIO stream for uploading
74
- # file_stream = io.BytesIO(uploaded_file.getvalue())
75
- # file_stream.name = uploaded_file.name # Preserve the file name
76
- # # Upload the file to the vector store
77
- # file_batch = client.beta.vector_stores.file_batches.upload_and_poll(
78
- # vector_store_id=vector_store_id,
79
- # files=[file_stream]
80
- # )
81
-
82
-
83
- # st.success(f"File '{uploaded_file.name}' processed and added to vector store. Status: {file_batch.status}")
84
- # except Exception as e:
85
- # st.error(f"Failed to process file: {str(e)}")
86
 
87
 
88
- # def list_all_files_in_vector_store():
89
- # """List all files in the specified vector store."""
90
- # try:
91
- # all_files = list(client.beta.vector_stores.files.list(vector_store_id=vector_store_id))
92
- # # st.write(all_files)
93
- # for file in all_files:
94
- # file_id = file.id
95
- # st.write(file_id)
96
- # except Exception as e:
97
- # st.error(f"Failed to list files: {str(e)}")
98
- # return {}
99
-
100
- # def delete_file_from_vector_store(vector_store_id, file_id):
101
- # """Delete a file from the specified vector store."""
102
- # try:
103
- # client.beta.vector_stores.files.delete(
104
- # vector_store_id=vector_store_id,
105
- # file_id=file_id
106
- # )
107
- # st.success(f"File with ID '{file_id}' deleted from vector store '{vector_store_id}'.")
108
- # except Exception as e:
109
- # st.error(f"Failed to delete file. File id is not Found.")
110
 
111
  # Interface to delete files from vector store
112
  st.sidebar.subheader("Delete File from Vector Store")
 
67
  except Exception as e:
68
  print(f"Error during streaming: {str(e)}")
69
 
70
+ def upload_and_add_to_vector_store(uploaded_file):
71
+ """Upload a file to OpenAI and add it to the specified vector store."""
72
+ try:
73
+ # Convert the uploaded file to a BytesIO stream for uploading
74
+ file_stream = io.BytesIO(uploaded_file.getvalue())
75
+ file_stream.name = uploaded_file.name # Preserve the file name
76
+ # Upload the file to the vector store
77
+ file_batch = client.beta.vector_stores.file_batches.upload_and_poll(
78
+ vector_store_id=vector_store_id,
79
+ files=[file_stream]
80
+ )
81
+
82
+
83
+ st.success(f"File '{uploaded_file.name}' processed and added to vector store. Status: {file_batch.status}")
84
+ except Exception as e:
85
+ st.error(f"Failed to process file: {str(e)}")
86
 
87
 
88
+ def list_all_files_in_vector_store():
89
+ """List all files in the specified vector store."""
90
+ try:
91
+ all_files = list(client.beta.vector_stores.files.list(vector_store_id=vector_store_id))
92
+ # st.write(all_files)
93
+ for file in all_files:
94
+ file_id = file.id
95
+ st.write(file_id)
96
+ except Exception as e:
97
+ st.error(f"Failed to list files: {str(e)}")
98
+ return {}
99
+
100
+ def delete_file_from_vector_store(vector_store_id, file_id):
101
+ """Delete a file from the specified vector store."""
102
+ try:
103
+ client.beta.vector_stores.files.delete(
104
+ vector_store_id=vector_store_id,
105
+ file_id=file_id
106
+ )
107
+ st.success(f"File with ID '{file_id}' deleted from vector store '{vector_store_id}'.")
108
+ except Exception as e:
109
+ st.error(f"Failed to delete file. File id is not Found.")
110
 
111
  # Interface to delete files from vector store
112
  st.sidebar.subheader("Delete File from Vector Store")