vidhiparikh commited on
Commit
37393b4
1 Parent(s): 7adf33a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -25
app.py CHANGED
@@ -74,30 +74,16 @@ As an AI, provide accurate and relevant information based on the provided docume
74
  callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
75
 
76
  # Function to create a conversational chain
77
- def create_conversational_chain(database):
78
- model_name = 'TheBloke/Llama-2-7b-chat-hf'
79
- model_directory = "files"
80
- #Check if the model file exists in the specified directory
81
- model_file = os.path.join(model_directory, model_name)
82
- if os.path.exists(model_file):
83
- model_path = model_file
84
- print("Model file found in the directory. Using the local model file.")
85
- else:
86
- model_path = "https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/blob/main/llama-2-7b-chat.Q8_0.gguf"
87
- print("Model file not found in the directory. Downloading the model from the repository.")
88
- #Load the model
89
- model = AutoModelForCausalLM.from_pretrained(model_path)
90
- print(model_path)
91
  llama_llm = LlamaCpp(
92
- # Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system. llama-2-7b-chat.Q8_0.gguf
93
- model_path = model_path,
94
- temperature=0.75,
95
- max_tokens=200,
96
- top_p=1,
97
- callback_manager=callback_manager,
98
- n_ctx=3000)
99
-
100
- retriever = database.as_retriever()
101
  CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(template)
102
 
103
  memory = ConversationBufferMemory(
@@ -109,10 +95,9 @@ def create_conversational_chain(database):
109
  #condense_question_prompt=CONDENSE_QUESTION_PROMPT,
110
  memory=memory,
111
  return_source_documents=True))
112
- print("Conversational Chain created.")
113
  return conversation_chain
114
 
115
- # Function to validate the answer against source documents
116
  def validate_answer(response_answer, source_documents):
117
  model = SentenceTransformer('all-MiniLM-L6-v2')
118
  similarity_threshold = 0.5
 
74
  callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
75
 
76
  # Function to create a conversational chain
77
+ def create_conversational_chain(vectordb):
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  llama_llm = LlamaCpp(
79
+ model_path="llama-2-7b-chat.Q8_0.gguf",
80
+ temperature=0.75,
81
+ max_tokens=200,
82
+ top_p=1,
83
+ callback_manager=callback_manager,
84
+ n_ctx=3000)
85
+
86
+ retriever = vectordb.as_retriever()
 
87
  CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(template)
88
 
89
  memory = ConversationBufferMemory(
 
95
  #condense_question_prompt=CONDENSE_QUESTION_PROMPT,
96
  memory=memory,
97
  return_source_documents=True))
98
+ print("Conversational Chain created for the LLM using the vector store")
99
  return conversation_chain
100
 
 
101
  def validate_answer(response_answer, source_documents):
102
  model = SentenceTransformer('all-MiniLM-L6-v2')
103
  similarity_threshold = 0.5