ArturG9 commited on
Commit
5a77081
·
verified ·
1 Parent(s): 6602c24

Update utills.py

Browse files
Files changed (1) hide show
  1. utills.py +7 -7
utills.py CHANGED
@@ -24,7 +24,7 @@ from langchain_community.llms import llamacpp
24
  import streamlit as st
25
 
26
  store = {}
27
- @st.cache_resource
28
  def get_session_history(session_id: str):
29
  if session_id not in store:
30
  store[session_id] = ChatMessageHistory()
@@ -32,7 +32,7 @@ def get_session_history(session_id: str):
32
 
33
 
34
 
35
- @st.cache_resource
36
  def load_pdf_documents(data_path):
37
  try:
38
  document_loader = PyPDFDirectoryLoader(data_path)
@@ -42,7 +42,7 @@ def load_pdf_documents(data_path):
42
  return None # or handle the error in an appropriate manner
43
 
44
 
45
- @st.cache_data
46
  def load_txt_documents(data_path):
47
  documents = []
48
  for filename in os.listdir(data_path):
@@ -51,7 +51,7 @@ def load_txt_documents(data_path):
51
  documents.extend(TextLoader(file_path).load())
52
  return documents
53
 
54
- @st.cache_resource
55
  def split_docs(_documents, chunk_size, chunk_overlap):
56
  try:
57
  text_splitter = RecursiveCharacterTextSplitter.from_tiktoken_encoder(
@@ -64,7 +64,7 @@ def split_docs(_documents, chunk_size, chunk_overlap):
64
  print(f"Error splitting documents: {e}")
65
  return [] # or handle the error in an appropriate manner
66
 
67
- @st.cache_data
68
  def load_uploaded_documents(uploaded_files):
69
  documents = []
70
  for uploaded_file in uploaded_files:
@@ -79,7 +79,7 @@ def retriever_from_chroma(docs, embeddings, search_type, k):
79
  retriever = vectordb.as_retriever(search_type=search_type, search_kwargs={"k": k})
80
  return retriever
81
 
82
- @st.cache_resource
83
  def history_aware_retriever(llm, retriever, contextualize_q_system_prompt):
84
  try:
85
  contextualize_q_prompt = ChatPromptTemplate.from_messages(
@@ -97,7 +97,7 @@ def history_aware_retriever(llm, retriever, contextualize_q_system_prompt):
97
 
98
 
99
 
100
- @st.cache_resource
101
  def echo(question, history):
102
  ai_message = rag_chain.invoke({"input": question, "chat_history": chat_history})
103
  chat_history.extend([HumanMessage(content=question), ai_message["answer"]])
 
24
  import streamlit as st
25
 
26
  store = {}
27
+
28
  def get_session_history(session_id: str):
29
  if session_id not in store:
30
  store[session_id] = ChatMessageHistory()
 
32
 
33
 
34
 
35
+
36
  def load_pdf_documents(data_path):
37
  try:
38
  document_loader = PyPDFDirectoryLoader(data_path)
 
42
  return None # or handle the error in an appropriate manner
43
 
44
 
45
+
46
  def load_txt_documents(data_path):
47
  documents = []
48
  for filename in os.listdir(data_path):
 
51
  documents.extend(TextLoader(file_path).load())
52
  return documents
53
 
54
+
55
  def split_docs(_documents, chunk_size, chunk_overlap):
56
  try:
57
  text_splitter = RecursiveCharacterTextSplitter.from_tiktoken_encoder(
 
64
  print(f"Error splitting documents: {e}")
65
  return [] # or handle the error in an appropriate manner
66
 
67
+
68
  def load_uploaded_documents(uploaded_files):
69
  documents = []
70
  for uploaded_file in uploaded_files:
 
79
  retriever = vectordb.as_retriever(search_type=search_type, search_kwargs={"k": k})
80
  return retriever
81
 
82
+
83
  def history_aware_retriever(llm, retriever, contextualize_q_system_prompt):
84
  try:
85
  contextualize_q_prompt = ChatPromptTemplate.from_messages(
 
97
 
98
 
99
 
100
+
101
  def echo(question, history):
102
  ai_message = rag_chain.invoke({"input": question, "chat_history": chat_history})
103
  chat_history.extend([HumanMessage(content=question), ai_message["answer"]])