瀏覽代碼

Storage base dir

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

+ 1 - 0
.gitignore

@@ -2,3 +2,4 @@
 /storage/*
 .DS_Store
 .vscode/launch.json
+*.pyc

+ 3 - 1
chatbot/main.py

@@ -6,6 +6,7 @@ import logging
 from datetime import datetime, timedelta
 from io import BytesIO
 from django.utils.text import slugify
+from django.conf import settings
 
 import openai
 from llama_index import VectorStoreIndex, Document, StorageContext, load_index_from_storage
@@ -30,8 +31,9 @@ class Chatbot():
         # load index
         self.ai_storage_context = None
         self.ai_index = None
+        base_dir = settings.BASE_DIR + '/storage'
         try:
-            self.ai_storage_context = StorageContext.from_defaults(persist_dir='./storage')
+            self.ai_storage_context = StorageContext.from_defaults(persist_dir=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()