selim-ba commited on
Commit
fa8cd6d
·
verified ·
1 Parent(s): 2df0e9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -16
app.py CHANGED
@@ -20,28 +20,29 @@ class AgentState(TypedDict):
20
 
21
  class SuperSmartAgent:
22
  def __init__(self):
23
- self.graph = self._build_graph() # Build graph after initializing wiki_wiki
24
 
25
  def _build_graph(self):
26
  # Define the graph
27
  workflow = StateGraph(AgentState)
28
-
29
- # Only keep relevant nodes
30
  workflow.add_node("check_reversed", self.check_reversed)
31
  workflow.add_node("fix_question", self.fix_question)
32
-
33
- # Entry point
 
34
  workflow.set_entry_point("check_reversed")
35
-
36
- # Transitions
37
  workflow.add_conditional_edges(
38
  "check_reversed",
39
- lambda state: "fix_question" if state["is_reversed"] else END,
40
  )
41
- workflow.add_edge("fix_question", END)
42
-
43
- return workflow.compile()
44
 
 
45
 
46
  def __call__(self, question: str) -> str:
47
  """
@@ -51,11 +52,7 @@ class SuperSmartAgent:
51
  initial_state = AgentState(
52
  question=question,
53
  response="",
54
- is_reversed=False,
55
- is_riddle=False,
56
- is_python=False,
57
- needs_reasoning=False,
58
- is_wiki=False
59
  )
60
  final_state = self.graph.invoke(initial_state)
61
  return final_state["response"]
@@ -86,6 +83,29 @@ class SuperSmartAgent:
86
  state["question"] = state["question"][::-1]
87
  return state
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
 
91
  def run_and_submit_all( profile: gr.OAuthProfile | None):
 
20
 
21
  class SuperSmartAgent:
22
  def __init__(self):
23
+ self.graph = self._build_graph()
24
 
25
  def _build_graph(self):
26
  # Define the graph
27
  workflow = StateGraph(AgentState)
28
+
29
+ # Add nodes
30
  workflow.add_node("check_reversed", self.check_reversed)
31
  workflow.add_node("fix_question", self.fix_question)
32
+ workflow.add_node("generate_response", self.generate_response) # New node for response generation
33
+
34
+ # Set entry point
35
  workflow.set_entry_point("check_reversed")
36
+
37
+ # Add edges
38
  workflow.add_conditional_edges(
39
  "check_reversed",
40
+ lambda state: "fix_question" if state["is_reversed"] else "generate_response",
41
  )
42
+ workflow.add_edge("fix_question", "generate_response")
43
+ workflow.add_edge("generate_response", END)
 
44
 
45
+ return workflow.compile()
46
 
47
  def __call__(self, question: str) -> str:
48
  """
 
52
  initial_state = AgentState(
53
  question=question,
54
  response="",
55
+ is_reversed=False
 
 
 
 
56
  )
57
  final_state = self.graph.invoke(initial_state)
58
  return final_state["response"]
 
83
  state["question"] = state["question"][::-1]
84
  return state
85
 
86
+ def generate_response(self, state):
87
+ """
88
+ Generate a response to the question.
89
+ This is a simplified version that just echoes the question for demonstration.
90
+ """
91
+ question = state["question"]
92
+
93
+ # Simple response generation logic
94
+ if not question.strip():
95
+ state["response"] = "No question detected."
96
+ else:
97
+ # For reversed questions, we've already fixed them, so now we can answer
98
+ if "what is" in question.lower():
99
+ state["response"] = "This is a generic answer to a 'what is' question."
100
+ elif "how to" in question.lower():
101
+ state["response"] = "This is a generic answer to a 'how to' question."
102
+ elif "?" in question: # Simple check if it's a question
103
+ state["response"] = f"I understand you're asking: '{question}'. Here's a generic response."
104
+ else:
105
+ state["response"] = f"I've processed your statement: '{question}'. Here's a generic acknowledgment."
106
+
107
+ return state
108
+
109
 
110
 
111
  def run_and_submit_all( profile: gr.OAuthProfile | None):