Spaces:
Sleeping
Sleeping
Karthikeyan
commited on
Commit
·
9d3b0a5
1
Parent(s):
f7645e3
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,6 @@ from langchain.text_splitter import CharacterTextSplitter
|
|
| 8 |
from langchain.vectorstores import FAISS
|
| 9 |
from langchain.vectorstores import Chroma
|
| 10 |
from langchain.chains import ConversationalRetrievalChain
|
| 11 |
-
from langchain.memory import ConversationBufferMemory
|
| 12 |
import gradio as gr
|
| 13 |
import openai
|
| 14 |
from langchain import PromptTemplate, OpenAI, LLMChain
|
|
@@ -126,15 +125,12 @@ class Chatbot:
|
|
| 126 |
str: The answer to the question.
|
| 127 |
"""
|
| 128 |
|
| 129 |
-
chat_history = []
|
| 130 |
# Retrieve the knowledge base from the state dictionary
|
| 131 |
knowledge_base = state["knowledge_base"]
|
| 132 |
retriever = knowledge_base.as_retriever()
|
| 133 |
-
chat_history.append(question)
|
| 134 |
qa = ConversationalRetrievalChain.from_llm(
|
| 135 |
-
llm=OpenAI(temperature=0),
|
| 136 |
retriever=retriever,
|
| 137 |
-
memory=ConversationBufferMemory(memory_key="chat_history",return_messages=True),
|
| 138 |
return_source_documents=False)
|
| 139 |
# Set the question for which we want to find the answer
|
| 140 |
res = []
|
|
@@ -149,7 +145,6 @@ class Chatbot:
|
|
| 149 |
result = qa({"question": query, "chat_history": chat_history})
|
| 150 |
# Perform a similarity search on the knowledge base to retrieve relevant documents
|
| 151 |
response = result["answer"]
|
| 152 |
-
chat_history.append(response)
|
| 153 |
# Return the response as the answer to the question
|
| 154 |
history[-1][1] = response
|
| 155 |
return history
|
|
|
|
| 8 |
from langchain.vectorstores import FAISS
|
| 9 |
from langchain.vectorstores import Chroma
|
| 10 |
from langchain.chains import ConversationalRetrievalChain
|
|
|
|
| 11 |
import gradio as gr
|
| 12 |
import openai
|
| 13 |
from langchain import PromptTemplate, OpenAI, LLMChain
|
|
|
|
| 125 |
str: The answer to the question.
|
| 126 |
"""
|
| 127 |
|
|
|
|
| 128 |
# Retrieve the knowledge base from the state dictionary
|
| 129 |
knowledge_base = state["knowledge_base"]
|
| 130 |
retriever = knowledge_base.as_retriever()
|
|
|
|
| 131 |
qa = ConversationalRetrievalChain.from_llm(
|
| 132 |
+
llm=OpenAI(temperature=0.5),
|
| 133 |
retriever=retriever,
|
|
|
|
| 134 |
return_source_documents=False)
|
| 135 |
# Set the question for which we want to find the answer
|
| 136 |
res = []
|
|
|
|
| 145 |
result = qa({"question": query, "chat_history": chat_history})
|
| 146 |
# Perform a similarity search on the knowledge base to retrieve relevant documents
|
| 147 |
response = result["answer"]
|
|
|
|
| 148 |
# Return the response as the answer to the question
|
| 149 |
history[-1][1] = response
|
| 150 |
return history
|