瀏覽代碼

Update main.py

donzito 2 年之前
父節點
當前提交
d45aabdbdd
共有 1 個文件被更改,包括 4 次插入4 次删除
  1. 4 4
      chatbot/main.py

+ 4 - 4
chatbot/main.py

@@ -31,9 +31,10 @@ class Chatbot():
         # load index
         self.ai_storage_context = None
         self.ai_index = None
-        base_dir = os.path.join(settings.BASE_DIR, 'storage')
+        self.base_dir = os.path.join(settings.BASE_DIR, 'storage')
+        print(self.base_dir)
         try:
-            self.ai_storage_context = StorageContext.from_defaults(persist_dir=base_dir)
+            self.ai_storage_context = StorageContext.from_defaults(persist_dir=self.base_dir)
             self.ai_index = load_index_from_storage(self.ai_storage_context)
         except BaseException as error:
             # exc_type, exc_obj, exc_tb = sys.exc_info()
@@ -41,7 +42,6 @@ class Chatbot():
             # strErro = "ERRO: %s | %s | %s | %s" % (error, exc_type, fname, exc_tb.tb_lineno)
             logger.info('Chatbot() init: '+str(error))
             pass
-        pass
 
     def train (self, chat=None):
         status = 400
@@ -115,7 +115,7 @@ class Chatbot():
         
         # save index to disk
         if ai_documents:
-            self.ai_index.storage_context.persist()
+            self.ai_index.storage_context.persist(persist_dir=self.base_dir)
             status = 200
         
         logger.info('Chatbot Training finished | Status '+str(status))