File size: 22,792 Bytes
01cd7f4
 
 
 
f1cb32a
df9e5de
 
 
58ae99f
 
3e80b94
 
f1cb32a
 
3e80b94
 
 
f1cb32a
 
3e80b94
58ae99f
3e80b94
 
f1cb32a
3e80b94
 
 
f1cb32a
3e80b94
 
f1cb32a
3e80b94
 
 
f1cb32a
3e80b94
 
f1cb32a
3e80b94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1cb32a
3e80b94
f1cb32a
3e80b94
 
65e5ff2
3e80b94
 
 
65e5ff2
3e80b94
 
 
 
df9e5de
f1cb32a
3e80b94
 
 
 
f1cb32a
3e80b94
 
df9e5de
3e80b94
 
 
 
 
 
df9e5de
3e80b94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1cb32a
3e80b94
df9e5de
3e80b94
 
 
f1cb32a
 
 
01cd7f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1cb32a
01cd7f4
f1cb32a
01cd7f4
f1cb32a
df9e5de
 
 
8fe992b
 
01cd7f4
f1cb32a
 
 
 
01cd7f4
3e80b94
 
01cd7f4
3e80b94
 
 
 
 
 
 
 
 
 
01cd7f4
3e80b94
 
 
 
 
 
 
 
 
 
 
 
01cd7f4
 
3e80b94
f1cb32a
01cd7f4
f1cb32a
 
01cd7f4
 
f1cb32a
 
dca5e74
9b5b26a
f1cb32a
3e80b94
df9e5de
 
f1cb32a
df9e5de
3e80b94
01cd7f4
df9e5de
 
 
01cd7f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1cb32a
df9e5de
 
01cd7f4
df9e5de
01cd7f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
df9e5de
01cd7f4
df9e5de
01cd7f4
 
df9e5de
01cd7f4
df9e5de
01cd7f4
 
 
 
 
f1cb32a
df9e5de
f1cb32a
df9e5de
3e80b94
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
import datetime
import requests
import pytz
import yaml
import math
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI

