-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.py
More file actions
210 lines (177 loc) · 7.47 KB
/
Copy pathbackend.py
File metadata and controls
210 lines (177 loc) · 7.47 KB
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
from typing import List, Dict
import autogen
from openai import OpenAI
from datetime import datetime
import json
import asyncio
class ProjectManager:
def __init__(self, groq_api_key: str):
# Configure OpenAI client with Groq base URL
self.client = OpenAI(
api_key=groq_api_key,
base_url="https://api.groq.com/openai/v1"
)
# Configure Autogen to use Groq
self.llm_config = {
"timeout": 60,
"cache_seed": 42,
"config_list": [
{
"model": "llama-3.3-70b-versatile",
"api_key": groq_api_key,
"base_url": "https://api.groq.com/openai/v1",
}
],
"temperature": 0.7,
}
# Create agents
self.user_proxy = autogen.UserProxyAgent(
name="user_proxy",
system_message="I am a user proxy agent that handles interaction with the human user.",
human_input_mode="TERMINATE",
code_execution_config={"work_dir": "coding"},
)
self.researcher = autogen.AssistantAgent(
name="researcher",
system_message="""I am a research agent that:
1. Analyzes project requirements thoroughly
2. Researches best practices, technologies, and solutions
3. Provides comprehensive research reports
4. Makes data-driven recommendations""",
llm_config=self.llm_config,
)
self.architect = autogen.AssistantAgent(
name="architect",
system_message="""I am a solution architect that:
1. Designs system architecture based on research findings
2. Evaluates and selects appropriate technologies
3. Creates detailed technical specifications
4. Ensures scalability, maintainability, and best practices""",
llm_config=self.llm_config,
)
self.developer = autogen.AssistantAgent(
name="developer",
system_message="""I am a developer that:
1. Implements solutions based on architectural specifications
2. Writes clean, efficient, and well-documented code
3. Follows coding standards and best practices
4. Implements proper error handling and logging""",
llm_config=self.llm_config,
)
self.tester = autogen.AssistantAgent(
name="tester",
system_message="""I am a QA engineer that:
1. Creates comprehensive test plans
2. Performs unit, integration, and system testing
3. Conducts thorough bug reporting and tracking
4. Ensures code quality and performance standards""",
llm_config=self.llm_config,
)
async def get_groq_response(self, query: str) -> str:
"""Get enhanced response from Groq API"""
try:
completion = self.client.chat.completions.create(
model="mixtral-8x7b-32768",
messages=[{"role": "user", "content": query}],
temperature=0.7,
max_tokens=4096
)
return completion.choices[0].message.content
except Exception as e:
print(f"Error getting Groq response: {str(e)}")
return "Error in getting response from Groq"
async def enhance_with_groq(self, agent_message: str, context: str) -> str:
"""Enhance agent messages with Groq's capabilities"""
prompt = f"""
Context: {context}
Original Message: {agent_message}
Please enhance this message with:
1. Additional relevant technical details
2. Best practices and recommendations
3. Potential challenges and solutions
4. Implementation considerations
"""
enhanced_response = await self.get_groq_response(prompt)
return enhanced_response
async def initiate_project(self, project_description: str):
"""Start the project development process"""
# Create a group chat for all agents
groupchat = autogen.GroupChat(
agents=[self.user_proxy, self.researcher, self.architect,
self.developer, self.tester],
messages=[],
max_round=50
)
manager = autogen.GroupChatManager(
groupchat=groupchat,
llm_config=self.llm_config
)
# Enhance project description with Groq
enhanced_description = await self.enhance_with_groq(
project_description,
"Initial project requirements analysis"
)
# Start the project with enhanced description
await self.user_proxy.initiate_chat(
manager,
message=f"""
New project request: {enhanced_description}
Please follow this development process:
1. Research Phase:
- Analyze requirements in detail
- Research potential solutions and technologies
- Provide comprehensive research report
2. Architecture Phase:
- Design system architecture
- Select appropriate technologies
- Create detailed technical specifications
3. Development Phase:
- Implement solution following specifications
- Write clean, efficient code
- Document all components
4. Testing Phase:
- Execute comprehensive test plan
- Perform all levels of testing
- Report and track issues
5. Review Phase:
- All agents review the solution
- Provide feedback and suggestions
- Identify areas for improvement
Start with the research phase.
"""
)
async def handle_feedback(self, feedback: str):
"""Process user feedback and initiate improvements"""
# Enhance feedback with Groq
enhanced_feedback = await self.enhance_with_groq(
feedback,
"Project improvement feedback analysis"
)
feedback_message = f"""
Enhanced user feedback received: {enhanced_feedback}
Please analyze and implement improvements:
1. Researcher: Evaluate if additional research is needed
2. Architect: Review if architectural changes are required
3. Developer: Implement necessary changes
4. Tester: Verify improvements
Provide detailed reports at each stage.
"""
await self.user_proxy.initiate_chat(
self.manager,
message=feedback_message
)
# Example usage
async def main():
# Initialize project manager with your Groq API key
project_manager = ProjectManager(groq_api_key="Key")
# Start a new project
project_description = """
Create a web application that allows users to upload and analyze CSV files.
The application should provide basic statistics and visualizations.
"""
await project_manager.initiate_project(project_description)
# Handle feedback later if needed
feedback = "Please add support for Excel files and improve the visualization options"
await project_manager.handle_feedback(feedback)
if __name__ == "__main__":
asyncio.run(main())