Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -181,14 +181,24 @@ def build_graph(provider: str = "groq"):
|
|
| 181 |
|
| 182 |
def retriever(state: MessagesState):
|
| 183 |
query = state["messages"][-1].content
|
| 184 |
-
|
| 185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
content = similar_doc.page_content
|
|
|
|
| 187 |
if "Final answer :" in content:
|
| 188 |
answer = content.split("Final answer :")[-1].strip()
|
| 189 |
else:
|
| 190 |
answer = content.strip()
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
return {"messages": [AIMessage(content=answer)]}
|
| 193 |
|
| 194 |
|
|
|
|
| 181 |
|
| 182 |
def retriever(state: MessagesState):
|
| 183 |
query = state["messages"][-1].content
|
| 184 |
+
similar_docs = vector_store.similarity_search(query, k=1)
|
| 185 |
+
|
| 186 |
+
# Handle empty results
|
| 187 |
+
if not similar_docs:
|
| 188 |
+
return {"messages": [AIMessage(content="I don't have information about this topic in my knowledge base. Please try a different question.")]}
|
| 189 |
+
|
| 190 |
+
similar_doc = similar_docs[0]
|
| 191 |
content = similar_doc.page_content
|
| 192 |
+
|
| 193 |
if "Final answer :" in content:
|
| 194 |
answer = content.split("Final answer :")[-1].strip()
|
| 195 |
else:
|
| 196 |
answer = content.strip()
|
| 197 |
+
|
| 198 |
+
# Ensure answer is not empty
|
| 199 |
+
if not answer:
|
| 200 |
+
answer = "I found related information but couldn't extract a clear answer. Please rephrase your question."
|
| 201 |
+
|
| 202 |
return {"messages": [AIMessage(content=answer)]}
|
| 203 |
|
| 204 |
|