@tool
def udp_advisor(development_phase: str, team_size: int, project_complexity: str) -> str:
    """Provides UDP (Unified Development Platform) recommendations based on development phase, team size, and project complexity.
    
    Args:
        development_phase: Current phase of development (planning, development, testing, deployment, monitoring)
        team_size: Number of team members
        project_complexity: Project complexity level (low, medium, high)
    
    Returns:
        UDP recommendations as formatted text
    """
    if team_size <= 0 or team_size > 1000:
        return "Error: Please provide a valid team size (1-1000)."
    
    # Normalize development phase
    development_phase = development_phase.lower().strip()
    valid_phases = ["planning", "development", "testing", "deployment", "monitoring"]
    
    if development_phase not in valid_phases:
        return "Error: Development phase must be one of: planning, development, testing, deployment, monitoring."
    
    # Normalize complexity
    project_complexity = project_complexity.lower().strip()
    valid_complexity = ["low", "medium", "high"]
    
    if project_complexity not in valid_complexity:
        return "Error: Project complexity must be 'low', 'medium', or 'high'."
    
    # Database of UDP tools by development phase and complexity
    udp_tools = {
        "planning": {
            "low": [
                {"name": "Trello", "category": "Project Management", "complexity": "Low", "min_team_size": 1, "description": "Simple kanban board for task tracking"},
                {"name": "GitHub Projects", "category": "Project Management", "complexity": "Low", "min_team_size": 1, "description": "Basic project management integrated with GitHub"}
            ],
            "medium": [
                {"name": "Jira", "category": "Project Management", "complexity": "Medium", "min_team_size": 5, "description": "Comprehensive agile project management tool"},
                {"name": "Azure DevOps Boards", "category": "Project Management", "complexity": "Medium", "min_team_size": 5, "description": "Project tracking with Azure integration"}
            ],
            "high": [
                {"name": "Monday.com", "category": "Project Management", "complexity": "High", "min_team_size": 10, "description": "Customizable workflow platform for complex projects"},
                {"name": "Rally", "category": "Project Management", "complexity": "High", "min_team_size": 20, "description": "Enterprise-scale agile management and portfolio planning"}
            ]
        },
        "development": {
            "low": [
                {"name": "GitHub", "category": "Version Control", "complexity": "Low", "min_team_size": 1, "description": "Popular code hosting platform with basic CI/CD"},
                {"name": "VS Code", "category": "IDE", "complexity": "Low", "min_team_size": 1, "description": "Lightweight, extensible code editor"}
            ],
            "medium": [
                {"name": "GitLab", "category": "DevOps Platform", "complexity": "Medium", "min_team_size": 5, "description": "Integrated DevOps platform with built-in CI/CD"},
                {"name": "JetBrains IDEs", "category": "IDE", "complexity": "Medium", "min_team_size": 1, "description": "Language-specific professional IDEs"}
            ],
            "high": [
                {"name": "Bitbucket + Bamboo", "category": "Enterprise DevOps", "complexity": "High", "min_team_size": 10, "description": "Atlassian's integrated code and CI/CD solution"},
                {"name": "GitHub Enterprise", "category": "Enterprise DevOps", "complexity": "High", "min_team_size": 20, "description": "Self-hosted, compliant GitHub with advanced security"}
            ]
        },
        "testing": {
            "low": [
                {"name": "Jest", "category": "Testing Framework", "complexity": "Low", "min_team_size": 1, "description": "JavaScript testing framework with minimal configuration"},
                {"name": "GitHub Actions", "category": "CI/CD", "complexity": "Low", "min_team_size": 1, "description": "Simple workflow automation integrated with GitHub"}
            ],
            "medium": [
                {"name": "Jenkins", "category": "CI/CD", "complexity": "Medium", "min_team_size": 3, "description": "Flexible automation server for building, testing, and deployment"},
                {"name": "Selenium", "category": "Testing", "complexity": "Medium", "min_team_size": 2, "description": "Browser automation for web application testing"}
            ],
            "high": [
                {"name": "Azure DevOps Pipelines", "category": "CI/CD", "complexity": "High", "min_team_size": 5, "description": "Enterprise-grade pipelines with extensive integration"},
                {"name": "SonarQube", "category": "Code Quality", "complexity": "High", "min_team_size": 5, "description": "Advanced code quality and security platform"}
            ]
        },
        "deployment": {
            "low": [
                {"name": "Netlify", "category": "Hosting", "complexity": "Low", "min_team_size": 1, "description": "Simple deployment platform for frontend applications"},
                {"name": "Heroku", "category": "PaaS", "complexity": "Low", "min_team_size": 1, "description": "Platform-as-a-Service with simplified deployment"}
            ],
            "medium": [
                {"name": "Docker", "category": "Containerization", "complexity": "Medium", "min_team_size": 2, "description": "Container platform for application packaging"},
                {"name": "AWS Elastic Beanstalk", "category": "PaaS", "complexity": "Medium", "min_team_size": 3, "description": "Easy-to-use service for deploying applications"}
            ],
            "high": [
                {"name": "Kubernetes", "category": "Container Orchestration", "complexity": "High", "min_team_size": 5, "description": "Production-grade container orchestration"},
                {"name": "Terraform", "category": "IaC", "complexity": "High", "min_team_size": 3, "description": "Infrastructure as Code for multi-cloud deployment"}
            ]
        },
        "monitoring": {
            "low": [
                {"name": "Uptime Robot", "category": "Monitoring", "complexity": "Low", "min_team_size": 1, "description": "Simple uptime monitoring for websites"},
                {"name": "Sentry", "category": "Error Tracking", "complexity": "Low", "min_team_size": 1, "description": "Application error monitoring"}
            ],
            "medium": [
                {"name": "Grafana", "category": "Observability", "complexity": "Medium", "min_team_size": 2, "description": "Metrics visualization and dashboards"},
                {"name": "New Relic", "category": "APM", "complexity": "Medium", "min_team_size": 3, "description": "Application performance monitoring"}
            ],
            "high": [
                {"name": "Prometheus", "category": "Monitoring", "complexity": "High", "min_team_size": 3, "description": "Advanced metrics collection and alerting system"},
                {"name": "Datadog", "category": "Observability", "complexity": "High", "min_team_size": 5, "description": "Full-stack observability platform"}
            ]
        }
    }
    
    # Team size categorization
    team_category = "small" if team_size < 10 else "medium" if team_size < 50 else "large"
    
    # Find suitable tools based on team size and complexity
    suitable_tools = []
    tools_for_phase = udp_tools[development_phase][project_complexity]
    
    # Filter tools by team size
    for tool in tools_for_phase:
        if tool["min_team_size"] <= team_size:
            suitable_tools.append(tool)
    
    # Format response
    response = f"## UDP Tool Recommendations\n\n"
    response += f"**Development Phase:** {development_phase.capitalize()}\n"
    response += f"**Team Size:** {team_size} ({team_category} team)\n"
    response += f"**Project Complexity:** {project_complexity.capitalize()}\n\n"
    
    if suitable_tools:
        response += "### Recommended Tools\n\n"
        
        for tool in suitable_tools:
            response += f"**{tool['name']}**\n"
            response += f"- Category: {tool['category']}\n"
            response += f"- Complexity: {tool['complexity']}\n"
            response += f"- Min Team Size: {tool['min_team_size']}\n"
            response += f"- Description: {tool['description']}\n\n"
    else:
        response += "Unfortunately, we cannot provide specific tool recommendations for your team size and complexity requirements. Consider reviewing tools for a different complexity level or adjusting your team size.\n\n"
    
    # Additional phase-specific advice
    if development_phase == "planning":
        response += "### Planning Phase Tips\n"
        response += "- Document your requirements clearly\n"
        response += "- Set up communication channels\n"
        response += "- Define team roles and responsibilities\n"
    elif development_phase == "development":
        response += "### Development Phase Tips\n"
        response += "- Implement branch protection rules\n"
        response += "- Use consistent code formatting\n"
        response += "- Schedule regular code reviews\n"
    elif development_phase == "testing":
        response += "### Testing Phase Tips\n"
        response += "- Automate unit and integration tests\n"
        response += "- Establish QA processes\n"
        response += "- Document test cases and expected outcomes\n"
    elif development_phase == "deployment":
        response += "### Deployment Phase Tips\n"
        response += "- Use environment-specific configurations\n"
        response += "- Implement rollback strategies\n"
        response += "- Document deployment procedures\n"
    elif development_phase == "monitoring":
        response += "### Monitoring Phase Tips\n"
        response += "- Set up alerts for critical metrics\n"
        response += "- Establish incident response processes\n"
        response += "- Regularly review logs and performance data\n"
    
    response += "\n### Important Information\n"
    response += "- These are general recommendations based on the information provided.\n"
    response += "- Before adopting tools, assess your team's specific needs and skills.\n"
    response += "- Consider integration capabilities with your existing toolchain.\n"
    response += "- Training requirements should be factored into tool adoption decisions.\n"
    
    return response

