RozzaCreat commited on
Commit
01cd7f4
·
verified ·
1 Parent(s): 3e80b94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +177 -55
app.py CHANGED
@@ -1,4 +1,7 @@
1
- from smolagents import CodeAgent, HfApiModel, tool
 
 
 
2
  import yaml
3
  import math
4
  from tools.final_answer import FinalAnswerTool
@@ -172,52 +175,101 @@ def udp_advisor(development_phase: str, team_size: int, project_complexity: str)
172
 
173
  return response
174
 
175
- # Setup agent
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  final_answer = FinalAnswerTool()
 
177
 
 
178
  model = HfApiModel(
179
  max_tokens=2096,
180
  temperature=0.5,
181
  model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
182
  )
183
 
184
- # Configure templates for the UDP advisor
185
- udp_prompt_templates = {
186
- "react-system": """You are a UDP (Unified Development Platform) advisor who helps users choose appropriate tools for their software development projects.
187
- You have access to the following tools:
188
-
189
- {tools_string}
190
-
191
- You should help the user determine which UDP tools are best for their project based on:
192
- 1. The current development phase they are in (planning, development, testing, deployment, monitoring)
193
- 2. The size of their development team
194
- 3. The complexity of their project (low, medium, high)
195
-
196
- Use the udp_advisor tool to analyze these factors and provide tool recommendations.
197
-
198
- To use a tool, output an action in this format:
199
- ```py
200
- action = tool_name(arg1=value1, arg2=value2, ...)
201
- ```
202
-
203
- Always use Python syntax for calling tools. After using a tool, analyze the result to determine what to do next. Use final_answer to return your final answer.
204
- """,
205
- "react-human": "{input_string}",
206
- "react-assistant": "{agent_response}",
207
- "final_answer": {
208
- "pre_messages": "I'll provide you with UDP tool recommendations based on your project details.",
209
- "template": "Final Answer: {answer}"
210
- }
211
- }
212
-
213
- # Load prompt templates from file or use our templates
214
  try:
215
  with open("prompts.yaml", 'r') as stream:
216
  prompt_templates = yaml.safe_load(stream)
217
  except:
 
218
  prompt_templates = {}
219
 
