Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -127,11 +127,11 @@ class SuperSmartAgent:
|
|
| 127 |
###################
|
| 128 |
def general_reasoning_qa(state):
|
| 129 |
question = state["question"]
|
| 130 |
-
|
| 131 |
# Step 1: Search Wikipedia broadly
|
| 132 |
search_results = wikipedia.search(question)
|
| 133 |
relevant_pages = search_results[:3] # get top 3 pages
|
| 134 |
-
|
| 135 |
context = ""
|
| 136 |
for title in relevant_pages:
|
| 137 |
try:
|
|
@@ -143,20 +143,21 @@ class SuperSmartAgent:
|
|
| 143 |
state["response"] = "Sorry, I couldn’t find enough information."
|
| 144 |
return state
|
| 145 |
|
| 146 |
-
# Step 2:
|
|
|
|
| 147 |
prompt = f"""
|
| 148 |
Based on the following Wikipedia content, answer the question:
|
| 149 |
-
|
| 150 |
Question: {question}
|
| 151 |
-
|
| 152 |
Context:
|
| 153 |
{context}
|
| 154 |
-
|
| 155 |
Answer in a single sentence.
|
| 156 |
"""
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
|
| 161 |
def check_reasoning_needed(state):
|
| 162 |
q = state["question"].lower()
|
|
@@ -169,7 +170,7 @@ class SuperSmartAgent:
|
|
| 169 |
def check_wikipedia_suitability(state):
|
| 170 |
q = state["question"].lower()
|
| 171 |
# Simple heuristic: if it's a "who is", "what is", or named entity
|
| 172 |
-
triggers = ["who is", "what is", "when did", "where is", "tell me about"]
|
| 173 |
state["is_wiki"] = any(trigger in q for trigger in triggers)
|
| 174 |
print(f"is_wiki: {state['is_wiki']}")
|
| 175 |
return state
|
|
|
|
| 127 |
###################
|
| 128 |
def general_reasoning_qa(state):
|
| 129 |
question = state["question"]
|
| 130 |
+
|
| 131 |
# Step 1: Search Wikipedia broadly
|
| 132 |
search_results = wikipedia.search(question)
|
| 133 |
relevant_pages = search_results[:3] # get top 3 pages
|
| 134 |
+
|
| 135 |
context = ""
|
| 136 |
for title in relevant_pages:
|
| 137 |
try:
|
|
|
|
| 143 |
state["response"] = "Sorry, I couldn’t find enough information."
|
| 144 |
return state
|
| 145 |
|
| 146 |
+
# Step 2: Use the SuperSmartAgent to reason over the context
|
| 147 |
+
agent = SuperSmartAgent()
|
| 148 |
prompt = f"""
|
| 149 |
Based on the following Wikipedia content, answer the question:
|
| 150 |
+
|
| 151 |
Question: {question}
|
| 152 |
+
|
| 153 |
Context:
|
| 154 |
{context}
|
| 155 |
+
|
| 156 |
Answer in a single sentence.
|
| 157 |
"""
|
| 158 |
+
state["response"] = agent(prompt) # Use the SuperSmartAgent to process the prompt
|
| 159 |
+
return state
|
| 160 |
+
|
| 161 |
|
| 162 |
def check_reasoning_needed(state):
|
| 163 |
q = state["question"].lower()
|
|
|
|
| 170 |
def check_wikipedia_suitability(state):
|
| 171 |
q = state["question"].lower()
|
| 172 |
# Simple heuristic: if it's a "who is", "what is", or named entity
|
| 173 |
+
triggers = ["who is", "what is", "when did", "where is", "tell me about", "How many"]
|
| 174 |
state["is_wiki"] = any(trigger in q for trigger in triggers)
|
| 175 |
print(f"is_wiki: {state['is_wiki']}")
|
| 176 |
return state
|