fehmikaya commited on
Commit
e0dfd56
·
verified ·
1 Parent(s): 92293bb

Update ragagent.py

Browse files
Files changed (1) hide show
  1. ragagent.py +12 -6
ragagent.py CHANGED
@@ -4,7 +4,7 @@
4
  from langchain_chroma import Chroma
5
  from langchain_huggingface import HuggingFaceEmbeddings
6
  import chromadb
7
- from chromadb import Settings
8
 
9
  from langchain_text_splitters import RecursiveCharacterTextSplitter
10
  from langchain_core.output_parsers import JsonOutputParser
@@ -82,13 +82,19 @@ class RAGAgent():
82
  Here is the question: {question} <|eot_id|><|start_header_id|>assistant<|end_header_id|>""",
83
  input_variables=["generation", "question"],
84
  )
85
-
86
  def reset_chains():
87
  RAGAgent.retrieval_grader = RAGAgent.retrieval_grader_prompt | CustomLlama3(bearer_token = RAGAgent.HF_TOKEN) | JsonOutputParser()
88
  RAGAgent.rag_chain = RAGAgent.answer_prompt | CustomLlama3(bearer_token = RAGAgent.HF_TOKEN) | StrOutputParser()
89
  RAGAgent.hallucination_grader = RAGAgent.hallucination_prompt | CustomLlama3(bearer_token = RAGAgent.HF_TOKEN) | JsonOutputParser()
90
  RAGAgent.answer_grader = RAGAgent.answer_grader_prompt | CustomLlama3(bearer_token = RAGAgent.HF_TOKEN) | JsonOutputParser()
91
-
 
 
 
 
 
 
92
  def __init__(self, docs):
93
  docs_list = [item for sublist in docs for item in sublist]
94
 
@@ -100,7 +106,8 @@ class RAGAgent():
100
  embedding_function = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
101
  collection_name = re.sub(r'[^a-zA-Z0-9]', '', doc_splits[0].metadata.get('source'))
102
 
103
- persistent_client = chromadb.PersistentClient(settings=Settings(allow_reset=True))
 
104
  # persistent_client.reset()
105
  if collection_name in [c.name for c in persistent_client.list_collections()]:
106
  print("\ndeleted: ",collection_name)
@@ -119,7 +126,7 @@ class RAGAgent():
119
  vectorstore.add_documents(doc_splits)
120
 
121
  RAGAgent.retriever = vectorstore.as_retriever()
122
- RAGAgent.reset_chains()
123
  RAGAgent.logs=""
124
 
125
  def add_log(log):
@@ -231,7 +238,6 @@ class RAGAgent():
231
  if grade == "yes":
232
  RAGAgent.add_log("---DECISION: GENERATION IS GROUNDED IN DOCUMENTS---")
233
  # Check question-answering
234
- print("---GRADE GENERATION vs QUESTION---")
235
  score = RAGAgent.answer_grader.invoke({"question": question, "generation": generation})
236
  grade = score["score"]
237
  if grade == "yes":
 
4
  from langchain_chroma import Chroma
5
  from langchain_huggingface import HuggingFaceEmbeddings
6
  import chromadb
7
+ # from chromadb import Settings
8
 
9
  from langchain_text_splitters import RecursiveCharacterTextSplitter
10
  from langchain_core.output_parsers import JsonOutputParser
 
82
  Here is the question: {question} <|eot_id|><|start_header_id|>assistant<|end_header_id|>""",
83
  input_variables=["generation", "question"],
84
  )
85
+ '''
86
  def reset_chains():
87
  RAGAgent.retrieval_grader = RAGAgent.retrieval_grader_prompt | CustomLlama3(bearer_token = RAGAgent.HF_TOKEN) | JsonOutputParser()
88
  RAGAgent.rag_chain = RAGAgent.answer_prompt | CustomLlama3(bearer_token = RAGAgent.HF_TOKEN) | StrOutputParser()
89
  RAGAgent.hallucination_grader = RAGAgent.hallucination_prompt | CustomLlama3(bearer_token = RAGAgent.HF_TOKEN) | JsonOutputParser()
90
  RAGAgent.answer_grader = RAGAgent.answer_grader_prompt | CustomLlama3(bearer_token = RAGAgent.HF_TOKEN) | JsonOutputParser()
91
+ '''
92
+
93
+ RAGAgent.retrieval_grader = RAGAgent.retrieval_grader_prompt | CustomLlama3(bearer_token = RAGAgent.HF_TOKEN) | JsonOutputParser()
94
+ RAGAgent.rag_chain = RAGAgent.answer_prompt | CustomLlama3(bearer_token = RAGAgent.HF_TOKEN) | StrOutputParser()
95
+ RAGAgent.hallucination_grader = RAGAgent.hallucination_prompt | CustomLlama3(bearer_token = RAGAgent.HF_TOKEN) | JsonOutputParser()
96
+ RAGAgent.answer_grader = RAGAgent.answer_grader_prompt | CustomLlama3(bearer_token = RAGAgent.HF_TOKEN) | JsonOutputParser()
97
+
98
  def __init__(self, docs):
99
  docs_list = [item for sublist in docs for item in sublist]
100
 
 
106
  embedding_function = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
107
  collection_name = re.sub(r'[^a-zA-Z0-9]', '', doc_splits[0].metadata.get('source'))
108
 
109
+ # persistent_client = chromadb.PersistentClient(settings=Settings(allow_reset=True))
110
+ persistent_client = chromadb.PersistentClient()
111
  # persistent_client.reset()
112
  if collection_name in [c.name for c in persistent_client.list_collections()]:
113
  print("\ndeleted: ",collection_name)
 
126
  vectorstore.add_documents(doc_splits)
127
 
128
  RAGAgent.retriever = vectorstore.as_retriever()
129
+ # RAGAgent.reset_chains()
130
  RAGAgent.logs=""
131
 
132
  def add_log(log):
 
238
  if grade == "yes":
239
  RAGAgent.add_log("---DECISION: GENERATION IS GROUNDED IN DOCUMENTS---")
240
  # Check question-answering
 
241
  score = RAGAgent.answer_grader.invoke({"question": question, "generation": generation})
242
  grade = score["score"]
243
  if grade == "yes":