fehmikaya commited on
Commit
911fa32
·
verified ·
1 Parent(s): be7c3f9

Update ragagent.py

Browse files
Files changed (1) hide show
  1. ragagent.py +1 -34
ragagent.py CHANGED
@@ -49,18 +49,6 @@ class RAGAgent():
49
  st.error("API key not found. Please set the TAVILY_API_KEY secret in your Hugging Face Space.")
50
  st.stop()
51
 
52
- router_llm = CustomLlama3(bearer_token = HF_TOKEN)
53
- router_prompt = PromptTemplate(
54
- template="""<|begin_of_text|><|start_header_id|>system<|end_header_id|> You are an expert at routing a
55
- user question to a vectorstore or web search. Use the vectorstore for questions on LLM agents,
56
- prompt engineering, and adversarial attacks. You do not need to be stringent with the keywords
57
- in the question related to these topics. Otherwise, use web-search. Give a binary choice 'web_search'
58
- or 'vectorstore' based on the question. Return the a JSON with a single key 'datasource' and
59
- no premable or explanation. Question to route: {question} <|eot_id|><|start_header_id|>assistant<|end_header_id|>""",
60
- input_variables=["question"],
61
- )
62
- question_router = router_prompt | router_llm | JsonOutputParser()
63
-
64
  retrieval_grader_prompt = PromptTemplate(
65
  template="""<|begin_of_text|><|start_header_id|>system<|end_header_id|> You are a grader assessing relevance
66
  of a retrieved document to a user question. If the document contains keywords related to the user question,
@@ -193,21 +181,6 @@ class RAGAgent():
193
  return {"documents": documents, "question": question}
194
 
195
 
196
- def route_question(state):
197
-
198
- print("---ROUTE QUESTION---")
199
- question = state["question"]
200
- print(question)
201
- source = RAGAgent.question_router.invoke({"question": question})
202
-
203
- if source["datasource"] == "web_search":
204
- print("---ROUTE QUESTION TO WEB SEARCH---")
205
- return "websearch"
206
- elif source["datasource"] == "vectorstore":
207
- print("---ROUTE QUESTION TO RAG---")
208
- return "vectorstore"
209
-
210
-
211
  def decide_to_generate(state):
212
 
213
  print("---ASSESS GRADED DOCUMENTS---")
@@ -265,13 +238,7 @@ class RAGAgent():
265
  workflow.add_node("generate", generate) # generatae
266
 
267
  # Build graph
268
- workflow.set_conditional_entry_point(
269
- route_question,
270
- {
271
- "websearch": "websearch",
272
- "vectorstore": "retrieve",
273
- },
274
- )
275
 
276
  workflow.add_edge("retrieve", "grade_documents")
277
  workflow.add_conditional_edges(
 
49
  st.error("API key not found. Please set the TAVILY_API_KEY secret in your Hugging Face Space.")
50
  st.stop()
51
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  retrieval_grader_prompt = PromptTemplate(
53
  template="""<|begin_of_text|><|start_header_id|>system<|end_header_id|> You are a grader assessing relevance
54
  of a retrieved document to a user question. If the document contains keywords related to the user question,
 
181
  return {"documents": documents, "question": question}
182
 
183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  def decide_to_generate(state):
185
 
186
  print("---ASSESS GRADED DOCUMENTS---")
 
238
  workflow.add_node("generate", generate) # generatae
239
 
240
  # Build graph
241
+ workflow.set_entry_point("retrieve")
 
 
 
 
 
 
242
 
243
  workflow.add_edge("retrieve", "grade_documents")
244
  workflow.add_conditional_edges(