Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -69,13 +69,17 @@ class MathRetrievalQA(dspy.Program):
|
|
69 |
print("Generating answer...")
|
70 |
answer = qa_pipeline(prompt, max_new_tokens=100)[0]["generated_text"]
|
71 |
print("Generated answer:", answer)
|
72 |
-
return
|
|
|
|
|
73 |
|
74 |
class WebFallbackQA(dspy.Program):
|
75 |
def forward(self, question):
|
76 |
print("Fallback to Tavily...")
|
77 |
answer = web_search_tavily(question)
|
78 |
-
|
|
|
|
|
79 |
|
80 |
class MathRouter(dspy.Program):
|
81 |
def forward(self, question):
|
@@ -83,8 +87,8 @@ class MathRouter(dspy.Program):
|
|
83 |
if not is_valid_math_question(question):
|
84 |
return dspy.Output(answer="❌ Only math questions are accepted. Please rephrase.", retrieved_context="")
|
85 |
result = MathRetrievalQA().forward(question)
|
86 |
-
return result if result.answer else WebFallbackQA().forward(question)
|
87 |
-
|
88 |
router = MathRouter()
|
89 |
|
90 |
# === Feedback Storage ===
|
@@ -105,7 +109,9 @@ def ask_question(question):
|
|
105 |
print("ask_question() called with:", question)
|
106 |
result = router.forward(question)
|
107 |
print("Result:", result)
|
108 |
-
return result.answer, question, result.answer
|
|
|
|
|
109 |
|
110 |
def submit_feedback(question, model_answer, feedback, correct_answer):
|
111 |
store_feedback(question, model_answer, feedback, correct_answer)
|
|
|
69 |
print("Generating answer...")
|
70 |
answer = qa_pipeline(prompt, max_new_tokens=100)[0]["generated_text"]
|
71 |
print("Generated answer:", answer)
|
72 |
+
return {"answer": answer, "retrieved_context": context}
|
73 |
+
|
74 |
+
# return dspy.Output(answer=answer, retrieved_context=context)
|
75 |
|
76 |
class WebFallbackQA(dspy.Program):
|
77 |
def forward(self, question):
|
78 |
print("Fallback to Tavily...")
|
79 |
answer = web_search_tavily(question)
|
80 |
+
# return dspy.Output(answer=answer, retrieved_context="Tavily")
|
81 |
+
return {"answer": answer, "retrieved_context": "Tavily"}
|
82 |
+
|
83 |
|
84 |
class MathRouter(dspy.Program):
|
85 |
def forward(self, question):
|
|
|
87 |
if not is_valid_math_question(question):
|
88 |
return dspy.Output(answer="❌ Only math questions are accepted. Please rephrase.", retrieved_context="")
|
89 |
result = MathRetrievalQA().forward(question)
|
90 |
+
#return result if result.answer else WebFallbackQA().forward(question)
|
91 |
+
return result if result["answer"] else WebFallbackQA().forward(question)
|
92 |
router = MathRouter()
|
93 |
|
94 |
# === Feedback Storage ===
|
|
|
109 |
print("ask_question() called with:", question)
|
110 |
result = router.forward(question)
|
111 |
print("Result:", result)
|
112 |
+
#return result.answer, question, result.answer
|
113 |
+
return result["answer"], question, result["answer"]
|
114 |
+
|
115 |
|
116 |
def submit_feedback(question, model_answer, feedback, correct_answer):
|
117 |
store_feedback(question, model_answer, feedback, correct_answer)
|