Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,18 +9,18 @@ from langchain_openai import ChatOpenAI
|
|
| 9 |
from langchain.chains.combine_documents import create_stuff_documents_chain
|
| 10 |
from langchain.embeddings import HuggingFaceEmbeddings
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
embedding_function=embedding_model)
|
| 18 |
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
| 22 |
|
| 23 |
-
|
| 24 |
instructions = file.read()
|
| 25 |
|
| 26 |
|
|
@@ -37,15 +37,15 @@ memory = ConversationBufferMemory(
|
|
| 37 |
return_messages=True
|
| 38 |
)
|
| 39 |
|
| 40 |
-
|
| 41 |
|
| 42 |
-
|
| 43 |
|
| 44 |
-
|
| 45 |
greetings = {"hey", "hi", "hello"}
|
| 46 |
normalized_query = query.strip().lower()
|
| 47 |
|
| 48 |
-
|
| 49 |
chat_history = memory.load_memory_variables({})["chat_history"][-6::]
|
| 50 |
else:
|
| 51 |
chat_history = memory.load_memory_variables({})["chat_history"]
|
|
@@ -70,9 +70,9 @@ memory = ConversationBufferMemory(
|
|
| 70 |
|
| 71 |
return answer
|
| 72 |
|
| 73 |
-
|
| 74 |
conversate_assistant,
|
| 75 |
type="messages"
|
| 76 |
)
|
| 77 |
|
| 78 |
-
|
|
|
|
| 9 |
from langchain.chains.combine_documents import create_stuff_documents_chain
|
| 10 |
from langchain.embeddings import HuggingFaceEmbeddings
|
| 11 |
|
| 12 |
+
embedding_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
| 13 |
|
| 14 |
+
persist_directory = 'vec_db'
|
| 15 |
|
| 16 |
+
vectordb = Chroma(persist_directory=persist_directory,
|
| 17 |
embedding_function=embedding_model)
|
| 18 |
|
| 19 |
+
vectordb_retriever = vectordb.as_retriever(search_kwargs={'k':5})
|
| 20 |
|
| 21 |
+
llm = ChatOpenAI(model="gpt-4.1-nano", temperature=0.7)
|
| 22 |
|
| 23 |
+
with open("instructions.txt", 'r') as file:
|
| 24 |
instructions = file.read()
|
| 25 |
|
| 26 |
|
|
|
|
| 37 |
return_messages=True
|
| 38 |
)
|
| 39 |
|
| 40 |
+
question_answer_chain = create_stuff_documents_chain(llm, custom_prompt)
|
| 41 |
|
| 42 |
+
chain = create_retrieval_chain(vectordb_retriever, question_answer_chain)
|
| 43 |
|
| 44 |
+
def conversate_assistant(query, history):
|
| 45 |
greetings = {"hey", "hi", "hello"}
|
| 46 |
normalized_query = query.strip().lower()
|
| 47 |
|
| 48 |
+
if len(memory.load_memory_variables({})["chat_history"]) >=6:
|
| 49 |
chat_history = memory.load_memory_variables({})["chat_history"][-6::]
|
| 50 |
else:
|
| 51 |
chat_history = memory.load_memory_variables({})["chat_history"]
|
|
|
|
| 70 |
|
| 71 |
return answer
|
| 72 |
|
| 73 |
+
demo = gr.ChatInterface(
|
| 74 |
conversate_assistant,
|
| 75 |
type="messages"
|
| 76 |
)
|
| 77 |
|
| 78 |
+
demo.launch()
|