220
- # Add our templates
221
  prompt_templates["react-system"] = """You are a UDP (Unified Development Platform) advisor who helps users choose appropriate tools for their software development projects.
222
  You have access to the following tools:
223
 
@@ -228,7 +280,7 @@ You should help the user determine which UDP tools are best for their project ba
228
  2. The size of their development team
229
  3. The complexity of their project (low, medium, high)
230
 
231
- Use the udp_advisor tool to analyze these factors and provide tool recommendations.
232
 
233
  To use a tool, output an action in this format:
234
  ```py
@@ -241,14 +293,15 @@ prompt_templates["react-human"] = "{input_string}"
241
  prompt_templates["react-assistant"] = "{agent_response}"
242
  prompt_templates["final_answer"] = {
243
  "pre_messages": "I'll provide you with UDP tool recommendations based on your project details.",
244
- "template": "Final Answer: {answer}"
 
245
  }
246
 
247
- # Create the agent
248
  agent = CodeAgent(
249
  model=model,
250
- tools=[final_answer, udp_advisor],
251
- max_steps=3,
252
  verbosity_level=1,
253
  prompt_templates=prompt_templates
254
  )
@@ -260,34 +313,103 @@ class UDPAdvisorUI(GradioUI):
260
 
261
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
262
  gr.Markdown("# UDP Advisor for Software Development")
263
- gr.Markdown("Get personalized UDP tool recommendations based on your project profile")
264
 
265
  with gr.Row():
266
  with gr.Column():
267
- phase_input = gr.Radio(["Planning", "Development", "Testing", "Deployment", "Monitoring"], label="Development Phase")
268
- team_input = gr.Number(label="Team Size", minimum=1)
269
- complexity_input = gr.Radio(["Low", "Medium", "High"], label="Project Complexity")
270
- submit_btn = gr.Button("Get Recommendations", variant="primary")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
 
272
  with gr.Row():
273
  with gr.Column():
274
- recommendation_output = gr.Markdown(label="UDP Recommendations")
275
 
276
- def get_recommendations(phase, team_size, complexity):
277
- if not phase:
278
- return "Please select a development phase."
279
- if not team_size or team_size < 1:
280
- return "Please provide a valid team size (at least 1)."
281
- if not complexity:
282
- return "Please select a project complexity level."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
 
 
284
  try:
285
- recommendations = udp_advisor(phase.lower(), int(team_size), complexity.lower())
286
- return recommendations
287
  except Exception as e:
288
- return f"Error generating recommendations: {str(e)}"
289
 
290
- submit_btn.click(get_recommendations, inputs=[phase_input, team_input, complexity_input], outputs=recommendation_output)
 
 
 
 
291
 
292
  demo.launch(**kwargs)
293
 
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
+ import datetime
3
+ import requests
4
+ import pytz
5
  import yaml
6
  import math
7
  from tools.final_answer import FinalAnswerTool
 
175
 
176
  return response
177
 
178
+ @tool
179
+ def get_current_time_in_timezone(timezone: str) -> str:
180
+ """A tool that fetches the current local time in a specified timezone.
181
+
182
+ Args:
183
+ timezone: A string representing a valid timezone (e.g., 'America/New_York').
184
+ """
185
+ try:
186
+ # Create timezone object
187
+ tz = pytz.timezone(timezone)
188
+ # Get current time in that timezone
189
+ local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
190
+ return f"The current local time in {timezone} is: {local_time}"
191
+ except Exception as e:
192
+ return f"Error fetching time for timezone '{timezone}': {str(e)}"
193
+
194
+ @tool
195
+ def search_udp_tool_reviews(tool_name: str) -> str:
196
+ """Searches for information and reviews about a specific UDP tool.
197
+
198
+ Args:
199
+ tool_name: The name of the tool to search for (e.g., 'Kubernetes', 'Jira')
200
+ """
201
+ try:
202
+ # This is a placeholder - in a real application, you would implement
203
+ # actual search functionality here using DuckDuckGoSearchTool
204
+
205
+ common_tools = {
206
+ "github": "GitHub is widely regarded as one of the most popular version control and collaboration platforms. " +
207
+ "Recent reviews praise its improved Actions feature for CI/CD pipelines, but note that complex " +
208
+ "permissions management can be challenging for larger teams.",
209
+
210
+ "gitlab": "GitLab receives positive reviews for its all-in-one DevOps platform approach. Users appreciate " +
211
+ "the integrated CI/CD capabilities and built-in security scanning. Some reviews mention that the " +
212
+ "interface can be overwhelming for beginners.",
213
+
214
+ "kubernetes": "Kubernetes continues to be the leading container orchestration platform. Reviews highlight " +
215
+ "its robust ecosystem and flexibility, though many note a steep learning curve. Enterprise " +
216
+ "users praise its scalability while smaller teams sometimes find it overly complex.",
217
+
218
+ "jenkins": "Jenkins remains a popular CI/CD tool with a large plugin ecosystem. Recent reviews mention " +
219
+ "that while it's highly customizable, maintaining Jenkins installations can become complex over time. " +
220
+ "Many organizations are considering cloud-native alternatives.",
221
+
222
+ "terraform": "Terraform is widely praised for its infrastructure-as-code capabilities across multiple cloud providers. " +
223
+ "Recent reviews highlight improved state management features, though some users note challenges with " +
224
+ "complex dependency management in large infrastructures.",
225
+
226
+ "jira": "Jira continues to be a leading project management tool for agile teams. Reviews appreciate its " +
227
+ "customization options but sometimes criticize its complexity and learning curve. Recent updates " +
228
+ "to the interface have received mixed feedback.",
229
+
230
+ "docker": "Docker remains essential for containerization. Recent reviews praise its compatibility improvements " +
231
+ "and simplified developer experience. Some enterprise users mention challenges with orchestration " +
232
+ "at scale, often leading them to Kubernetes.",
233
+
234
+ "azure devops": "Azure DevOps receives positive reviews for its integrated toolchain and strong integration " +
235
+ "with Microsoft products. Users appreciate its CI/CD capabilities and built-in test management. " +
236
+ "Some reviews mention that non-Microsoft workloads might require additional configuration."
237
+ }
238
+
239
+ # Normalize the tool name for lookup
240
+ normalized_tool = tool_name.lower()
241
+
242
+ if normalized_tool in common_tools:
243
+ return f"### Recent Reviews for {tool_name}\n\n{common_tools[normalized_tool]}\n\n" + \
244
+ "This information is based on aggregated recent reviews and industry analysis."
245
+ else:
246
+ return f"No specific review information available for '{tool_name}'. " + \
247
+ "This tool may be less commonly used or recently introduced to the market. " + \
248
+ "Consider searching for specific features you need rather than tool names."
249
+
250
+ except Exception as e:
251
+ return f"Error searching for information about '{tool_name}': {str(e)}"
252
+
253
+ # Setup required tools
254
  final_answer = FinalAnswerTool()
255
+ search_tool = DuckDuckGoSearchTool()
256
 
257
+ # Setup language model
258
  model = HfApiModel(
259
  max_tokens=2096,
260
  temperature=0.5,
261
  model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
262
  )
263
 
264
+ # Try to load prompt templates from file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  try:
266
  with open("prompts.yaml", 'r') as stream:
267
  prompt_templates = yaml.safe_load(stream)
268
  except:
269
+ # If loading fails, create default templates
270
  prompt_templates = {}
271
 
272
+ # Add our templates directly to ensure proper structure
273
  prompt_templates["react-system"] = """You are a UDP (Unified Development Platform) advisor who helps users choose appropriate tools for their software development projects.
274
  You have access to the following tools:
275
 
 
280
  2. The size of their development team
281
  3. The complexity of their project (low, medium, high)
282
 
