captain-awesome
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -41,19 +41,9 @@ def get_vector_store_from_url(url):
|
|
41 |
return vector_store
|
42 |
|
43 |
|
44 |
-
def get_context_retriever_chain(vector_store):
|
45 |
# llm = ChatOpenAI()
|
46 |
-
llm =
|
47 |
-
# model = "TheBloke/Mistral-7B-Instruct-v0.2-GGUF",
|
48 |
-
model= "TheBloke/Llama-2-7B-Chat-GGUF",
|
49 |
-
model_file = "llama-2-7b-chat.Q3_K_S.gguf",
|
50 |
-
model_type="llama",
|
51 |
-
max_new_tokens = 300,
|
52 |
-
temperature = 0.3,
|
53 |
-
lib="avx2", # for CPU
|
54 |
-
)
|
55 |
-
|
56 |
-
|
57 |
retriever = vector_store.as_retriever()
|
58 |
|
59 |
prompt = ChatPromptTemplate.from_messages([
|
@@ -67,17 +57,9 @@ def get_context_retriever_chain(vector_store):
|
|
67 |
return retriever_chain
|
68 |
|
69 |
|
70 |
-
def get_conversational_rag_chain(retriever_chain):
|
71 |
|
72 |
-
llm
|
73 |
-
# model = "TheBloke/Mistral-7B-Instruct-v0.2-GGUF",
|
74 |
-
model= "TheBloke/Llama-2-7B-Chat-GGUF",
|
75 |
-
model_file = "llama-2-7b-chat.Q3_K_S.gguf",
|
76 |
-
model_type="llama",
|
77 |
-
max_new_tokens = 300,
|
78 |
-
temperature = 0.3,
|
79 |
-
lib="avx2", # for CPU
|
80 |
-
)
|
81 |
|
82 |
prompt = ChatPromptTemplate.from_messages([
|
83 |
("system", "Answer the user's questions based on the below context:\n\n{context}"),
|
@@ -90,8 +72,17 @@ def get_conversational_rag_chain(retriever_chain):
|
|
90 |
return create_retrieval_chain(retriever_chain, stuff_documents_chain)
|
91 |
|
92 |
def get_response(user_input):
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
response = conversation_rag_chain.invoke({
|
97 |
"chat_history": st.session_state.chat_history,
|
|
|
41 |
return vector_store
|
42 |
|
43 |
|
44 |
+
def get_context_retriever_chain(vector_store,llm):
|
45 |
# llm = ChatOpenAI()
|
46 |
+
llm = llm
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
retriever = vector_store.as_retriever()
|
48 |
|
49 |
prompt = ChatPromptTemplate.from_messages([
|
|
|
57 |
return retriever_chain
|
58 |
|
59 |
|
60 |
+
def get_conversational_rag_chain(retriever_chain,llm):
|
61 |
|
62 |
+
llm=llm
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
prompt = ChatPromptTemplate.from_messages([
|
65 |
("system", "Answer the user's questions based on the below context:\n\n{context}"),
|
|
|
72 |
return create_retrieval_chain(retriever_chain, stuff_documents_chain)
|
73 |
|
74 |
def get_response(user_input):
|
75 |
+
llm = CTransformers(
|
76 |
+
# model = "TheBloke/Mistral-7B-Instruct-v0.2-GGUF",
|
77 |
+
model= "TheBloke/Llama-2-7B-Chat-GGUF",
|
78 |
+
model_file = "llama-2-7b-chat.Q3_K_S.gguf",
|
79 |
+
model_type="llama",
|
80 |
+
max_new_tokens = 300,
|
81 |
+
temperature = 0.3,
|
82 |
+
lib="avx2", # for CPU
|
83 |
+
)
|
84 |
+
retriever_chain = get_context_retriever_chain(st.session_state.vector_store,llm)
|
85 |
+
conversation_rag_chain = get_conversational_rag_chain(retriever_chain,llm)
|
86 |
|
87 |
response = conversation_rag_chain.invoke({
|
88 |
"chat_history": st.session_state.chat_history,
|