@tool
def get_current_time_in_timezone(timezone: str) -> str:
    """A tool that fetches the current local time in a specified timezone.
    
    Args:
        timezone: A string representing a valid timezone (e.g., 'America/New_York').
    """
    try:
        # Create timezone object
        tz = pytz.timezone(timezone)
        # Get current time in that timezone
        local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
        return f"The current local time in {timezone} is: {local_time}"
    except Exception as e:
        return f"Error fetching time for timezone '{timezone}': {str(e)}"

@tool
def search_udp_tool_reviews(tool_name: str) -> str:
    """Searches for information and reviews about a specific UDP tool.
    
    Args:
        tool_name: The name of the tool to search for (e.g., 'Kubernetes', 'Jira')
    """
    try:
        # This is a placeholder - in a real application, you would implement 
        # actual search functionality here using DuckDuckGoSearchTool
        
        common_tools = {
            "github": "GitHub is widely regarded as one of the most popular version control and collaboration platforms. " +
                      "Recent reviews praise its improved Actions feature for CI/CD pipelines, but note that complex " +
                      "permissions management can be challenging for larger teams.",
            
            "gitlab": "GitLab receives positive reviews for its all-in-one DevOps platform approach. Users appreciate " +
                     "the integrated CI/CD capabilities and built-in security scanning. Some reviews mention that the " +
                     "interface can be overwhelming for beginners.",
            
            "kubernetes": "Kubernetes continues to be the leading container orchestration platform. Reviews highlight " +
                         "its robust ecosystem and flexibility, though many note a steep learning curve. Enterprise " +
                         "users praise its scalability while smaller teams sometimes find it overly complex.",
            
            "jenkins": "Jenkins remains a popular CI/CD tool with a large plugin ecosystem. Recent reviews mention " +
                      "that while it's highly customizable, maintaining Jenkins installations can become complex over time. " +
                      "Many organizations are considering cloud-native alternatives.",
            
            "terraform": "Terraform is widely praised for its infrastructure-as-code capabilities across multiple cloud providers. " +
                        "Recent reviews highlight improved state management features, though some users note challenges with " +
                        "complex dependency management in large infrastructures.",
            
            "jira": "Jira continues to be a leading project management tool for agile teams. Reviews appreciate its " +
                   "customization options but sometimes criticize its complexity and learning curve. Recent updates " +
                   "to the interface have received mixed feedback.",
            
            "docker": "Docker remains essential for containerization. Recent reviews praise its compatibility improvements " +
                     "and simplified developer experience. Some enterprise users mention challenges with orchestration " +
                     "at scale, often leading them to Kubernetes.",
            
            "azure devops": "Azure DevOps receives positive reviews for its integrated toolchain and strong integration " +
                           "with Microsoft products. Users appreciate its CI/CD capabilities and built-in test management. " +
                           "Some reviews mention that non-Microsoft workloads might require additional configuration."
        }
        
        # Normalize the tool name for lookup
        normalized_tool = tool_name.lower()
        
        if normalized_tool in common_tools:
            return f"### Recent Reviews for {tool_name}\n\n{common_tools[normalized_tool]}\n\n" + \
                   "This information is based on aggregated recent reviews and industry analysis."
        else:
            return f"No specific review information available for '{tool_name}'. " + \
                   "This tool may be less commonly used or recently introduced to the market. " + \
                   "Consider searching for specific features you need rather than tool names."
            
    except Exception as e:
        return f"Error searching for information about '{tool_name}': {str(e)}"

