junaid17 commited on
Commit
2e019bc
·
verified ·
1 Parent(s): f4a7ce5

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +21 -21
tools.py CHANGED
@@ -83,41 +83,41 @@ def get_retriever():
83
 
84
  def create_rag_tool():
85
 
86
- @tool()
87
  def rag_search(query: str) -> str:
88
  """
89
- Retrieve and summarize information from uploaded documents.
90
- Returns the final summarized answer directly.
 
 
 
91
  """
 
92
 
93
- retriever = get_retriever()
94
  if retriever is None:
95
- return "No document has been uploaded yet."
96
 
97
  docs = retriever.invoke(query)
98
 
99
  if not docs:
100
- return "No relevant information found in the document."
101
 
102
- context = "\n".join(d.page_content for d in docs)
103
 
104
- from langchain_openai import ChatOpenAI
105
- llm = ChatOpenAI(model="gpt-4.1-nano", temperature=0.2)
106
 
107
- summary_prompt = f"""
108
- Summarize the following content clearly and concisely.
 
 
 
 
109
 
110
- Rules:
111
- - Use bullet points where appropriate
112
- - Do NOT repeat ideas
113
- - Do NOT explain what the document is
114
- - Do NOT add commentary
115
- - Stop after the summary
116
 
117
- CONTENT:
118
- {context}
119
- """
120
- return response.content.strip()
121
 
122
  return rag_search
123
 
 
83
 
84
  def create_rag_tool():
85
 
86
+ @tool
87
  def rag_search(query: str) -> str:
88
  """
89
+ Retrieve relevant information from the uploaded document.
90
+
91
+ Use this tool when the user asks questions related to the uploaded PDF
92
+ or any document-based knowledge. If no document is available or no
93
+ relevant information is found, return an appropriate message.
94
  """
95
+ global retriever
96
 
 
97
  if retriever is None:
98
+ return "No document uploaded yet."
99
 
100
  docs = retriever.invoke(query)
101
 
102
  if not docs:
103
+ return "No relevant information found in the uploaded document."
104
 
105
+ context = "\n\n".join(d.page_content for d in docs)
106
 
107
+ return f"""
108
+ You are given extracted content from a document.
109
 
110
+ Your task:
111
+ - Summarize the content clearly
112
+ - Use bullet points where appropriate
113
+ - Keep formatting clean and readable
114
+ - Do NOT repeat unnecessary text
115
+ - Do NOT mention that this came from a document
116
 
117
+ DOCUMENT CONTENT:
118
+ {context}
119
+ """
 
 
 
120
 
 
 
 
 
121
 
122
  return rag_search
123