blob: 37358214fe19ccafbff6f823093eeafda2726ab8 [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
19func NewFakeProvider() *FakeProvider {
20 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}`,
iomodof1ddefe2025-07-28 09:02:05 +0400189 }
190
191 return &FakeProvider{
192 responses: responses,
193 index: 0,
194 }
195}
196
197// ChatCompletion implements the LLM interface
198func (f *FakeProvider) ChatCompletion(ctx context.Context, req llm.ChatCompletionRequest) (*llm.ChatCompletionResponse, error) {
199 // Simulate API delay
200 time.Sleep(500 * time.Millisecond)
201
iomodod9ff8da2025-07-28 11:42:22 +0400202 // Check if this is a subtask analysis request
203 isSubtaskRequest := false
204 for _, msg := range req.Messages {
205 if strings.Contains(msg.Content, "subtasks") || strings.Contains(msg.Content, "JSON") {
206 isSubtaskRequest = true
207 break
208 }
209 }
210
211 var response string
212 if isSubtaskRequest && len(f.responses) > 3 {
213 // Always use the JSON subtask response for subtask requests
214 response = f.responses[3] // The JSON response is at index 3
215 } else {
216 // Get the next response (cycle through responses)
217 response = f.responses[f.index%len(f.responses)]
218 f.index++
219 }
iomodof1ddefe2025-07-28 09:02:05 +0400220
221 return &llm.ChatCompletionResponse{
222 ID: fmt.Sprintf("fake-response-%d", f.index),
223 Object: "chat.completion",
224 Created: time.Now().Unix(),
225 Model: req.Model,
226 Choices: []llm.ChatCompletionChoice{
227 {
228 Index: 0,
229 Message: llm.Message{
230 Role: llm.RoleAssistant,
231 Content: response,
232 },
233 FinishReason: "stop",
234 },
235 },
236 Usage: llm.Usage{
237 PromptTokens: 100,
238 CompletionTokens: 300,
239 TotalTokens: 400,
240 },
241 }, nil
242}
243
244// CreateEmbeddings implements the LLM interface (not used in current implementation)
245func (f *FakeProvider) CreateEmbeddings(ctx context.Context, req llm.EmbeddingRequest) (*llm.EmbeddingResponse, error) {
246 return &llm.EmbeddingResponse{
247 Object: "list",
248 Data: []llm.Embedding{
249 {
250 Object: "embedding",
251 Index: 0,
252 Embedding: make([]float64, 1536), // OpenAI embedding size
253 },
254 },
255 Model: req.Model,
256 Usage: llm.Usage{
257 PromptTokens: 50,
258 TotalTokens: 50,
259 },
260 }, nil
261}
262
263// Close implements the LLM interface
264func (f *FakeProvider) Close() error {
265 // Nothing to close for fake provider
266 return nil
267}