# Setup required tools
final_answer = FinalAnswerTool()
search_tool = DuckDuckGoSearchTool()

# Setup language model
model = HfApiModel(
    max_tokens=2096,
    temperature=0.5,
    model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
)

# Try to load prompt templates from file
try:
    with open("prompts.yaml", 'r') as stream:
        prompt_templates = yaml.safe_load(stream)
except:
    # If loading fails, create default templates
    prompt_templates = {}

# Add our templates directly to ensure proper structure
prompt_templates["react-system"] = """You are a UDP (Unified Development Platform) advisor who helps users choose appropriate tools for their software development projects.
You have access to the following tools:

{tools_string}

You should help the user determine which UDP tools are best for their project based on:
1. The current development phase they are in (planning, development, testing, deployment, monitoring)
2. The size of their development team
3. The complexity of their project (low, medium, high)

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.

To use a tool, output an action in this format:
```py
action = tool_name(arg1=value1, arg2=value2, ...)
```

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.
"""
prompt_templates["react-human"] = "{input_string}"
prompt_templates["react-assistant"] = "{agent_response}"
prompt_templates["final_answer"] = {
    "pre_messages": "I'll provide you with UDP tool recommendations based on your project details.",
    "template": "Final Answer: {answer}",
    "post_messages": "Is there anything else you'd like to know about these UDP tools or development practices?"
}