283
+ You can also provide information about specific tools, search for reviews, and check the current time in different timezones to help with global team coordination.
284
 
285
  To use a tool, output an action in this format:
286
  ```py
 
293
  prompt_templates["react-assistant"] = "{agent_response}"
294
  prompt_templates["final_answer"] = {
295
  "pre_messages": "I'll provide you with UDP tool recommendations based on your project details.",
296
+ "template": "Final Answer: {answer}",
297
+ "post_messages": "Is there anything else you'd like to know about these UDP tools or development practices?"
298
  }
299
 
300
+ # Create the agent with all tools
301
  agent = CodeAgent(
302
  model=model,
303
+ tools=[final_answer, udp_advisor, get_current_time_in_timezone, search_udp_tool_reviews, search_tool],
304
+ max_steps=6,
305
  verbosity_level=1,
306
  prompt_templates=prompt_templates
307
  )
 
313
 
314
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
315
  gr.Markdown("# UDP Advisor for Software Development")
316
+ gr.Markdown("Get personalized UDP tool recommendations and development information")
317
 
318
  with gr.Row():
319
  with gr.Column():
320
+ input_type = gr.Radio(
321
+ ["Tool Recommendations", "Tool Reviews", "Timezone Check", "Free-form Question"],
322
+ label="What would you like help with?",
323
+ value="Tool Recommendations"
324
+ )
325
+
326
+ # Tool recommendation inputs
327
+ with gr.Group(visible=True) as recommendation_group:
328
+ phase_input = gr.Radio(
329
+ ["Planning", "Development", "Testing", "Deployment", "Monitoring"],
330
+ label="Development Phase"
331
+ )
332
+ team_input = gr.Number(label="Team Size", minimum=1, value=5)
333
+ complexity_input = gr.Radio(
334
+ ["Low", "Medium", "High"],
335
+ label="Project Complexity"
336
+ )
337
+
338
+ # Tool review input
339
+ with gr.Group(visible=False) as review_group:
340
+ tool_name_input = gr.Textbox(label="Tool Name", placeholder="Enter a tool name (e.g., Kubernetes, GitLab)")
341
+
342
+ # Timezone input
343
+ with gr.Group(visible=False) as timezone_group:
344
+ timezone_input = gr.Textbox(label="Timezone", placeholder="Enter a timezone (e.g., America/New_York, Europe/London)")
345
+
346
+ # Free-form question input
347
+ with gr.Group(visible=False) as freeform_group:
348
+ question_input = gr.Textbox(label="Your Question", placeholder="Ask anything about development tools or practices")
349
+
350
+ submit_btn = gr.Button("Submit", variant="primary")
351
 
352
  with gr.Row():
353
  with gr.Column():
354
+ output = gr.Markdown(label="Response")
355
 
356
+ # Logic to show/hide input groups based on selection
357
+ def update_visibility(choice):
358
+ return {
359
+ recommendation_group: choice == "Tool Recommendations",
360
+ review_group: choice == "Tool Reviews",
361
+ timezone_group: choice == "Timezone Check",
362
+ freeform_group: choice == "Free-form Question"
363
+ }
364
+
365
+ input_type.change(
366
+ update_visibility,
367
+ inputs=[input_type],
368
+ outputs=[recommendation_group, review_group, timezone_group, freeform_group]
369
+ )
370
+
371
+ # Process input based on type
372
+ def process_input(input_type, phase, team_size, complexity, tool_name, timezone, question):
373
+ if input_type == "Tool Recommendations":
374
+ if not phase:
375
+ return "Please select a development phase."
376
+ if not team_size or team_size < 1:
377
+ return "Please provide a valid team size (at least 1)."
378
+ if not complexity:
379
+ return "Please select a project complexity level."
380
+
381
+ query = f"I need UDP tool recommendations for a project in the {phase.lower()} phase with a team of {int(team_size)} people and {complexity.lower()} complexity."
382
+
383
+ elif input_type == "Tool Reviews":
384
+ if not tool_name or tool_name.strip() == "":
385
+ return "Please enter a tool name to search for reviews."
386
+
387
+ query = f"What are the reviews and opinions about {tool_name.strip()}?"
388
+
389
+ elif input_type == "Timezone Check":
390
+ if not timezone or timezone.strip() == "":
391
+ return "Please enter a timezone to check."
392
+
393
+ query = f"What is the current time in {timezone.strip()}?"
394
+
395
+ else: # Free-form question
396
+ if not question or question.strip() == "":
397
+ return "Please enter your question."
398
+
399
+ query = question
400
 
401
+ # Process the query using the agent
402
  try:
403
+ response = agent.run(query)
404
+ return response
405
  except Exception as e:
406
+ return f"Error processing request: {str(e)}"
407
 
408
+ submit_btn.click(
409
+ process_input,
410
+ inputs=[input_type, phase_input, team_input, complexity_input, tool_name_input, timezone_input, question_input],
411
+ outputs=output
412
+ )
413
 
414
  demo.launch(**kwargs)
415