junaid17 commited on
Commit
8a0d556
·
verified ·
1 Parent(s): 7a14b73

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +18 -21
tools.py CHANGED
@@ -83,17 +83,14 @@ 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
-
91
- Use this tool whenever the user asks about uploaded documents.
92
- Summarize clearly and avoid repeating raw content.
93
  """
94
 
95
  retriever = get_retriever()
96
-
97
  if retriever is None:
98
  return "No document has been uploaded yet."
99
 
@@ -102,27 +99,27 @@ def create_rag_tool():
102
  if not docs:
103
  return "No relevant information found in the document."
104
 
105
- context = "\n\n".join(d.page_content for d in docs)
106
-
107
- summary_prompt = f"""
108
- Summarize the following content clearly and concisely.
109
-
110
- Rules:
111
- - Use bullet points when helpful
112
- - Do NOT repeat ideas
113
- - Do NOT mention the document
114
- - Stop after the summary
115
-
116
- CONTENT:
117
- {context}
118
- """
119
 
 
120
  llm = ChatOpenAI(model="gpt-4.1-nano", temperature=0.2)
121
 
122
- summary = llm.invoke(summary_prompt)
 
 
 
 
 
 
 
 
123
 
124
- return summary.content.strip()
 
 
125
 
 
 
126
 
127
  return rag_search
128
 
 
83
 
84
  def create_rag_tool():
85
 
86
+ @tool(return_direct=True)
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
 
 
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
 
121
+ response = llm.invoke(summary_prompt)
122
+ return response.content.strip()
123
 
124
  return rag_search
125