WaysAhead Global commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -190,26 +190,33 @@ load_or_create_faiss()
|
|
| 190 |
@tool
|
| 191 |
def retrieve_documents(query: str) -> str:
|
| 192 |
"""
|
| 193 |
-
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
"""
|
| 196 |
if not vector_store:
|
| 197 |
-
return "
|
| 198 |
-
|
| 199 |
-
def clean(text):
|
| 200 |
-
text = re.sub(r'\[([^\]]+)\]\((https?://[^\)]+)\)', r'\1', text)
|
| 201 |
-
text = re.sub(r'https?://\S+', '', text)
|
| 202 |
-
return text.strip()
|
| 203 |
|
| 204 |
try:
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
except Exception as e:
|
| 211 |
-
logging.error(f"Document
|
| 212 |
-
return "There was an error
|
| 213 |
@tool
|
| 214 |
def fetch_youtube_videos(query: str) -> list:
|
| 215 |
"""
|
|
|
|
| 190 |
@tool
|
| 191 |
def retrieve_documents(query: str) -> str:
|
| 192 |
"""
|
| 193 |
+
🧠 Use this tool when the answer is likely found in a document, article, magazine, or written content.
|
| 194 |
+
|
| 195 |
+
💡 Ideal for questions that involve:
|
| 196 |
+
- What someone said, did, or thinks
|
| 197 |
+
- Quotes, opinions, event mentions
|
| 198 |
+
- Details that would appear in a news article, magazine, or report
|
| 199 |
+
|
| 200 |
+
❌ Do NOT use for email addresses or CRM-like participant info (use Zoho tool instead)
|
| 201 |
+
|
| 202 |
+
This tool uses a FAISS vector store and RetrievalQA to find the most relevant chunks and generate a context-based answer.
|
| 203 |
"""
|
| 204 |
if not vector_store:
|
| 205 |
+
return "The document system is currently unavailable."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
|
| 207 |
try:
|
| 208 |
+
retriever = vector_store.as_retriever(search_kwargs={"k": 5})
|
| 209 |
+
qa = RetrievalQA.from_chain_type(
|
| 210 |
+
llm=ChatOpenAI(model="gpt-4", temperature=0),
|
| 211 |
+
retriever=retriever,
|
| 212 |
+
return_source_documents=False,
|
| 213 |
+
chain_type="stuff"
|
| 214 |
+
)
|
| 215 |
+
return qa.run(query)
|
| 216 |
+
|
| 217 |
except Exception as e:
|
| 218 |
+
logging.error(f"Document QA error: {e}")
|
| 219 |
+
return "There was an error fetching the answer from documents."
|
| 220 |
@tool
|
| 221 |
def fetch_youtube_videos(query: str) -> list:
|
| 222 |
"""
|