Spaces:
Sleeping
Sleeping
Update tools.py
Browse files
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
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
| 91 |
"""
|
|
|
|
| 92 |
|
| 93 |
-
retriever = get_retriever()
|
| 94 |
if retriever is None:
|
| 95 |
-
return "No document
|
| 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 |
-
|
| 105 |
-
|
| 106 |
|
| 107 |
-
|
| 108 |
-
Summarize the
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 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 |
|