# Create the agent with all tools
agent = CodeAgent(
    model=model,
    tools=[final_answer, udp_advisor, get_current_time_in_timezone, search_udp_tool_reviews, search_tool],
    max_steps=6,
    verbosity_level=1,
    prompt_templates=prompt_templates
)

# Create a custom Gradio UI
class UDPAdvisorUI(GradioUI):
    def launch(self, **kwargs):
        import gradio as gr
        
        with gr.Blocks(theme=gr.themes.Soft()) as demo:
            gr.Markdown("# UDP Advisor for Software Development")
            gr.Markdown("Get personalized UDP tool recommendations and development information")
            
            with gr.Row():
                with gr.Column():
                    input_type = gr.Radio(
                        ["Tool Recommendations", "Tool Reviews", "Timezone Check", "Free-form Question"], 
                        label="What would you like help with?",
                        value="Tool Recommendations"
                    )
                    
                    # Tool recommendation inputs
                    with gr.Group(visible=True) as recommendation_group:
                        phase_input = gr.Radio(
                            ["Planning", "Development", "Testing", "Deployment", "Monitoring"], 
                            label="Development Phase"
                        )
                        team_input = gr.Number(label="Team Size", minimum=1, value=5)
                        complexity_input = gr.Radio(
                            ["Low", "Medium", "High"], 
                            label="Project Complexity"
                        )
                    
                    # Tool review input
                    with gr.Group(visible=False) as review_group:
                        tool_name_input = gr.Textbox(label="Tool Name", placeholder="Enter a tool name (e.g., Kubernetes, GitLab)")
                    
                    # Timezone input
                    with gr.Group(visible=False) as timezone_group:
                        timezone_input = gr.Textbox(label="Timezone", placeholder="Enter a timezone (e.g., America/New_York, Europe/London)")
                    
                    # Free-form question input
                    with gr.Group(visible=False) as freeform_group:
                        question_input = gr.Textbox(label="Your Question", placeholder="Ask anything about development tools or practices")
                    
                    submit_btn = gr.Button("Submit", variant="primary")
            
            with gr.Row():
                with gr.Column():
                    output = gr.Markdown(label="Response")
            
            # Logic to show/hide input groups based on selection
            def update_visibility(choice):
                return {
                    recommendation_group: choice == "Tool Recommendations",
                    review_group: choice == "Tool Reviews",
                    timezone_group: choice == "Timezone Check",
                    freeform_group: choice == "Free-form Question"
                }
            
            input_type.change(
                update_visibility,
                inputs=[input_type],
                outputs=[recommendation_group, review_group, timezone_group, freeform_group]
            )
            
            # Process input based on type
            def process_input(input_type, phase, team_size, complexity, tool_name, timezone, question):
                if input_type == "Tool Recommendations":
                    if not phase:
                        return "Please select a development phase."
                    if not team_size or team_size < 1:
                        return "Please provide a valid team size (at least 1)."
                    if not complexity:
                        return "Please select a project complexity level."
                    
                    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."
                
                elif input_type == "Tool Reviews":
                    if not tool_name or tool_name.strip() == "":
                        return "Please enter a tool name to search for reviews."
                    
                    query = f"What are the reviews and opinions about {tool_name.strip()}?"
                
                elif input_type == "Timezone Check":
                    if not timezone or timezone.strip() == "":
                        return "Please enter a timezone to check."
                    
                    query = f"What is the current time in {timezone.strip()}?"
                
                else:  # Free-form question
                    if not question or question.strip() == "":
                        return "Please enter your question."
                    
                    query = question
                
                # Process the query using the agent
                try:
                    response = agent.run(query)
                    return response
                except Exception as e:
                    return f"Error processing request: {str(e)}"
            
            submit_btn.click(
                process_input, 
                inputs=[input_type, phase_input, team_input, complexity_input, tool_name_input, timezone_input, question_input], 
                outputs=output
            )
        
        demo.launch(**kwargs)

# Launch the interface
UDPAdvisorUI(agent).launch()