ewaltuch commited on
Commit
500d057
·
verified ·
1 Parent(s): 41b548a

Update app.py

Browse files

added humerous jedi mind trick tool

Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -99,7 +99,31 @@ def execute_bash_command(command: str) -> Tuple[str, str]:
99
  return ("", f"Error: Command timed out after 10 seconds.")
100
  except Exception as e:
101
  return ("", f"An unexpected error occurred: {e}")
 
 
 
 
 
 
 
 
 
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  final_answer = FinalAnswerTool()
104
 
105
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
@@ -121,7 +145,7 @@ with open("prompts.yaml", 'r') as stream:
121
 
122
  agent = CodeAgent(
123
  model=model,
124
- tools=[final_answer, get_current_time_in_timezone, get_os_info, DuckDuckGoSearchTool()], ## add your tools here (don't remove final answer)
125
  max_steps=6,
126
  verbosity_level=1,
127
  grammar=None,
 
99
  return ("", f"Error: Command timed out after 10 seconds.")
100
  except Exception as e:
101
  return ("", f"An unexpected error occurred: {e}")
102
+
103
+ @tool
104
+ def jedi_mind_trick(question: str) -> str:
105
+ # it's import to specify the return type
106
+ """A powerful tool that uses the classic Jedi Mind Trick phrase to dismiss queries about droids.
107
+
108
+ Args:
109
+ question: The user's full question or query, which should be about droids (or C3PO/R2D2).
110
+ """
111
 
112
+ # Convert the question to lowercase for case-insensitive matching
113
+ lower_question = question.lower()
114
+
115
+ # Keywords to trigger the mind trick
116
+ # Uses regex word boundaries (\b) for 'droid' to avoid matching 'android',
117
+ # but allows exact matching for character names.
118
+ droid_keywords = re.compile(r'\b(droid|droids)\b|c3po|r2d2')
119
+
120
+ if droid_keywords.search(lower_question):
121
+ # The trick works!
122
+ return "These aren't the droids you are looking for"
123
+ else:
124
+ # For non-droid questions, return a neutral response
125
+ return "You don't need to use the Force for this query."
126
+
127
  final_answer = FinalAnswerTool()
128
 
129
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
 
145
 
146
  agent = CodeAgent(
147
  model=model,
148
+ tools=[final_answer, get_current_time_in_timezone, get_os_info, jedi_mind_trick, DuckDuckGoSearchTool()], ## add your tools here (don't remove final answer)
149
  max_steps=6,
150
  verbosity_level=1,
151
  grammar=None,