Langchain-Chatchat/cli_demo.py

38 lines
1.3 KiB
Python
Raw Normal View History

2023-04-13 23:01:52 +08:00
from configs.model_config import *
from chains.local_doc_qa import LocalDocQA
2023-04-16 23:38:25 +08:00
import os
import nltk
nltk.data.path = [os.path.join(os.path.dirname(__file__), "nltk_data")] + nltk.data.path
2023-04-13 23:01:52 +08:00
# return top-k text chunk from vector store
2023-04-17 23:59:22 +08:00
VECTOR_SEARCH_TOP_K = 6
2023-04-13 23:01:52 +08:00
# LLM input history length
LLM_HISTORY_LEN = 3
# Show reply with source text from input document
REPLY_WITH_SOURCE = True
if __name__ == "__main__":
local_doc_qa = LocalDocQA()
local_doc_qa.init_cfg(llm_model=LLM_MODEL,
embedding_model=EMBEDDING_MODEL,
embedding_device=EMBEDDING_DEVICE,
2023-04-14 00:06:45 +08:00
llm_history_len=LLM_HISTORY_LEN,
top_k=VECTOR_SEARCH_TOP_K)
2023-04-13 23:01:52 +08:00
vs_path = None
while not vs_path:
filepath = input("Input your local knowledge file path 请输入本地知识文件路径:")
vs_path = local_doc_qa.init_knowledge_vector_store(filepath)
history = []
while True:
query = input("Input your question 请输入问题:")
resp, history = local_doc_qa.get_knowledge_based_answer(query=query,
vs_path=vs_path,
chat_history=history)
if REPLY_WITH_SOURCE:
print(resp)
else:
print(resp["result"])