浏览代码

修改路径

yulongyan_citu 10 月之前
父节点
当前提交
7d7223c6c3
共有 3 个文件被更改,包括 9 次插入9 次删除
  1. 8 5
      app.py
  2. 0 3
      qa_chain/Chat_QA_chain_self.py
  3. 1 1
      qa_chain/get_vectordb.py

+ 8 - 5
app.py

@@ -29,12 +29,15 @@ app.add_middleware(
     # max_age=1000
 )
 
-# 定义默认路径
-DEFAULT_DB_PATH = os.path.join(".", "knowledge_db")
-DEFAULT_PERSIST_PATH = os.path.join(".", "vector_db", "chroma")
+# 获取当前脚本所在的绝对路径
+current_dir = os.path.dirname(os.path.abspath(__file__))
 
-# 初始化你的Chat_QA_chain_self实例
-chat_qa_chain = Chat_QA_chain_self(file_path=DEFAULT_DB_PATH, persist_path=DEFAULT_PERSIST_PATH,embedding='m3e')
+# 构建默认路径
+DEFAULT_DB_PATH = os.path.join(current_dir, "knowledge_db")
+DEFAULT_PERSIST_PATH = os.path.join(current_dir, "vector_db", "chroma")
+
+# 初始化 QA 链接
+chat_qa_chain = Chat_QA_chain_self(file_path=DEFAULT_DB_PATH, persist_path=DEFAULT_PERSIST_PATH, embedding='m3e')
 
 @app.post('/clear/history')
 async def clear_history():

+ 0 - 3
qa_chain/Chat_QA_chain_self.py

@@ -17,9 +17,6 @@ from graph.graph_retrieval import connect, structured_retriever, text_structured
 from llm.llm import LLM
 import os
 
-DEFAULT_DB_PATH = os.path.join("..", "knowledge_db")
-DEFAULT_PERSIST_PATH = os.path.join("..", "vector_db", "chroma")
-
 class Chat_QA_chain_self:
     """
     带历史记录的问答链

+ 1 - 1
qa_chain/get_vectordb.py

@@ -19,7 +19,7 @@ def get_vectordb(file_path, persist_path, embedding="m3e"):
     if os.path.exists(persist_path):  # 持久化目录存在
         contents = os.listdir(persist_path)
         if len(contents) == 0:  # 但是下面为空
-            print("目录为空")
+            # print("目录为空")
             create_db(file_path, persist_path, embedding)
             # presit_knowledge_db(vectordb)
             vectordb = load_knowledge_db(persist_path, embedding)