-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathapp.py
71 lines (59 loc) · 2 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from langchain_community.llms import Ollama
from langchain_community.embeddings import OllamaEmbeddings
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.vectorstores import Chroma
from models import check_if_model_is_available
from document_loader import load_documents_into_database
import argparse
import sys
from llm import getChatChain
def main(llm_model_name: str, embedding_model_name: str, documents_path: str) -> None:
# Check to see if the models available, if not attempt to pull them
try:
check_if_model_is_available(llm_model_name)
check_if_model_is_available(embedding_model_name)
except Exception as e:
print(e)
sys.exit()
# Creating database form documents
try:
db = load_documents_into_database(embedding_model_name, documents_path)
except FileNotFoundError as e:
print(e)
sys.exit()
llm = Ollama(model=llm_model_name)
chat = getChatChain(llm, db)
while True:
try:
user_input = input(
"\n\nPlease enter your question (or type 'exit' to end): "
)
if user_input.lower() == "exit":
break
chat(user_input)
except KeyboardInterrupt:
break
def parse_arguments() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Run local LLM with RAG with Ollama.")
parser.add_argument(
"-m",
"--model",
default="mistral",
help="The name of the LLM model to use.",
)
parser.add_argument(
"-e",
"--embedding_model",
default="nomic-embed-text",
help="The name of the embedding model to use.",
)
parser.add_argument(
"-p",
"--path",
default="Research",
help="The path to the directory containing documents to load.",
)
return parser.parse_args()
if __name__ == "__main__":
args = parse_arguments()
main(args.model, args.embedding_model, args.path)