Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -48,6 +48,29 @@ class SuperSmartAgent:
|
|
| 48 |
print(f"Reversing question: {state['question']}")
|
| 49 |
state["question"] = state["question"][::-1]
|
| 50 |
return state
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
def check_python_suitability(state):
|
| 53 |
question = state["question"].lower()
|
|
@@ -85,14 +108,25 @@ class SuperSmartAgent:
|
|
| 85 |
# Nodes
|
| 86 |
builder.add_node("check_reversed", check_reversed)
|
| 87 |
builder.add_node("fix_question", fix_question)
|
|
|
|
|
|
|
| 88 |
builder.add_node("check_python_suitability", check_python_suitability)
|
| 89 |
builder.add_node("generate_code", generate_code)
|
| 90 |
builder.add_node("fallback", fallback)
|
|
|
|
| 91 |
|
| 92 |
# Edges
|
| 93 |
builder.set_entry_point("check_reversed")
|
| 94 |
builder.add_edge("check_reversed", "fix_question")
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
builder.add_conditional_edges(
|
| 97 |
"check_python_suitability",
|
| 98 |
lambda s: "generate_code" if s["is_python"] else "fallback"
|
|
|
|
| 48 |
print(f"Reversing question: {state['question']}")
|
| 49 |
state["question"] = state["question"][::-1]
|
| 50 |
return state
|
| 51 |
+
|
| 52 |
+
def check_riddle_or_trick(state):
|
| 53 |
+
q = state["question"].lower()
|
| 54 |
+
if "opposite of the word" in q:
|
| 55 |
+
state["is_riddle"] = True
|
| 56 |
+
else:
|
| 57 |
+
state["is_riddle"] = False
|
| 58 |
+
return state
|
| 59 |
+
|
| 60 |
+
def solve_riddle(state):
|
| 61 |
+
q = state["question"].lower()
|
| 62 |
+
if "opposite of the word" in q:
|
| 63 |
+
if "left" in q:
|
| 64 |
+
state["response"] = "right"
|
| 65 |
+
elif "up" in q:
|
| 66 |
+
state["response"] = "down"
|
| 67 |
+
elif "hot" in q:
|
| 68 |
+
state["response"] = "cold"
|
| 69 |
+
else:
|
| 70 |
+
state["response"] = "Unknown opposite."
|
| 71 |
+
else:
|
| 72 |
+
state["response"] = "Could not solve riddle."
|
| 73 |
+
return state
|
| 74 |
|
| 75 |
def check_python_suitability(state):
|
| 76 |
question = state["question"].lower()
|
|
|
|
| 108 |
# Nodes
|
| 109 |
builder.add_node("check_reversed", check_reversed)
|
| 110 |
builder.add_node("fix_question", fix_question)
|
| 111 |
+
builder.add_node("check_riddle_or_trick", check_riddle_or_trick)
|
| 112 |
+
builder.add_node("solve_riddle", solve_riddle)
|
| 113 |
builder.add_node("check_python_suitability", check_python_suitability)
|
| 114 |
builder.add_node("generate_code", generate_code)
|
| 115 |
builder.add_node("fallback", fallback)
|
| 116 |
+
|
| 117 |
|
| 118 |
# Edges
|
| 119 |
builder.set_entry_point("check_reversed")
|
| 120 |
builder.add_edge("check_reversed", "fix_question")
|
| 121 |
+
|
| 122 |
+
builder.add_edge("fix_question", "check_riddle_or_trick")
|
| 123 |
+
builder.add_conditional_edges(
|
| 124 |
+
"check_riddle_or_trick",
|
| 125 |
+
lambda s: "solve_riddle" if s["is_riddle"] else "check_python_suitability"
|
| 126 |
+
)
|
| 127 |
+
builder.add_edge("solve_riddle", END)
|
| 128 |
+
|
| 129 |
+
builder.add_node("check_python_suitability", check_python_suitability)
|
| 130 |
builder.add_conditional_edges(
|
| 131 |
"check_python_suitability",
|
| 132 |
lambda s: "generate_code" if s["is_python"] else "fallback"
|