blob: 92560cf48de7ebf3572bcd574afadbadf2173d17 [file] [log] [blame]
iomodof1ddefe2025-07-28 09:02:05 +04001package fake
2
3import (
4 "context"
5 "fmt"
iomodod9ff8da2025-07-28 11:42:22 +04006 "strings"
iomodof1ddefe2025-07-28 09:02:05 +04007 "time"
8
9 "github.com/iomodo/staff/llm"
10)
11
12// FakeProvider implements a fake LLM provider for testing
13type FakeProvider struct {
14 responses []string
15 index int
16}
17
18// NewFakeProvider creates a new fake provider with predefined responses
iomodo75542322025-07-30 19:27:48 +040019func New() *FakeProvider {
iomodof1ddefe2025-07-28 09:02:05 +040020 responses := []string{
21 `## Task Solution
22
23I've analyzed the task requirements and here's my proposed solution:
24
25### Implementation Plan
261. Create the necessary data structures
272. Implement the core business logic
283. Add proper error handling
294. Write comprehensive tests
305. Update documentation
31
32### Code Changes
33- Add new functions to handle the requirements
34- Update existing modules for compatibility
35- Implement proper validation
36- Add logging for debugging
37
38### Testing Strategy
39- Unit tests for all new functions
40- Integration tests for the workflow
41- Performance tests for scalability
42- Edge case validation
43
44### Files to Create/Modify
45- src/main.go - Core implementation
46- src/handlers.go - Request handlers
47- src/models.go - Data models
48- tests/ - Test files
49- docs/ - Documentation updates
50
51### Dependencies
52No new external dependencies required.
53
54### Deployment Notes
55- Backward compatible changes
56- No database migrations needed
57- Can be deployed incrementally
58
59This solution addresses all the requirements while maintaining code quality and system stability.`,
60
61 `## Comprehensive Task Analysis
62
63After careful consideration, I recommend the following approach:
64
65### Technical Architecture
66- **Backend**: Implement using existing Go patterns
67- **Database**: Utilize current PostgreSQL setup
68- **API**: RESTful endpoints with proper versioning
69- **Security**: OAuth2 authentication with JWT tokens
70
71### Development Steps
721. **Phase 1**: Core functionality implementation
732. **Phase 2**: User interface development
743. **Phase 3**: Testing and optimization
754. **Phase 4**: Documentation and deployment
76
77### Risk Assessment
78- **Low Risk**: Well-defined requirements
79- **Medium Risk**: Timeline constraints
80- **Mitigation**: Incremental development approach
81
82### Resource Requirements
83- Development time: 2-3 weeks
84- Testing phase: 1 week
85- Documentation: 2-3 days
86
87### Success Metrics
88- Performance benchmarks met
89- All test cases passing
90- User acceptance criteria satisfied
91- Code coverage > 90%
92
93This solution provides a robust foundation for future enhancements while meeting immediate business needs.`,
94
95 `## Strategic Implementation Proposal
96
97### Executive Summary
98This task requires a comprehensive solution that balances technical excellence with business objectives.
99
100### Solution Overview
101- **Approach**: Agile development methodology
102- **Technology Stack**: Current tech stack enhancement
103- **Timeline**: 3-4 week delivery cycle
104- **Team**: Cross-functional collaboration
105
106### Technical Specifications
107- Clean architecture principles
108- Microservices design patterns
109- Event-driven communication
110- Comprehensive monitoring and logging
111
112### Implementation Details
1131. **Requirements Analysis**: Complete stakeholder alignment
1142. **System Design**: Scalable and maintainable architecture
1153. **Development**: Test-driven development approach
1164. **Quality Assurance**: Automated testing pipeline
1175. **Deployment**: Blue-green deployment strategy
118
119### Business Impact
120- Improved user experience
121- Enhanced system reliability
122- Reduced operational overhead
123- Increased development velocity
124
125### Next Steps
1261. Stakeholder review and approval
1272. Resource allocation confirmation
1283. Development sprint planning
1294. Implementation kickoff
130
131This solution ensures long-term success while delivering immediate value to the organization.`,
iomodod9ff8da2025-07-28 11:42:22 +0400132
133 `{
134 "analysis_summary": "This task requires a comprehensive multi-phase approach involving frontend, backend, and infrastructure components. The complexity suggests breaking it into specialized subtasks for different team members.",
135 "subtasks": [
136 {
137 "title": "Design System Architecture",
138 "description": "Create detailed technical architecture diagrams, define API contracts, and establish database schema design",
139 "priority": "high",
140 "assigned_to": "ceo",
141 "estimated_hours": 12,
142 "dependencies": []
143 },
144 {
145 "title": "Backend API Development",
146 "description": "Implement core backend services, API endpoints, authentication middleware, and data validation layers",
147 "priority": "high",
148 "assigned_to": "ceo",
149 "estimated_hours": 24,
150 "dependencies": ["0"]
151 },
152 {
153 "title": "Database Setup and Migration",
154 "description": "Set up database infrastructure, create migration scripts, establish indexes, and implement backup procedures",
155 "priority": "medium",
156 "assigned_to": "ceo",
157 "estimated_hours": 8,
158 "dependencies": ["0"]
159 },
160 {
161 "title": "Frontend Interface Implementation",
162 "description": "Build user interface components, implement state management, integrate with backend APIs, and ensure responsive design",
163 "priority": "high",
164 "assigned_to": "ceo",
165 "estimated_hours": 32,
166 "dependencies": ["1"]
167 },
168 {
169 "title": "Testing and Quality Assurance",
170 "description": "Develop comprehensive test suites including unit tests, integration tests, and end-to-end testing scenarios",
171 "priority": "medium",
172 "assigned_to": "ceo",
173 "estimated_hours": 16,
174 "dependencies": ["1", "3"]
175 },
176 {
177 "title": "Deployment and Documentation",
178 "description": "Set up CI/CD pipeline, deploy to staging environment, create user documentation, and prepare production deployment",
179 "priority": "low",
180 "assigned_to": "ceo",
181 "estimated_hours": 10,
182 "dependencies": ["4"]
183 }
184 ],
185 "recommended_approach": "Start with architecture design to establish clear foundations, then proceed with parallel backend and database development. Once backend APIs are stable, begin frontend implementation while maintaining continuous testing throughout the process.",
186 "estimated_total_hours": 102,
187 "risk_assessment": "Main risks include scope creep, API integration complexity, and potential database performance issues. Mitigation strategies include regular stakeholder reviews, comprehensive API documentation, and early performance testing."
188}`,
iomodo5c99a442025-07-28 14:23:52 +0400189
190 `{
191 "needs_subtasks": true,
192 "reasoning": "This task appears to be complex and multi-faceted, requiring different specialized skills including backend development, frontend work, database management, and testing. Breaking it down into subtasks would allow for better parallel execution and specialized agent assignment.",
193 "complexity_score": 8,
194 "required_skills": ["backend_development", "frontend_development", "database_design", "api_development", "testing", "deployment"]
195}`,
196
197 `{
198 "needs_subtasks": false,
199 "reasoning": "This task is straightforward and can be completed by a single agent with existing capabilities. The scope is well-defined and doesn't require multiple specialized skills or extensive coordination.",
200 "complexity_score": 3,
201 "required_skills": ["basic_development"]
202}`,
iomodof1ddefe2025-07-28 09:02:05 +0400203 }
204
205 return &FakeProvider{
206 responses: responses,
207 index: 0,
208 }
209}
210
211// ChatCompletion implements the LLM interface
212func (f *FakeProvider) ChatCompletion(ctx context.Context, req llm.ChatCompletionRequest) (*llm.ChatCompletionResponse, error) {
213 // Simulate API delay
214 time.Sleep(500 * time.Millisecond)
215
iomodo5c99a442025-07-28 14:23:52 +0400216 // Check the type of request to provide appropriate response
217 isSubtaskAnalysisRequest := false
218 isSubtaskDecisionRequest := false
iomodod9ff8da2025-07-28 11:42:22 +0400219 for _, msg := range req.Messages {
iomodo5c99a442025-07-28 14:23:52 +0400220 if strings.Contains(msg.Content, "break it down into subtasks") || strings.Contains(msg.Content, "subtask analysis") {
221 isSubtaskAnalysisRequest = true
222 break
223 } else if strings.Contains(msg.Content, "needs to be broken down") || strings.Contains(msg.Content, "evaluate whether") {
224 isSubtaskDecisionRequest = true
iomodod9ff8da2025-07-28 11:42:22 +0400225 break
226 }
227 }
228
229 var response string
iomodo5c99a442025-07-28 14:23:52 +0400230 if isSubtaskAnalysisRequest && len(f.responses) > 3 {
231 // Use the detailed subtask analysis JSON response
232 response = f.responses[3] // The detailed JSON response is at index 3
233 } else if isSubtaskDecisionRequest && len(f.responses) > 4 {
234 // Use alternating decision responses
235 if f.index%2 == 0 {
236 response = f.responses[4] // "needs_subtasks": true
237 } else {
238 response = f.responses[5] // "needs_subtasks": false
239 }
240 f.index++
iomodod9ff8da2025-07-28 11:42:22 +0400241 } else {
iomodo5c99a442025-07-28 14:23:52 +0400242 // Get the next regular response (cycle through first 3)
243 response = f.responses[f.index%3] // Only cycle through first 3 responses
iomodod9ff8da2025-07-28 11:42:22 +0400244 f.index++
245 }
iomodof1ddefe2025-07-28 09:02:05 +0400246
247 return &llm.ChatCompletionResponse{
248 ID: fmt.Sprintf("fake-response-%d", f.index),
249 Object: "chat.completion",
250 Created: time.Now().Unix(),
251 Model: req.Model,
252 Choices: []llm.ChatCompletionChoice{
253 {
254 Index: 0,
255 Message: llm.Message{
256 Role: llm.RoleAssistant,
257 Content: response,
258 },
259 FinishReason: "stop",
260 },
261 },
262 Usage: llm.Usage{
263 PromptTokens: 100,
264 CompletionTokens: 300,
265 TotalTokens: 400,
266 },
267 }, nil
268}
269
270// CreateEmbeddings implements the LLM interface (not used in current implementation)
271func (f *FakeProvider) CreateEmbeddings(ctx context.Context, req llm.EmbeddingRequest) (*llm.EmbeddingResponse, error) {
272 return &llm.EmbeddingResponse{
273 Object: "list",
274 Data: []llm.Embedding{
275 {
276 Object: "embedding",
277 Index: 0,
278 Embedding: make([]float64, 1536), // OpenAI embedding size
279 },
280 },
281 Model: req.Model,
282 Usage: llm.Usage{
283 PromptTokens: 50,
284 TotalTokens: 50,
285 },
286 }, nil
287}
288
289// Close implements the LLM interface
290func (f *FakeProvider) Close() error {
291 // Nothing to close for fake provider
292 return nil
iomodo75542322025-07-30 19:27:48 +0400293}