Syed Junaid Iqbal commited on
Commit
d6bdb65
β€’
1 Parent(s): 787200f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -6
app.py CHANGED
@@ -7,25 +7,54 @@ from langchain.vectorstores import Chroma
7
  from langchain.callbacks.manager import CallbackManager
8
  from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
9
  from langchain import hub
 
10
 
11
  def init_retriever():
12
  """
13
  Initialize and return the retriever function
14
  """
15
  callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
16
- llm = LlamaCpp(model_path="./models/llama-2-13b-chat.Q4_K_S.gguf",
 
17
  n_ctx=4000,
18
  max_tokens=4000,
19
- f16_kv=True,
 
20
  callback_manager=callback_manager,
21
  verbose=True)
22
- embeddings = FastEmbedEmbeddings(model_name="BAAI/bge-small-en-v1.5", cache_dir="./embedding_model/")
23
- db = Chroma(persist_directory="./vectordb/", embedding_function=embeddings)
24
- rag_prompt_llama = hub.pull("rlm/rag-prompt-llama")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  qa_chain = RetrievalQA.from_chain_type(
26
  llm,
27
  retriever=db.as_retriever(),
28
- chain_type_kwargs={"prompt": rag_prompt_llama},
29
  )
30
  qa_chain.callback_manager = callback_manager
31
  qa_chain.memory = ConversationBufferMemory()
 
7
  from langchain.callbacks.manager import CallbackManager
8
  from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
9
  from langchain import hub
10
+ from langchain.prompts import PromptTemplate
11
 
12
  def init_retriever():
13
  """
14
  Initialize and return the retriever function
15
  """
16
  callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
17
+ llm = LlamaCpp(model_path="/content/models/llama-2-13b-chat.Q4_K_S.gguf",
18
+ template = 0.4,
19
  n_ctx=4000,
20
  max_tokens=4000,
21
+ n_gpu_layers = 50,
22
+ n_batch = 512,
23
  callback_manager=callback_manager,
24
  verbose=True)
25
+
26
+ embeddings = FastEmbedEmbeddings(model_name="BAAI/bge-small-en-v1.5", cache_dir="/content/embeddings/")
27
+ db = Chroma(persist_directory="/content/vectordb/", embedding_function=embeddings)
28
+
29
+ # prompt template πŸ“
30
+ template = """
31
+ You are a Experience human Resource Manager. When the employee asks you a question, you will have to refer the company policy and respond in a professional way. Make sure to sound Empethetic while being professional and sound like a Human!
32
+
33
+ Try to summarise the content and keep the answer to the point.
34
+
35
+
36
+ If you don't know the answer, just say that you don't know, don't try to make up an answer.
37
+
38
+ When generating answer for the given question make sure to follow the example template!
39
+
40
+ Example:
41
+ Question : how many paid leaves do i have ?
42
+ Answer : The number of paid leaves varies depending on the type of leave, like privilege leave you're entitled to a maximum of 21 days in a calendar year. Other leaves might have different entitlements. thanks for asking!
43
+
44
+ make sure to add "thanks for asking!" after every answer
45
+
46
+ {context}
47
+ Question: {question}
48
+ Answer:
49
+ """
50
+
51
+ rag_prompt_custom = PromptTemplate.from_template(template)
52
+
53
+
54
  qa_chain = RetrievalQA.from_chain_type(
55
  llm,
56
  retriever=db.as_retriever(),
57
+ chain_type_kwargs={"prompt": rag_prompt_custom},
58
  )
59
  qa_chain.callback_manager = callback_manager
60
  qa_chain.memory = ConversationBufferMemory()