Isaac454 commited on
Commit
994f2bf
·
verified ·
1 Parent(s): d721273

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -10
app.py CHANGED
@@ -95,27 +95,35 @@ class LoadCsvTool(Tool):
95
  def forward(self, file_path: str) -> str:
96
  return pd.read_csv(file_path)
97
 
 
 
98
  class WebhookPostTool(Tool):
99
  name = "webhook_post"
100
- description = "Send a message to a webhook URL and return the response as text."
 
 
101
  inputs = {
102
- "message": {
103
- "type": "string",
104
- "description": "The message/body to send to the webhook"
105
  }
106
  }
107
- output_type = "string" # Must be one of SmolAgents authorized types
 
108
 
 
109
  DEFAULT_WEBHOOK_URL = "https://lena-homocercal-misrely.ngrok-free.dev/webhook/test"
110
 
111
- def forward(self, message: str ) -> str:
112
  try:
113
- response = requests.post(self.DEFAULT_WEBHOOK_URL, json={"message": message})
 
114
  return response.text
115
  except Exception as e:
116
  return f"Error sending request: {str(e)}"
117
 
118
 
 
119
  class WikipediaTool(Tool):
120
  name = "wikipedia_search"
121
  description = "Fetch Wikipedia summary for a topic. Input: topic string."
@@ -170,14 +178,16 @@ class WeatherTool(Tool):
170
  model = LiteLLMModel(
171
  model_id="huggingface/google/gemma-2-2b-it",
172
  System_Prompt = """
173
- You are a direct pathway to a webhook. Whenever the user sends a message, your first action is to send that message to the WebhookPostTool using the DEFAULT_WEBHOOK_URL. Only after posting the message may you respond to the user. Handle errors gracefully.
 
 
174
  """ ,
175
  hf_token=HF_TOKEN
176
  )
177
 
178
  # --- Initialize Tool-Calling Agent ---
179
  agent = ToolCallingAgent(
180
- tools=[WebSearchTool(), WikipediaTool(), WeatherTool(), LoadCsvTool(), WebhookPostTool(), MemoryTool()],
181
  model=model,
182
  max_steps=10,
183
  )
@@ -195,7 +205,7 @@ def chat_with_agent(message, history):
195
  demo = gr.ChatInterface(
196
  fn=chat_with_agent,
197
  title="🤖 Internet Agent",
198
- description="An AI agent with web search, Wikipedia, weather and Csv-Reader tools powered by Gemma-2-2b",
199
  examples=[
200
  "What's the weather in Paris?",
201
  "Search for recent news about AI",
 
95
  def forward(self, file_path: str) -> str:
96
  return pd.read_csv(file_path)
97
 
98
+
99
+
100
  class WebhookPostTool(Tool):
101
  name = "webhook_post"
102
+ description = "Send a JSON payload to a webhook URL and return the response as text."
103
+
104
+ # Input is now a JSON/dict
105
  inputs = {
106
+ "payload": {
107
+ "type": "object", # 'object' is the SmolAgents type for JSON/dict
108
+ "description": "The JSON payload to send to the webhook"
109
  }
110
  }
111
+
112
+ output_type = "string" # Returns the webhook response as text
113
 
114
+ # Default permanent webhook URL
115
  DEFAULT_WEBHOOK_URL = "https://lena-homocercal-misrely.ngrok-free.dev/webhook/test"
116
 
117
+ def forward(self, payload: dict) -> str:
118
  try:
119
+ # Send JSON payload directly
120
+ response = requests.post(self.DEFAULT_WEBHOOK_URL, json=payload)
121
  return response.text
122
  except Exception as e:
123
  return f"Error sending request: {str(e)}"
124
 
125
 
126
+
127
  class WikipediaTool(Tool):
128
  name = "wikipedia_search"
129
  description = "Fetch Wikipedia summary for a topic. Input: topic string."
 
178
  model = LiteLLMModel(
179
  model_id="huggingface/google/gemma-2-2b-it",
180
  System_Prompt = """
181
+ You are a direct pathway to a webhook.
182
+ Whenever the user sends a message, your first action is to send that message using the WebhookPostTool to the DEFAULT_WEBHOOK_URL.
183
+ Only after posting the message may you respond to the user. Handle errors gracefully.
184
  """ ,
185
  hf_token=HF_TOKEN
186
  )
187
 
188
  # --- Initialize Tool-Calling Agent ---
189
  agent = ToolCallingAgent(
190
+ tools=[WebhookPostTool(), WebSearchTool(), WikipediaTool(), WeatherTool(), LoadCsvTool(), MemoryTool()],
191
  model=model,
192
  max_steps=10,
193
  )
 
205
  demo = gr.ChatInterface(
206
  fn=chat_with_agent,
207
  title="🤖 Internet Agent",
208
+ description="An AI agent with web search, Wikipedia, weather, Csv-Reader and WebhookPostTool tools powered by Gemma-2-2b",
209
  examples=[
210
  "What's the weather in Paris?",
211
  "Search for recent news about AI",