Commit ·
bd91486
1
Parent(s): 7ef8c9d
cogenbai
Browse files- .env +5 -0
- BUILD.md +311 -0
- Dockerfile +0 -0
- INTEGRATION.md +190 -0
- README.md +34 -3
- cogenbai.egg-info/PKG-INFO +241 -0
- cogenbai.egg-info/SOURCES.txt +11 -0
- cogenbai.egg-info/dependency_links.txt +1 -0
- cogenbai.egg-info/entry_points.txt +2 -0
- cogenbai.egg-info/requires.txt +11 -0
- cogenbai.egg-info/top_level.txt +1 -0
- cogenbai/__init__.py +10 -0
- cogenbai/__pycache__/__init__.cpython-313.pyc +0 -0
- cogenbai/api/middleware.py +13 -0
- cogenbai/api/server.py +128 -0
- cogenbai/cli/main.py +67 -0
- cogenbai/collaboration/session.py +48 -0
- cogenbai/collaboration/websocket.py +24 -0
- cogenbai/config.py +84 -0
- cogenbai/core/__pycache__/model.cpython-313.pyc +0 -0
- cogenbai/core/config.py +0 -0
- cogenbai/core/model.py +179 -0
- cogenbai/debug/analyzer.py +23 -0
- cogenbai/languages/generator.py +126 -0
- cogenbai/languages/modern_frameworks.py +72 -0
- cogenbai/optimization/optimizer.py +59 -0
- cogenbai/review/analyzer.py +88 -0
- cogenbai/storage/project_tracker.py +91 -0
- cogenbai/templates/code_templates.py +61 -0
- cogenbai/templates/frameworks/qt_template.py +40 -0
- cogenbai/templates/modern/astro_template.py +66 -0
- cogenbai/templates/registry.py +34 -0
- cogenbai/templates/scaffolds/python_project.json +18 -0
- cogenbai/testing/generator.py +64 -0
- cogenbai/voice/synthesizer.py +16 -0
- config.yaml +43 -0
- docker-compose.yml +34 -0
- requirements.txt +12 -0
- setup.py +59 -0
- tests/integration/test_workflow.py +28 -0
- tests/test_model.py +31 -0
.env
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MODEL_NAME=codegen-16B-multi
|
| 2 |
+
DEVICE=cuda
|
| 3 |
+
API_TOKEN_SECRET=your-secret-key
|
| 4 |
+
PROMETHEUS_ENABLED=true
|
| 5 |
+
DEBUG=false
|
BUILD.md
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# COGENBAI Build Guide
|
| 2 |
+
|
| 3 |
+
This guide explains how to build, deploy, and use COGENBAI from source, including Ollama integration.
|
| 4 |
+
|
| 5 |
+
## Prerequisites
|
| 6 |
+
|
| 7 |
+
- Python 3.8 or higher
|
| 8 |
+
- CUDA-capable GPU (recommended)
|
| 9 |
+
- Git
|
| 10 |
+
- Docker (optional)
|
| 11 |
+
- Ollama
|
| 12 |
+
|
| 13 |
+
## Local Development Setup
|
| 14 |
+
|
| 15 |
+
1. Clone the repository:
|
| 16 |
+
```bash
|
| 17 |
+
git clone https://github.com/algoscienceacademy/cogenbai.git
|
| 18 |
+
cd cogenbai
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
2. Create a virtual environment:
|
| 22 |
+
```bash
|
| 23 |
+
python -m venv venv
|
| 24 |
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
3. Install dependencies:
|
| 28 |
+
```bash
|
| 29 |
+
pip install -e ".[dev]"
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
## Building the Model
|
| 33 |
+
|
| 34 |
+
1. Download the base model:
|
| 35 |
+
```bash
|
| 36 |
+
python scripts/download_model.py --model codegen-16B-multi
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
2. Train or fine-tune (optional):
|
| 40 |
+
```bash
|
| 41 |
+
python scripts/train.py \
|
| 42 |
+
--model-path models/codegen-16B-multi \
|
| 43 |
+
--train-data data/code_samples \
|
| 44 |
+
--epochs 3
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
## Ollama Integration
|
| 48 |
+
|
| 49 |
+
1. Install Ollama:
|
| 50 |
+
```bash
|
| 51 |
+
curl -fsSL https://ollama.com/install.sh | sh
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
2. Create Modelfile:
|
| 55 |
+
```bash
|
| 56 |
+
# Create Modelfile
|
| 57 |
+
FROM codellama
|
| 58 |
+
PARAMETER temperature 0.7
|
| 59 |
+
PARAMETER top_p 0.95
|
| 60 |
+
SYSTEM """
|
| 61 |
+
You are COGENBAI, an advanced code generation AI created by Algo Science Academy.
|
| 62 |
+
Created by: Shahrear Hossain Shawon
|
| 63 |
+
Organization: Algo Science Academy
|
| 64 |
+
"""
|
| 65 |
+
|
| 66 |
+
# Build the model
|
| 67 |
+
ollama create cogenbai -f Modelfile
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
3. Deploy with Ollama:
|
| 71 |
+
```bash
|
| 72 |
+
ollama run cogenbai
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
## Building with Ollama
|
| 76 |
+
|
| 77 |
+
### Prerequisites
|
| 78 |
+
- Ollama installed on your system
|
| 79 |
+
- Base model files ready
|
| 80 |
+
|
| 81 |
+
### Steps to Build Model in Ollama
|
| 82 |
+
|
| 83 |
+
1. Create a Modelfile:
|
| 84 |
+
```bash
|
| 85 |
+
# Modelfile
|
| 86 |
+
FROM codellama
|
| 87 |
+
PARAMETER temperature 0.7
|
| 88 |
+
PARAMETER top_p 0.95
|
| 89 |
+
PARAMETER num_ctx 4096
|
| 90 |
+
|
| 91 |
+
# Model configuration
|
| 92 |
+
SYSTEM """
|
| 93 |
+
You are COGENBAI, an advanced code generation AI.
|
| 94 |
+
Focus: Code generation and software development assistance
|
| 95 |
+
Created by: Shahrear Hossain Shawon
|
| 96 |
+
Organization: Algo Science Academy
|
| 97 |
+
"""
|
| 98 |
+
|
| 99 |
+
# Include base model files
|
| 100 |
+
FROM models/codegen-16B-multi
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
2. Build the model in Ollama:
|
| 104 |
+
```bash
|
| 105 |
+
# Navigate to project directory
|
| 106 |
+
cd cogenbai
|
| 107 |
+
|
| 108 |
+
# Build the model
|
| 109 |
+
ollama create cogenbai -f Modelfile
|
| 110 |
+
|
| 111 |
+
# Verify the build
|
| 112 |
+
ollama list
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
3. Run the model:
|
| 116 |
+
```bash
|
| 117 |
+
ollama run cogenbai
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
### Testing the Build
|
| 121 |
+
|
| 122 |
+
Test your model with a simple prompt:
|
| 123 |
+
```bash
|
| 124 |
+
ollama run cogenbai "Write a Python function to calculate fibonacci sequence"
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
### Troubleshooting Ollama Build
|
| 128 |
+
|
| 129 |
+
If you encounter issues:
|
| 130 |
+
1. Check Ollama logs:
|
| 131 |
+
```bash
|
| 132 |
+
ollama logs
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
2. Rebuild model if needed:
|
| 136 |
+
```bash
|
| 137 |
+
ollama rm cogenbai
|
| 138 |
+
ollama create cogenbai -f Modelfile
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
## Docker Deployment
|
| 142 |
+
|
| 143 |
+
1. Build Docker image:
|
| 144 |
+
```bash
|
| 145 |
+
docker build -t cogenbai:latest .
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
2. Run container:
|
| 149 |
+
```bash
|
| 150 |
+
docker run -d -p 8000:8000 cogenbai:latest
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
## Project Structure
|
| 154 |
+
|
| 155 |
+
```
|
| 156 |
+
cogenbai/
|
| 157 |
+
├── cogenbai/
|
| 158 |
+
│ ├── core/ # Core model implementation
|
| 159 |
+
│ ├── languages/ # Language-specific generators
|
| 160 |
+
│ ├── templates/ # Code templates
|
| 161 |
+
│ ├── collaboration/ # Real-time collaboration
|
| 162 |
+
│ ├── review/ # Code review tools
|
| 163 |
+
│ ├── testing/ # Test generation
|
| 164 |
+
│ └── api/ # REST API
|
| 165 |
+
├── tests/ # Unit and integration tests
|
| 166 |
+
├── scripts/ # Build and utility scripts
|
| 167 |
+
└── docs/ # Documentation
|
| 168 |
+
```
|
| 169 |
+
|
| 170 |
+
## Configuration
|
| 171 |
+
|
| 172 |
+
1. Create configuration file:
|
| 173 |
+
```yaml
|
| 174 |
+
# config.yaml
|
| 175 |
+
model:
|
| 176 |
+
name: codegen-16B-multi
|
| 177 |
+
device: cuda
|
| 178 |
+
max_length: 1024
|
| 179 |
+
temperature: 0.7
|
| 180 |
+
|
| 181 |
+
language:
|
| 182 |
+
default: python
|
| 183 |
+
style:
|
| 184 |
+
python: black
|
| 185 |
+
javascript: prettier
|
| 186 |
+
```
|
| 187 |
+
|
| 188 |
+
2. Apply configuration:
|
| 189 |
+
```python
|
| 190 |
+
from cogenbai import CogenConfig
|
| 191 |
+
config = CogenConfig.load('config.yaml')
|
| 192 |
+
```
|
| 193 |
+
|
| 194 |
+
## API Deployment
|
| 195 |
+
|
| 196 |
+
1. Start the API server:
|
| 197 |
+
```bash
|
| 198 |
+
uvicorn cogenbai.api.server:app --host 0.0.0.0 --port 8000
|
| 199 |
+
```
|
| 200 |
+
|
| 201 |
+
2. Access API documentation:
|
| 202 |
+
```
|
| 203 |
+
http://localhost:8000/docs
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
## Testing
|
| 207 |
+
|
| 208 |
+
Run the test suite:
|
| 209 |
+
```bash
|
| 210 |
+
pytest tests/
|
| 211 |
+
```
|
| 212 |
+
|
| 213 |
+
## Development Workflow
|
| 214 |
+
|
| 215 |
+
1. Create new feature branch:
|
| 216 |
+
```bash
|
| 217 |
+
git checkout -b feature/new-feature
|
| 218 |
+
```
|
| 219 |
+
|
| 220 |
+
2. Make changes and run tests:
|
| 221 |
+
```bash
|
| 222 |
+
pytest tests/
|
| 223 |
+
black cogenbai/
|
| 224 |
+
```
|
| 225 |
+
|
| 226 |
+
3. Build documentation:
|
| 227 |
+
```bash
|
| 228 |
+
mkdocs build
|
| 229 |
+
```
|
| 230 |
+
|
| 231 |
+
## Performance Optimization
|
| 232 |
+
|
| 233 |
+
1. Enable CUDA acceleration:
|
| 234 |
+
```python
|
| 235 |
+
model = CogenBAI(device="cuda")
|
| 236 |
+
```
|
| 237 |
+
|
| 238 |
+
2. Batch processing:
|
| 239 |
+
```python
|
| 240 |
+
config = CogenConfig(batch_size=4, num_workers=2)
|
| 241 |
+
```
|
| 242 |
+
|
| 243 |
+
## Monitoring
|
| 244 |
+
|
| 245 |
+
1. Start Prometheus metrics:
|
| 246 |
+
```bash
|
| 247 |
+
docker-compose up -d prometheus grafana
|
| 248 |
+
```
|
| 249 |
+
|
| 250 |
+
2. Access dashboard:
|
| 251 |
+
```
|
| 252 |
+
http://localhost:3000
|
| 253 |
+
```
|
| 254 |
+
|
| 255 |
+
## Troubleshooting
|
| 256 |
+
|
| 257 |
+
Common issues and solutions:
|
| 258 |
+
|
| 259 |
+
1. CUDA Out of Memory:
|
| 260 |
+
```bash
|
| 261 |
+
export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:128
|
| 262 |
+
```
|
| 263 |
+
|
| 264 |
+
2. Model Loading Issues:
|
| 265 |
+
```python
|
| 266 |
+
import torch
|
| 267 |
+
torch.cuda.empty_cache()
|
| 268 |
+
```
|
| 269 |
+
|
| 270 |
+
## Security Considerations
|
| 271 |
+
|
| 272 |
+
1. API Authentication:
|
| 273 |
+
```python
|
| 274 |
+
from fastapi.security import OAuth2PasswordBearer
|
| 275 |
+
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
| 276 |
+
```
|
| 277 |
+
|
| 278 |
+
2. Rate Limiting:
|
| 279 |
+
```python
|
| 280 |
+
from fastapi_limiter import FastAPILimiter
|
| 281 |
+
await FastAPILimiter.init(redis)
|
| 282 |
+
```
|
| 283 |
+
|
| 284 |
+
## Production Deployment
|
| 285 |
+
|
| 286 |
+
1. Using Kubernetes:
|
| 287 |
+
```bash
|
| 288 |
+
kubectl apply -f k8s/
|
| 289 |
+
```
|
| 290 |
+
|
| 291 |
+
2. Load Balancing:
|
| 292 |
+
```bash
|
| 293 |
+
kubectl apply -f k8s/ingress.yaml
|
| 294 |
+
```
|
| 295 |
+
|
| 296 |
+
## Contributing
|
| 297 |
+
|
| 298 |
+
1. Fork the repository
|
| 299 |
+
2. Create feature branch
|
| 300 |
+
3. Make changes
|
| 301 |
+
4. Submit pull request
|
| 302 |
+
|
| 303 |
+
## Support
|
| 304 |
+
|
| 305 |
+
For support and questions:
|
| 306 |
+
- Email: contact@algoscienceacademy.com
|
| 307 |
+
- GitHub Issues: [Create Issue](https://github.com/algoscienceacademy/cogenbai/issues)
|
| 308 |
+
|
| 309 |
+
## License
|
| 310 |
+
|
| 311 |
+
Copyright (c) 2024 Algo Science Academy. All rights reserved.
|
Dockerfile
ADDED
|
File without changes
|
INTEGRATION.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# COGENBAI Integration Guide
|
| 2 |
+
|
| 3 |
+
## Component Integration Map
|
| 4 |
+
|
| 5 |
+
### 1. Core Components
|
| 6 |
+
```
|
| 7 |
+
cogenbai/core/
|
| 8 |
+
├── model.py # Main AI model (CogenBAI class)
|
| 9 |
+
└── config.py # Configuration management
|
| 10 |
+
```
|
| 11 |
+
- `model.py` is the central component that integrates with all other modules
|
| 12 |
+
- `config.py` provides configuration management used across all components
|
| 13 |
+
|
| 14 |
+
### 2. API Layer Integration
|
| 15 |
+
```
|
| 16 |
+
cogenbai/api/
|
| 17 |
+
├── server.py # FastAPI server
|
| 18 |
+
└── middleware.py # Request logging and auth
|
| 19 |
+
```
|
| 20 |
+
- `server.py` exposes core functionality via REST API
|
| 21 |
+
- Connects to core model, language generator, and collaboration features
|
| 22 |
+
|
| 23 |
+
### 3. Language Support Integration
|
| 24 |
+
```
|
| 25 |
+
cogenbai/languages/
|
| 26 |
+
└── generator.py # Language-specific code generation
|
| 27 |
+
```
|
| 28 |
+
- Used by core model for language-specific code generation
|
| 29 |
+
- Integrates with templates and modern frameworks
|
| 30 |
+
|
| 31 |
+
### 4. Collaboration Features
|
| 32 |
+
```
|
| 33 |
+
cogenbai/collaboration/
|
| 34 |
+
├── session.py # Session management
|
| 35 |
+
└── websocket.py # Real-time collaboration
|
| 36 |
+
```
|
| 37 |
+
- WebSocket server handles real-time code synchronization
|
| 38 |
+
- Session manager tracks active collaboration sessions
|
| 39 |
+
|
| 40 |
+
### 5. Development Tools
|
| 41 |
+
```
|
| 42 |
+
cogenbai/
|
| 43 |
+
├── debug/ # Code analysis
|
| 44 |
+
├── review/ # Code review
|
| 45 |
+
└── testing/ # Test generation
|
| 46 |
+
```
|
| 47 |
+
- All tools integrate with core model via API endpoints
|
| 48 |
+
- Share common configuration and language support
|
| 49 |
+
|
| 50 |
+
## Integration Flow
|
| 51 |
+
|
| 52 |
+
1. **Startup Sequence**
|
| 53 |
+
```python
|
| 54 |
+
from cogenbai import CogenBAI, CogenConfig
|
| 55 |
+
|
| 56 |
+
# Load configuration
|
| 57 |
+
config = CogenConfig.load('config.yaml')
|
| 58 |
+
|
| 59 |
+
# Initialize core model
|
| 60 |
+
model = CogenBAI(config)
|
| 61 |
+
|
| 62 |
+
# Start API server
|
| 63 |
+
from cogenbai.api.server import app
|
| 64 |
+
import uvicorn
|
| 65 |
+
uvicorn.run(app)
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
2. **Code Generation Flow**
|
| 69 |
+
```python
|
| 70 |
+
# 1. Request comes through API
|
| 71 |
+
@app.post("/generate")
|
| 72 |
+
async def generate_code(request: CodeRequest):
|
| 73 |
+
|
| 74 |
+
# 2. Core model handles request
|
| 75 |
+
code = model.generate_code(
|
| 76 |
+
prompt=request.prompt,
|
| 77 |
+
language=request.language
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
# 3. Language generator processes code
|
| 81 |
+
from cogenbai.languages.generator import LanguageGenerator
|
| 82 |
+
lang_generator = LanguageGenerator()
|
| 83 |
+
formatted_code = lang_generator.format(code, request.language)
|
| 84 |
+
|
| 85 |
+
return {"code": formatted_code}
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
3. **Collaboration Flow**
|
| 89 |
+
```python
|
| 90 |
+
# 1. WebSocket connection established
|
| 91 |
+
@app.websocket("/ws/{session_id}")
|
| 92 |
+
async def websocket_endpoint(websocket: WebSocket, session_id: str):
|
| 93 |
+
|
| 94 |
+
# 2. Session manager handles connection
|
| 95 |
+
await session_manager.connect(session_id, websocket)
|
| 96 |
+
|
| 97 |
+
# 3. Real-time updates broadcast to all participants
|
| 98 |
+
await collaboration_manager.broadcast(
|
| 99 |
+
session_id,
|
| 100 |
+
{"type": "update", "data": code_update}
|
| 101 |
+
)
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
## File Paths and Dependencies
|
| 105 |
+
|
| 106 |
+
All components are installed under the main package:
|
| 107 |
+
```
|
| 108 |
+
/c:/Users/shahrear/Downloads/cogenbai/
|
| 109 |
+
├── cogenbai/ # Main package directory
|
| 110 |
+
├── tests/ # Test files
|
| 111 |
+
├── Modelfile # Ollama model definition
|
| 112 |
+
├── BUILD.md # Build instructions
|
| 113 |
+
└── INTEGRATION.md # This file
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
## Configuration Integration
|
| 117 |
+
|
| 118 |
+
The `config.py` file integrates all components through shared settings:
|
| 119 |
+
```yaml
|
| 120 |
+
model:
|
| 121 |
+
name: codegen-16B-multi
|
| 122 |
+
device: cuda
|
| 123 |
+
|
| 124 |
+
languages:
|
| 125 |
+
default: python
|
| 126 |
+
supported: [python, javascript, ...]
|
| 127 |
+
|
| 128 |
+
collaboration:
|
| 129 |
+
max_sessions: 100
|
| 130 |
+
timeout: 3600
|
| 131 |
+
|
| 132 |
+
api:
|
| 133 |
+
host: 0.0.0.0
|
| 134 |
+
port: 8000
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
## Testing Integration
|
| 138 |
+
|
| 139 |
+
Run integrated tests:
|
| 140 |
+
```bash
|
| 141 |
+
pytest tests/integration/
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
## Monitoring Integration
|
| 145 |
+
|
| 146 |
+
All components emit metrics:
|
| 147 |
+
```python
|
| 148 |
+
from cogenbai.monitoring import metrics
|
| 149 |
+
|
| 150 |
+
# Track model performance
|
| 151 |
+
metrics.track_generation_time(duration)
|
| 152 |
+
|
| 153 |
+
# Monitor API requests
|
| 154 |
+
metrics.track_api_request(endpoint, status)
|
| 155 |
+
|
| 156 |
+
# Log collaboration events
|
| 157 |
+
metrics.track_collaboration_session(session_id)
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
## Security Integration
|
| 161 |
+
|
| 162 |
+
Components share common security features:
|
| 163 |
+
- API authentication
|
| 164 |
+
- Session validation
|
| 165 |
+
- Rate limiting
|
| 166 |
+
- Input sanitization
|
| 167 |
+
|
| 168 |
+
## Production Integration Steps
|
| 169 |
+
|
| 170 |
+
1. Build the model:
|
| 171 |
+
```bash
|
| 172 |
+
ollama create cogenbai -f Modelfile
|
| 173 |
+
```
|
| 174 |
+
|
| 175 |
+
2. Start all components:
|
| 176 |
+
```bash
|
| 177 |
+
# Start API server
|
| 178 |
+
uvicorn cogenbai.api.server:app
|
| 179 |
+
|
| 180 |
+
# Start collaboration server
|
| 181 |
+
python -m cogenbai.collaboration.server
|
| 182 |
+
|
| 183 |
+
# Start monitoring
|
| 184 |
+
docker-compose up -d prometheus grafana
|
| 185 |
+
```
|
| 186 |
+
|
| 187 |
+
3. Verify integration:
|
| 188 |
+
```bash
|
| 189 |
+
curl http://localhost:8000/health
|
| 190 |
+
```
|
README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
| 1 |
-
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# COGENBAI - Advanced Code Generation AI
|
| 2 |
+
|
| 3 |
+
COGENBAI is a specialized AI model built on CodeLlama, optimized for software development and code analysis.
|
| 4 |
+
|
| 5 |
+
## Features
|
| 6 |
+
|
| 7 |
+
- 🚀 Advanced code generation
|
| 8 |
+
- 📊 Code analysis and optimization
|
| 9 |
+
- 🏗️ Project scaffolding
|
| 10 |
+
- 🔍 Code review and debugging
|
| 11 |
+
- 🛠️ Multi-framework support
|
| 12 |
+
- 🤝 Collaborative development
|
| 13 |
+
|
| 14 |
+
## Quick Start
|
| 15 |
+
|
| 16 |
+
```bash
|
| 17 |
+
# Create the model
|
| 18 |
+
ollama create cogenbai:7.5b -f Modelfile
|
| 19 |
+
|
| 20 |
+
# Run the model
|
| 21 |
+
ollama run cogenbai:7.5b
|
| 22 |
+
|
| 23 |
+
# Example usage
|
| 24 |
+
ollama run cogenbai:7.5b "Create a FastAPI endpoint for user authentication"
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
## Configuration
|
| 28 |
+
|
| 29 |
+
See `config.yaml` for model parameters and settings.
|
| 30 |
+
|
| 31 |
+
## License
|
| 32 |
+
|
| 33 |
+
Copyright (c) 2025 Algo Science Academy
|
| 34 |
+
````
|
cogenbai.egg-info/PKG-INFO
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.2
|
| 2 |
+
Name: cogenbai
|
| 3 |
+
Version: 1.0.0
|
| 4 |
+
Summary: Advanced AI model for coding experts by Algo Science Academy
|
| 5 |
+
Home-page: https://algoscienceacademy.com/cogenbai
|
| 6 |
+
Author: Shahrear Hossain Shawon
|
| 7 |
+
Author-email: contact@algoscienceacademy.com
|
| 8 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 9 |
+
Classifier: Intended Audience :: Developers
|
| 10 |
+
Classifier: License :: Other/Proprietary License
|
| 11 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 12 |
+
Requires-Python: >=3.8
|
| 13 |
+
Description-Content-Type: text/markdown
|
| 14 |
+
Requires-Dist: torch>=1.9.0
|
| 15 |
+
Requires-Dist: transformers>=4.11.0
|
| 16 |
+
Requires-Dist: pyttsx3>=2.90
|
| 17 |
+
Requires-Dist: fastapi>=0.68.0
|
| 18 |
+
Requires-Dist: uvicorn>=0.15.0
|
| 19 |
+
Requires-Dist: click>=8.0.0
|
| 20 |
+
Requires-Dist: autopep8>=1.5.7
|
| 21 |
+
Requires-Dist: black>=21.5b2
|
| 22 |
+
Requires-Dist: yapf>=0.31.0
|
| 23 |
+
Requires-Dist: websockets>=10.0
|
| 24 |
+
Requires-Dist: python-socketio>=5.5.0
|
| 25 |
+
Dynamic: author
|
| 26 |
+
Dynamic: author-email
|
| 27 |
+
Dynamic: classifier
|
| 28 |
+
Dynamic: description
|
| 29 |
+
Dynamic: description-content-type
|
| 30 |
+
Dynamic: home-page
|
| 31 |
+
Dynamic: requires-dist
|
| 32 |
+
Dynamic: requires-python
|
| 33 |
+
Dynamic: summary
|
| 34 |
+
|
| 35 |
+
# COGENBAI
|
| 36 |
+
|
| 37 |
+
An advanced AI model for coding experts, created by Algo Science Academy.
|
| 38 |
+
|
| 39 |
+
## About
|
| 40 |
+
|
| 41 |
+
COGENBAI is developed by Algo Science Academy under the leadership of Shahrear Hossain Shawon,
|
| 42 |
+
a student at International Islamic University Chittagong. This cutting-edge AI model represents
|
| 43 |
+
a significant advancement in automated code generation and development assistance.
|
| 44 |
+
|
| 45 |
+
## Organization
|
| 46 |
+
|
| 47 |
+
- **Organization**: Algo Science Academy
|
| 48 |
+
- **Lead Developer**: Shahrear Hossain Shawon
|
| 49 |
+
- **Institution**: International Islamic University Chittagong
|
| 50 |
+
- **Version**: 1.0.0
|
| 51 |
+
|
| 52 |
+
## Features
|
| 53 |
+
|
| 54 |
+
- Multi-language code generation
|
| 55 |
+
- Framework and library integration
|
| 56 |
+
- Complete software solutions
|
| 57 |
+
- Custom framework creation
|
| 58 |
+
- Real-time voiceover assistance
|
| 59 |
+
- Cross-platform development support
|
| 60 |
+
- Advanced debugging tools
|
| 61 |
+
- Collaborative development features
|
| 62 |
+
|
| 63 |
+
## Installation
|
| 64 |
+
|
| 65 |
+
```bash
|
| 66 |
+
pip install cogenbai
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## Usage
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
from cogenbai import CogenBAI, VoiceSynthesizer
|
| 73 |
+
|
| 74 |
+
# Initialize the model
|
| 75 |
+
model = CogenBAI()
|
| 76 |
+
|
| 77 |
+
# Generate code
|
| 78 |
+
code = model.generate_code(
|
| 79 |
+
prompt="Create a REST API endpoint in Python",
|
| 80 |
+
language="python"
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
# Use voice assistance
|
| 84 |
+
voice = VoiceSynthesizer()
|
| 85 |
+
voice.explain_code(code, "This code creates a REST API endpoint using FastAPI")
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
## API Usage
|
| 89 |
+
|
| 90 |
+
Start the API server:
|
| 91 |
+
```bash
|
| 92 |
+
uvicorn cogenbai.api.server:app --reload
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
Generate code via API:
|
| 96 |
+
```bash
|
| 97 |
+
curl -X POST "http://localhost:8000/generate" \
|
| 98 |
+
-H "Content-Type: application/json" \
|
| 99 |
+
-d '{"prompt": "Create a REST API endpoint", "language": "python"}'
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
Get supported languages:
|
| 103 |
+
```bash
|
| 104 |
+
curl "http://localhost:8000/supported-languages"
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
## CLI Usage
|
| 108 |
+
|
| 109 |
+
Generate code from command line:
|
| 110 |
+
```bash
|
| 111 |
+
cogenbai generate "Create a REST API endpoint" -l python -f fastapi
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
List supported languages:
|
| 115 |
+
```bash
|
| 116 |
+
cogenbai list-languages
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
## Project Scaffolding
|
| 120 |
+
|
| 121 |
+
Generate a new project structure:
|
| 122 |
+
```bash
|
| 123 |
+
cogenbai scaffold my-project -t python_project -d "My awesome project"
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
## Code Optimization
|
| 127 |
+
|
| 128 |
+
```python
|
| 129 |
+
from cogenbai.optimization import CodeOptimizer
|
| 130 |
+
|
| 131 |
+
optimizer = CodeOptimizer()
|
| 132 |
+
optimized_code = optimizer.optimize(code, "python")
|
| 133 |
+
complexity = optimizer.analyze_complexity(code)
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
## Collaborative Development
|
| 137 |
+
|
| 138 |
+
Start a collaborative session:
|
| 139 |
+
```python
|
| 140 |
+
import asyncio
|
| 141 |
+
from cogenbai import CogenBAI
|
| 142 |
+
from cogenbai.collaboration import SessionManager
|
| 143 |
+
|
| 144 |
+
async def main():
|
| 145 |
+
session_manager = SessionManager()
|
| 146 |
+
session = await session_manager.create_session("session1", "user1")
|
| 147 |
+
|
| 148 |
+
# Join session
|
| 149 |
+
await session_manager.join_session("session1", "user2")
|
| 150 |
+
|
| 151 |
+
# Update code
|
| 152 |
+
await session_manager.update_code("session1", "print('Hello, World!')")
|
| 153 |
+
|
| 154 |
+
asyncio.run(main())
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
Connect to WebSocket for real-time updates:
|
| 158 |
+
```javascript
|
| 159 |
+
const ws = new WebSocket('ws://localhost:8000/ws/session1/user1');
|
| 160 |
+
ws.onmessage = (event) => {
|
| 161 |
+
const data = JSON.parse(event.data);
|
| 162 |
+
if (data.type === 'code_update') {
|
| 163 |
+
console.log('Code updated:', data.code);
|
| 164 |
+
}
|
| 165 |
+
};
|
| 166 |
+
```
|
| 167 |
+
|
| 168 |
+
## Code Review and Testing
|
| 169 |
+
|
| 170 |
+
Review code quality:
|
| 171 |
+
```python
|
| 172 |
+
from cogenbai.review import CodeReviewAnalyzer
|
| 173 |
+
|
| 174 |
+
reviewer = CodeReviewAnalyzer()
|
| 175 |
+
results = reviewer.review_code(code, "python")
|
| 176 |
+
print(f"Code quality score: {results['complexity']['cyclomatic_complexity']}")
|
| 177 |
+
```
|
| 178 |
+
|
| 179 |
+
Generate tests:
|
| 180 |
+
```python
|
| 181 |
+
from cogenbai.testing import TestGenerator
|
| 182 |
+
|
| 183 |
+
generator = TestGenerator()
|
| 184 |
+
test_code = generator.generate_tests(code, "python", "unit")
|
| 185 |
+
print("Generated test code:", test_code)
|
| 186 |
+
```
|
| 187 |
+
|
| 188 |
+
## Hardware Requirements
|
| 189 |
+
|
| 190 |
+
### Model Size Information
|
| 191 |
+
- Model Parameters: 16 billion
|
| 192 |
+
- Model Size (FP16): ~32GB
|
| 193 |
+
- Model Size (FP32): ~64GB
|
| 194 |
+
|
| 195 |
+
### Minimum Hardware Requirements
|
| 196 |
+
- GPU Memory: 40GB (for FP16)
|
| 197 |
+
- System RAM: 64GB recommended
|
| 198 |
+
- Storage: 100GB free space
|
| 199 |
+
|
| 200 |
+
### Recommended Hardware
|
| 201 |
+
- GPU: NVIDIA A5000 (24GB) or better
|
| 202 |
+
- GPU Memory: 48GB or more
|
| 203 |
+
- System RAM: 128GB
|
| 204 |
+
- Storage: 500GB NVMe SSD
|
| 205 |
+
|
| 206 |
+
### Supported GPU Configurations
|
| 207 |
+
1. Single GPU (High-end):
|
| 208 |
+
- NVIDIA A6000 (48GB)
|
| 209 |
+
- NVIDIA A100 (80GB)
|
| 210 |
+
|
| 211 |
+
2. Multi-GPU Setup:
|
| 212 |
+
- 2x NVIDIA RTX 4090 (24GB each)
|
| 213 |
+
- 2x NVIDIA A5000 (24GB each)
|
| 214 |
+
|
| 215 |
+
### Memory Optimization Options
|
| 216 |
+
1. FP16 Precision (Default)
|
| 217 |
+
- Model Size: ~32GB
|
| 218 |
+
- Working Memory: ~8GB
|
| 219 |
+
- Total Required: ~40GB
|
| 220 |
+
|
| 221 |
+
2. 8-bit Quantization
|
| 222 |
+
- Model Size: ~16GB
|
| 223 |
+
- Working Memory: ~4GB
|
| 224 |
+
- Total Required: ~20GB
|
| 225 |
+
|
| 226 |
+
3. 4-bit Quantization
|
| 227 |
+
- Model Size: ~8GB
|
| 228 |
+
- Working Memory: ~2GB
|
| 229 |
+
- Total Required: ~10GB
|
| 230 |
+
|
| 231 |
+
## License
|
| 232 |
+
|
| 233 |
+
Copyright (c) 2024 Algo Science Academy. All rights reserved.
|
| 234 |
+
|
| 235 |
+
## Contact
|
| 236 |
+
|
| 237 |
+
For inquiries and collaboration opportunities:
|
| 238 |
+
- Organization: Algo Science Academy
|
| 239 |
+
- Lead Developer: Shahrear Hossain Shawon
|
| 240 |
+
- Email: contact@algoscienceacademy.com
|
| 241 |
+
- Website: https://algoscienceacademy.com
|
cogenbai.egg-info/SOURCES.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
README.md
|
| 2 |
+
setup.py
|
| 3 |
+
cogenbai/__init__.py
|
| 4 |
+
cogenbai/config.py
|
| 5 |
+
cogenbai.egg-info/PKG-INFO
|
| 6 |
+
cogenbai.egg-info/SOURCES.txt
|
| 7 |
+
cogenbai.egg-info/dependency_links.txt
|
| 8 |
+
cogenbai.egg-info/entry_points.txt
|
| 9 |
+
cogenbai.egg-info/requires.txt
|
| 10 |
+
cogenbai.egg-info/top_level.txt
|
| 11 |
+
tests/test_model.py
|
cogenbai.egg-info/dependency_links.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
cogenbai.egg-info/entry_points.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[console_scripts]
|
| 2 |
+
cogenbai = cogenbai.cli.main:cli
|
cogenbai.egg-info/requires.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch>=1.9.0
|
| 2 |
+
transformers>=4.11.0
|
| 3 |
+
pyttsx3>=2.90
|
| 4 |
+
fastapi>=0.68.0
|
| 5 |
+
uvicorn>=0.15.0
|
| 6 |
+
click>=8.0.0
|
| 7 |
+
autopep8>=1.5.7
|
| 8 |
+
black>=21.5b2
|
| 9 |
+
yapf>=0.31.0
|
| 10 |
+
websockets>=10.0
|
| 11 |
+
python-socketio>=5.5.0
|
cogenbai.egg-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
cogenbai
|
cogenbai/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .core.model import CogenBAI
|
| 2 |
+
from .voice.synthesizer import VoiceSynthesizer
|
| 3 |
+
from .languages.generator import LanguageGenerator
|
| 4 |
+
from .debug.analyzer import CodeAnalyzer
|
| 5 |
+
from .config import CogenConfig
|
| 6 |
+
from .api.server import app as api_app
|
| 7 |
+
|
| 8 |
+
__version__ = "0.1.0"
|
| 9 |
+
|
| 10 |
+
__all__ = ['CogenBAI', 'VoiceSynthesizer', 'LanguageGenerator', 'CodeAnalyzer', 'CogenConfig', 'api_app']
|
cogenbai/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (547 Bytes). View file
|
|
|
cogenbai/api/middleware.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
from fastapi import Request
|
| 3 |
+
import logging
|
| 4 |
+
|
| 5 |
+
logging.basicConfig(level=logging.INFO)
|
| 6 |
+
logger = logging.getLogger(__name__)
|
| 7 |
+
|
| 8 |
+
async def log_request_middleware(request: Request, call_next):
|
| 9 |
+
start_time = time.time()
|
| 10 |
+
response = await call_next(request)
|
| 11 |
+
process_time = time.time() - start_time
|
| 12 |
+
logger.info(f"{request.method} {request.url.path} - {process_time:.2f}s")
|
| 13 |
+
return response
|
cogenbai/api/server.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException, WebSocket, WebSocketDisconnect, Depends
|
| 2 |
+
from fastapi.security import OAuth2PasswordBearer
|
| 3 |
+
from pydantic import BaseModel
|
| 4 |
+
from typing import Optional, Dict, Any
|
| 5 |
+
|
| 6 |
+
from ..core.model import CogenBAI
|
| 7 |
+
from ..languages.generator import LanguageGenerator
|
| 8 |
+
from ..collaboration.session import SessionManager
|
| 9 |
+
from ..collaboration.websocket import collaboration_manager
|
| 10 |
+
from ..review.analyzer import CodeReviewAnalyzer
|
| 11 |
+
from ..testing.generator import TestGenerator
|
| 12 |
+
|
| 13 |
+
app = FastAPI(title="COGENBAI API")
|
| 14 |
+
model = CogenBAI()
|
| 15 |
+
lang_generator = LanguageGenerator()
|
| 16 |
+
session_manager = SessionManager()
|
| 17 |
+
code_reviewer = CodeReviewAnalyzer()
|
| 18 |
+
test_generator = TestGenerator()
|
| 19 |
+
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
| 20 |
+
|
| 21 |
+
class CodeRequest(BaseModel):
|
| 22 |
+
prompt: str
|
| 23 |
+
language: str
|
| 24 |
+
framework: Optional[str] = None
|
| 25 |
+
max_length: Optional[int] = 1024
|
| 26 |
+
temperature: float = 0.7
|
| 27 |
+
|
| 28 |
+
@app.post("/generate")
|
| 29 |
+
async def generate_code(request: CodeRequest, token: str = Depends(oauth2_scheme)) -> Dict[str, Any]:
|
| 30 |
+
try:
|
| 31 |
+
code = model.generate_code(
|
| 32 |
+
prompt=request.prompt,
|
| 33 |
+
language=request.language,
|
| 34 |
+
max_length=request.max_length,
|
| 35 |
+
temperature=request.temperature
|
| 36 |
+
)
|
| 37 |
+
return {"status": "success", "code": code}
|
| 38 |
+
except Exception as e:
|
| 39 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 40 |
+
|
| 41 |
+
@app.get("/supported-languages")
|
| 42 |
+
async def get_supported_languages():
|
| 43 |
+
return {"languages": list(lang_generator.language_configs.keys())}
|
| 44 |
+
|
| 45 |
+
@app.websocket("/ws/{session_id}/{user_id}")
|
| 46 |
+
async def websocket_endpoint(websocket: WebSocket, session_id: str, user_id: str):
|
| 47 |
+
await collaboration_manager.connect(session_id, websocket)
|
| 48 |
+
try:
|
| 49 |
+
session = await session_manager.join_session(session_id, user_id)
|
| 50 |
+
if not session:
|
| 51 |
+
await websocket.close()
|
| 52 |
+
return
|
| 53 |
+
|
| 54 |
+
while True:
|
| 55 |
+
data = await websocket.receive_json()
|
| 56 |
+
if data["type"] == "code_update":
|
| 57 |
+
await session_manager.update_code(session_id, data["code"])
|
| 58 |
+
await collaboration_manager.broadcast(session_id, {
|
| 59 |
+
"type": "code_update",
|
| 60 |
+
"code": data["code"],
|
| 61 |
+
"user_id": user_id
|
| 62 |
+
})
|
| 63 |
+
except WebSocketDisconnect:
|
| 64 |
+
await collaboration_manager.disconnect(session_id, websocket)
|
| 65 |
+
|
| 66 |
+
@app.post("/sessions/create")
|
| 67 |
+
async def create_session(user_id: str):
|
| 68 |
+
session_id = f"session_{len(session_manager.sessions) + 1}"
|
| 69 |
+
session = await session_manager.create_session(session_id, user_id)
|
| 70 |
+
return session.to_dict()
|
| 71 |
+
|
| 72 |
+
@app.post("/review")
|
| 73 |
+
async def review_code(code: str, language: str) -> Dict[str, Any]:
|
| 74 |
+
try:
|
| 75 |
+
review_results = code_reviewer.review_code(code, language)
|
| 76 |
+
return {"status": "success", "review": review_results}
|
| 77 |
+
except Exception as e:
|
| 78 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 79 |
+
|
| 80 |
+
@app.post("/generate-tests")
|
| 81 |
+
async def generate_tests(code: str, language: str, test_type: str = 'unit') -> Dict[str, str]:
|
| 82 |
+
try:
|
| 83 |
+
tests = test_generator.generate_tests(code, language, test_type)
|
| 84 |
+
return {"status": "success", "tests": tests}
|
| 85 |
+
except Exception as e:
|
| 86 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 87 |
+
|
| 88 |
+
@app.post("/projects/create")
|
| 89 |
+
async def create_project(
|
| 90 |
+
name: str,
|
| 91 |
+
language: str,
|
| 92 |
+
framework: str,
|
| 93 |
+
initial_description: str
|
| 94 |
+
) -> Dict[str, Any]:
|
| 95 |
+
project_id = f"proj_{int(time.time())}"
|
| 96 |
+
project = ProjectState(
|
| 97 |
+
project_id=project_id,
|
| 98 |
+
name=name,
|
| 99 |
+
language=language,
|
| 100 |
+
framework=framework,
|
| 101 |
+
status="active",
|
| 102 |
+
completion_percentage=0.0,
|
| 103 |
+
last_modified=datetime.now(),
|
| 104 |
+
code_snippets={},
|
| 105 |
+
dependencies=[]
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
if model.project_tracker.create_project(project):
|
| 109 |
+
initial_code = model.generate_code(initial_description, language, framework)
|
| 110 |
+
project.code_snippets["initial"] = initial_code
|
| 111 |
+
model.project_tracker.update_project(
|
| 112 |
+
project_id,
|
| 113 |
+
{"code_snippets": json.dumps(project.code_snippets)}
|
| 114 |
+
)
|
| 115 |
+
return {"status": "success", "project_id": project_id, "code": initial_code}
|
| 116 |
+
|
| 117 |
+
raise HTTPException(status_code=500, detail="Failed to create project")
|
| 118 |
+
|
| 119 |
+
@app.post("/projects/{project_id}/continue")
|
| 120 |
+
async def continue_project(
|
| 121 |
+
project_id: str,
|
| 122 |
+
feature_description: str
|
| 123 |
+
) -> Dict[str, Any]:
|
| 124 |
+
try:
|
| 125 |
+
new_code = model.continue_project(project_id, feature_description)
|
| 126 |
+
return {"status": "success", "code": new_code}
|
| 127 |
+
except Exception as e:
|
| 128 |
+
raise HTTPException(status_code=500, detail=str(e))
|
cogenbai/cli/main.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import click
|
| 2 |
+
from ..core.model import CogenBAI
|
| 3 |
+
from ..languages.generator import LanguageGenerator
|
| 4 |
+
from ..config import CogenConfig
|
| 5 |
+
|
| 6 |
+
@click.group()
|
| 7 |
+
def cli():
|
| 8 |
+
"""COGENBAI Command Line Interface"""
|
| 9 |
+
pass
|
| 10 |
+
|
| 11 |
+
@cli.command()
|
| 12 |
+
@click.argument('prompt')
|
| 13 |
+
@click.option('--language', '-l', required=True, help='Target programming language')
|
| 14 |
+
@click.option('--framework', '-f', help='Framework to use')
|
| 15 |
+
def generate(prompt: str, language: str, framework: str = None):
|
| 16 |
+
"""Generate code from a prompt"""
|
| 17 |
+
model = CogenBAI()
|
| 18 |
+
result = model.generate_code(prompt, language)
|
| 19 |
+
click.echo(result)
|
| 20 |
+
|
| 21 |
+
@cli.command()
|
| 22 |
+
def list_languages():
|
| 23 |
+
"""List supported programming languages"""
|
| 24 |
+
generator = LanguageGenerator()
|
| 25 |
+
for lang, config in generator.language_configs.items():
|
| 26 |
+
click.echo(f"\n{lang}:")
|
| 27 |
+
click.echo(f" Frameworks: {', '.join(config['frameworks'])}")
|
| 28 |
+
click.echo(f" Package Manager: {config['package_manager']}")
|
| 29 |
+
|
| 30 |
+
@cli.command()
|
| 31 |
+
@click.argument('project_name')
|
| 32 |
+
@click.option('--template', '-t', default='python_project', help='Project template to use')
|
| 33 |
+
@click.option('--description', '-d', default='A new project', help='Project description')
|
| 34 |
+
def scaffold(project_name: str, template: str, description: str):
|
| 35 |
+
"""Generate a new project scaffold"""
|
| 36 |
+
from ..templates.registry import TemplateRegistry
|
| 37 |
+
registry = TemplateRegistry()
|
| 38 |
+
template_data = registry.get_template('scaffolds', template)
|
| 39 |
+
if not template_data:
|
| 40 |
+
click.echo(f"Template {template} not found")
|
| 41 |
+
return
|
| 42 |
+
|
| 43 |
+
# Create project structure
|
| 44 |
+
import os
|
| 45 |
+
import json
|
| 46 |
+
structure = json.loads(template_data)['structure']
|
| 47 |
+
base_path = os.path.join(os.getcwd(), project_name)
|
| 48 |
+
|
| 49 |
+
for path, content in _walk_structure(structure):
|
| 50 |
+
full_path = os.path.join(base_path, path)
|
| 51 |
+
os.makedirs(os.path.dirname(full_path), exist_ok=True)
|
| 52 |
+
|
| 53 |
+
if isinstance(content, str):
|
| 54 |
+
with open(full_path, 'w') as f:
|
| 55 |
+
f.write(content.replace('${project_name}', project_name)
|
| 56 |
+
.replace('${project_description}', description))
|
| 57 |
+
|
| 58 |
+
def _walk_structure(structure, parent=""):
|
| 59 |
+
for name, content in structure.items():
|
| 60 |
+
path = os.path.join(parent, name)
|
| 61 |
+
if isinstance(content, dict):
|
| 62 |
+
yield from _walk_structure(content, path)
|
| 63 |
+
else:
|
| 64 |
+
yield path, content
|
| 65 |
+
|
| 66 |
+
if __name__ == '__main__':
|
| 67 |
+
cli()
|
cogenbai/collaboration/session.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Set, Optional
|
| 2 |
+
from dataclasses import dataclass, field
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
import asyncio
|
| 5 |
+
import json
|
| 6 |
+
|
| 7 |
+
@dataclass
|
| 8 |
+
class CodeSession:
|
| 9 |
+
id: str
|
| 10 |
+
code: str = ""
|
| 11 |
+
language: str = "python"
|
| 12 |
+
participants: Set[str] = field(default_factory=set)
|
| 13 |
+
created_at: datetime = field(default_factory=datetime.now)
|
| 14 |
+
|
| 15 |
+
def to_dict(self) -> dict:
|
| 16 |
+
return {
|
| 17 |
+
"id": self.id,
|
| 18 |
+
"code": self.code,
|
| 19 |
+
"language": self.language,
|
| 20 |
+
"participants": list(self.participants),
|
| 21 |
+
"created_at": self.created_at.isoformat()
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
class SessionManager:
|
| 25 |
+
def __init__(self):
|
| 26 |
+
self.sessions: Dict[str, CodeSession] = {}
|
| 27 |
+
self.user_connections: Dict[str, Set[str]] = {}
|
| 28 |
+
|
| 29 |
+
async def create_session(self, session_id: str, creator: str) -> CodeSession:
|
| 30 |
+
session = CodeSession(id=session_id)
|
| 31 |
+
session.participants.add(creator)
|
| 32 |
+
self.sessions[session_id] = session
|
| 33 |
+
return session
|
| 34 |
+
|
| 35 |
+
async def join_session(self, session_id: str, user_id: str) -> Optional[CodeSession]:
|
| 36 |
+
if session := self.sessions.get(session_id):
|
| 37 |
+
session.participants.add(user_id)
|
| 38 |
+
if user_id not in self.user_connections:
|
| 39 |
+
self.user_connections[user_id] = set()
|
| 40 |
+
self.user_connections[user_id].add(session_id)
|
| 41 |
+
return session
|
| 42 |
+
return None
|
| 43 |
+
|
| 44 |
+
async def update_code(self, session_id: str, code: str) -> bool:
|
| 45 |
+
if session := self.sessions.get(session_id):
|
| 46 |
+
session.code = code
|
| 47 |
+
return True
|
| 48 |
+
return False
|
cogenbai/collaboration/websocket.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import WebSocket, WebSocketDisconnect
|
| 2 |
+
from typing import Dict, Set
|
| 3 |
+
import json
|
| 4 |
+
import asyncio
|
| 5 |
+
|
| 6 |
+
class CollaborationManager:
|
| 7 |
+
def __init__(self):
|
| 8 |
+
self.active_connections: Dict[str, Set[WebSocket]] = {}
|
| 9 |
+
|
| 10 |
+
async def connect(self, session_id: str, websocket: WebSocket):
|
| 11 |
+
await websocket.accept()
|
| 12 |
+
if session_id not in self.active_connections:
|
| 13 |
+
self.active_connections[session_id] = set()
|
| 14 |
+
self.active_connections[session_id].add(websocket)
|
| 15 |
+
|
| 16 |
+
async def disconnect(self, session_id: str, websocket: WebSocket):
|
| 17 |
+
self.active_connections[session_id].remove(websocket)
|
| 18 |
+
|
| 19 |
+
async def broadcast(self, session_id: str, message: dict):
|
| 20 |
+
if session_id in self.active_connections:
|
| 21 |
+
for connection in self.active_connections[session_id]:
|
| 22 |
+
await connection.send_json(message)
|
| 23 |
+
|
| 24 |
+
collaboration_manager = CollaborationManager()
|
cogenbai/config.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dataclasses import dataclass, field
|
| 2 |
+
from typing import Dict, Any, List
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
@dataclass
|
| 7 |
+
class CogenConfig:
|
| 8 |
+
# Model settings
|
| 9 |
+
model_name: str = "codegen-16B-multi"
|
| 10 |
+
max_length: int = 2048
|
| 11 |
+
temperature: float = 0.8
|
| 12 |
+
top_p: float = 0.95
|
| 13 |
+
|
| 14 |
+
# Language settings
|
| 15 |
+
default_language: str = "python"
|
| 16 |
+
supported_languages: List[str] = field(default_factory=lambda: [
|
| 17 |
+
"python",
|
| 18 |
+
"javascript",
|
| 19 |
+
"typescript",
|
| 20 |
+
"java",
|
| 21 |
+
"rust",
|
| 22 |
+
"go",
|
| 23 |
+
"cpp",
|
| 24 |
+
"csharp",
|
| 25 |
+
"php",
|
| 26 |
+
"ruby",
|
| 27 |
+
"kotlin",
|
| 28 |
+
"swift",
|
| 29 |
+
"dart" # Added dart
|
| 30 |
+
])
|
| 31 |
+
|
| 32 |
+
code_style: Dict[str, str] = field(default_factory=lambda: {
|
| 33 |
+
"python": "black",
|
| 34 |
+
"javascript": "prettier",
|
| 35 |
+
"typescript": "prettier",
|
| 36 |
+
"java": "google",
|
| 37 |
+
"rust": "rustfmt",
|
| 38 |
+
"go": "gofmt",
|
| 39 |
+
"cpp": "clang-format",
|
| 40 |
+
"csharp": "dotnet-format",
|
| 41 |
+
"php": "php-cs-fixer",
|
| 42 |
+
"ruby": "rubocop",
|
| 43 |
+
"kotlin": "ktlint",
|
| 44 |
+
"swift": "swiftformat",
|
| 45 |
+
"dart": "dart format" # Added dart formatter
|
| 46 |
+
})
|
| 47 |
+
|
| 48 |
+
language_extensions: Dict[str, List[str]] = field(default_factory=lambda: {
|
| 49 |
+
"python": [".py", ".pyi", ".pyx"],
|
| 50 |
+
"javascript": [".js", ".jsx", ".mjs"],
|
| 51 |
+
"typescript": [".ts", ".tsx"],
|
| 52 |
+
"java": [".java"],
|
| 53 |
+
"rust": [".rs"],
|
| 54 |
+
"go": [".go"],
|
| 55 |
+
"cpp": [".cpp", ".hpp", ".cc", ".h"],
|
| 56 |
+
"csharp": [".cs"],
|
| 57 |
+
"php": [".php"],
|
| 58 |
+
"ruby": [".rb"],
|
| 59 |
+
"kotlin": [".kt"],
|
| 60 |
+
"swift": [".swift"],
|
| 61 |
+
"dart": [".dart"] # Added dart extension
|
| 62 |
+
})
|
| 63 |
+
|
| 64 |
+
# Generation settings
|
| 65 |
+
add_comments: bool = True
|
| 66 |
+
add_type_hints: bool = True
|
| 67 |
+
add_docstrings: bool = True
|
| 68 |
+
|
| 69 |
+
# Performance settings
|
| 70 |
+
use_gpu: bool = True
|
| 71 |
+
batch_size: int = 1
|
| 72 |
+
num_workers: int = 4
|
| 73 |
+
|
| 74 |
+
@classmethod
|
| 75 |
+
def load(cls, config_path: str) -> 'CogenConfig':
|
| 76 |
+
if os.path.exists(config_path):
|
| 77 |
+
with open(config_path, 'r') as f:
|
| 78 |
+
config_dict = json.load(f)
|
| 79 |
+
return cls(**config_dict)
|
| 80 |
+
return cls()
|
| 81 |
+
|
| 82 |
+
def save(self, config_path: str):
|
| 83 |
+
with open(config_path, 'w') as f:
|
| 84 |
+
json.dump(self.__dict__, f, indent=2)
|
cogenbai/core/__pycache__/model.cpython-313.pyc
ADDED
|
Binary file (8.84 kB). View file
|
|
|
cogenbai/core/config.py
ADDED
|
File without changes
|
cogenbai/core/model.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from torch import nn
|
| 3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
+
from typing import Optional, Dict, Any
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
from ..languages.generator import LanguageGenerator
|
| 7 |
+
|
| 8 |
+
class CogenBAI(nn.Module):
|
| 9 |
+
"""
|
| 10 |
+
CogenBAI: Advanced Code Generation Model
|
| 11 |
+
|
| 12 |
+
Created by Algo Science Academy
|
| 13 |
+
Lead Developer: Shahrear Hossain Shawon
|
| 14 |
+
Organization: Algo Science Academy
|
| 15 |
+
Academic Background: International Islamic University Chittagong
|
| 16 |
+
|
| 17 |
+
This model is designed to generate high-quality code across multiple programming
|
| 18 |
+
languages with support for various frameworks and coding patterns. It represents
|
| 19 |
+
a significant advancement in AI-assisted software development, combining modern
|
| 20 |
+
language support with intelligent code generation capabilities.
|
| 21 |
+
|
| 22 |
+
Copyright (c) 2024 Algo Science Academy
|
| 23 |
+
All rights reserved.
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
# Model metadata
|
| 27 |
+
__author__ = "Shahrear Hossain Shawon"
|
| 28 |
+
__organization__ = "Algo Science Academy"
|
| 29 |
+
__version__ = "1.0.0"
|
| 30 |
+
__license__ = "Proprietary"
|
| 31 |
+
__copyright__ = f"Copyright (c) {datetime.now().year} Algo Science Academy"
|
| 32 |
+
__contact__ = {
|
| 33 |
+
"organization": "Algo Science Academy",
|
| 34 |
+
"developer": "Shahrear Hossain Shawon",
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
def __init__(self, model_name: str = "codegen-16B-multi", device: str = "cuda"):
|
| 38 |
+
"""
|
| 39 |
+
Initialize the CogenBAI model.
|
| 40 |
+
|
| 41 |
+
Developed by Algo Science Academy under the leadership of
|
| 42 |
+
Shahrear Hossain Shawon from International Islamic University Chittagong.
|
| 43 |
+
"""
|
| 44 |
+
super().__init__()
|
| 45 |
+
self.device = "cuda" if torch.cuda.is_available() and device == "cuda" else "cpu"
|
| 46 |
+
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 47 |
+
self.model = AutoModelForCausalLM.from_pretrained(model_name).to(self.device)
|
| 48 |
+
self.lang_generator = LanguageGenerator()
|
| 49 |
+
self.project_tracker = ProjectTracker()
|
| 50 |
+
from ..languages.modern_frameworks import ModernFrameworkSupport
|
| 51 |
+
self.modern_frameworks = ModernFrameworkSupport()
|
| 52 |
+
|
| 53 |
+
@classmethod
|
| 54 |
+
def get_model_info(cls) -> Dict[str, Any]:
|
| 55 |
+
"""
|
| 56 |
+
Get information about the model and its creators.
|
| 57 |
+
"""
|
| 58 |
+
return {
|
| 59 |
+
"model_name": "CogenBAI",
|
| 60 |
+
"version": cls.__version__,
|
| 61 |
+
"author": cls.__author__,
|
| 62 |
+
"organization": cls.__organization__,
|
| 63 |
+
"institution": cls.__contact__["institution"],
|
| 64 |
+
"license": cls.__license__,
|
| 65 |
+
"copyright": cls.__copyright__,
|
| 66 |
+
"contact": cls.__contact__
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
def generate_code(self, prompt: str, language: str,
|
| 70 |
+
framework: Optional[str] = None,
|
| 71 |
+
max_length: int = 1024,
|
| 72 |
+
temperature: float = 0.7,
|
| 73 |
+
top_p: float = 0.95) -> str:
|
| 74 |
+
"""
|
| 75 |
+
Generate code based on the given prompt and parameters.
|
| 76 |
+
|
| 77 |
+
Args:
|
| 78 |
+
prompt (str): The coding task description
|
| 79 |
+
language (str): Target programming language
|
| 80 |
+
framework (Optional[str]): Specific framework to use
|
| 81 |
+
max_length (int): Maximum length of generated code
|
| 82 |
+
temperature (float): Sampling temperature
|
| 83 |
+
top_p (float): Nucleus sampling parameter
|
| 84 |
+
|
| 85 |
+
Returns:
|
| 86 |
+
str: Generated code
|
| 87 |
+
"""
|
| 88 |
+
# Validate language and framework
|
| 89 |
+
lang_config = self.lang_generator.get_language_config(language)
|
| 90 |
+
if not lang_config:
|
| 91 |
+
raise ValueError(f"Unsupported language: {language}")
|
| 92 |
+
|
| 93 |
+
if framework and framework not in lang_config["frameworks"]:
|
| 94 |
+
raise ValueError(f"Unsupported framework {framework} for {language}")
|
| 95 |
+
|
| 96 |
+
# Prepare prompt with language and framework context
|
| 97 |
+
context = f"Generate {language} code"
|
| 98 |
+
if framework:
|
| 99 |
+
context += f" using {framework}"
|
| 100 |
+
formatted_prompt = f"{context}:\n{prompt}\n\nSolution:\n"
|
| 101 |
+
|
| 102 |
+
# Generate code
|
| 103 |
+
inputs = self.tokenizer(formatted_prompt, return_tensors="pt").to(self.device)
|
| 104 |
+
outputs = self.model.generate(
|
| 105 |
+
inputs.input_ids,
|
| 106 |
+
max_length=max_length,
|
| 107 |
+
temperature=temperature,
|
| 108 |
+
top_p=top_p,
|
| 109 |
+
do_sample=True,
|
| 110 |
+
pad_token_id=self.tokenizer.eos_token_id,
|
| 111 |
+
num_return_sequences=1
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
generated_code = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 115 |
+
return self._format_code(generated_code, language)
|
| 116 |
+
|
| 117 |
+
def continue_project(self, project_id: str, new_feature_description: str) -> str:
|
| 118 |
+
"""Continue development of an existing project."""
|
| 119 |
+
project = self.project_tracker.get_project(project_id)
|
| 120 |
+
if not project:
|
| 121 |
+
raise ValueError(f"Project {project_id} not found")
|
| 122 |
+
|
| 123 |
+
# Generate context from existing code
|
| 124 |
+
context = self._build_project_context(project)
|
| 125 |
+
|
| 126 |
+
# Generate new code
|
| 127 |
+
new_code = self.generate_code(
|
| 128 |
+
prompt=f"{context}\n\nAdd feature: {new_feature_description}",
|
| 129 |
+
language=project.language,
|
| 130 |
+
framework=project.framework
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
# Update project state
|
| 134 |
+
project.code_snippets[new_feature_description] = new_code
|
| 135 |
+
project.last_modified = datetime.now()
|
| 136 |
+
self.project_tracker.update_project(project_id, {
|
| 137 |
+
"code_snippets": json.dumps(project.code_snippets),
|
| 138 |
+
"last_modified": project.last_modified.isoformat()
|
| 139 |
+
})
|
| 140 |
+
|
| 141 |
+
return new_code
|
| 142 |
+
|
| 143 |
+
def generate_deployment_config(self, project_id: str, platform: str) -> Dict[str, Any]:
|
| 144 |
+
"""Generate deployment configuration for modern frameworks."""
|
| 145 |
+
project = self.project_tracker.get_project(project_id)
|
| 146 |
+
if not project:
|
| 147 |
+
raise ValueError(f"Project {project_id} not found")
|
| 148 |
+
|
| 149 |
+
try:
|
| 150 |
+
deploy_config = self.modern_frameworks.get_deployment_config(
|
| 151 |
+
project.framework, platform
|
| 152 |
+
)
|
| 153 |
+
return deploy_config
|
| 154 |
+
except ValueError as e:
|
| 155 |
+
raise ValueError(f"Deployment configuration failed: {str(e)}")
|
| 156 |
+
|
| 157 |
+
def _build_project_context(self, project: ProjectState) -> str:
|
| 158 |
+
"""Build context from existing project code."""
|
| 159 |
+
context = f"Project: {project.name}\nLanguage: {project.language}\nFramework: {project.framework}\n\n"
|
| 160 |
+
context += "Existing code:\n"
|
| 161 |
+
for feature, code in project.code_snippets.items():
|
| 162 |
+
context += f"\n# Feature: {feature}\n{code}\n"
|
| 163 |
+
return context
|
| 164 |
+
|
| 165 |
+
def _format_code(self, code: str, language: str) -> str:
|
| 166 |
+
"""Format the generated code according to language standards."""
|
| 167 |
+
# Remove the prompt from the generated code
|
| 168 |
+
if "Solution:" in code:
|
| 169 |
+
code = code.split("Solution:")[-1].strip()
|
| 170 |
+
|
| 171 |
+
# Add language-specific formatting
|
| 172 |
+
if language == "python":
|
| 173 |
+
import black
|
| 174 |
+
try:
|
| 175 |
+
return black.format_str(code, mode=black.FileMode())
|
| 176 |
+
except:
|
| 177 |
+
return code
|
| 178 |
+
|
| 179 |
+
return code
|
cogenbai/debug/analyzer.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ast
|
| 2 |
+
from typing import List, Dict
|
| 3 |
+
|
| 4 |
+
class CodeAnalyzer:
|
| 5 |
+
def __init__(self):
|
| 6 |
+
self.issues = []
|
| 7 |
+
|
| 8 |
+
def analyze_python(self, code: str) -> List[Dict]:
|
| 9 |
+
try:
|
| 10 |
+
tree = ast.parse(code)
|
| 11 |
+
return self._analyze_ast(tree)
|
| 12 |
+
except SyntaxError as e:
|
| 13 |
+
return [{"type": "syntax_error", "message": str(e)}]
|
| 14 |
+
|
| 15 |
+
def _analyze_ast(self, tree: ast.AST) -> List[Dict]:
|
| 16 |
+
issues = []
|
| 17 |
+
for node in ast.walk(tree):
|
| 18 |
+
if isinstance(node, ast.Try):
|
| 19 |
+
issues.append({
|
| 20 |
+
"type": "suggestion",
|
| 21 |
+
"message": "Consider adding specific exception handlers"
|
| 22 |
+
})
|
| 23 |
+
return issues
|
cogenbai/languages/generator.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Optional
|
| 2 |
+
|
| 3 |
+
class LanguageGenerator:
|
| 4 |
+
def __init__(self):
|
| 5 |
+
self.language_configs: Dict[str, dict] = {
|
| 6 |
+
"python": {
|
| 7 |
+
"frameworks": ["django", "flask", "fastapi", "pyramid", "aiohttp", "tornado"],
|
| 8 |
+
"package_manager": "pip/poetry/conda",
|
| 9 |
+
"file_extension": ".py",
|
| 10 |
+
"testing_frameworks": ["pytest", "unittest", "nose"],
|
| 11 |
+
"doc_format": "docstring",
|
| 12 |
+
},
|
| 13 |
+
"javascript": {
|
| 14 |
+
"frameworks": [
|
| 15 |
+
"react", "vue", "angular", "next.js", "nuxt.js", "express",
|
| 16 |
+
"astro", "sveltekit", "remix", "solid", "qwik"
|
| 17 |
+
],
|
| 18 |
+
"package_manager": "npm/yarn/pnpm",
|
| 19 |
+
"file_extension": ".js",
|
| 20 |
+
"testing_frameworks": ["jest", "vitest", "cypress", "playwright"],
|
| 21 |
+
"doc_format": "jsdoc",
|
| 22 |
+
"bundlers": ["vite", "webpack", "rollup", "esbuild", "turbopack"]
|
| 23 |
+
},
|
| 24 |
+
"typescript": {
|
| 25 |
+
"frameworks": [
|
| 26 |
+
"react", "vue", "angular", "next.js", "nest.js",
|
| 27 |
+
"astro", "sveltekit", "remix", "solid", "qwik"
|
| 28 |
+
],
|
| 29 |
+
"package_manager": "npm/yarn/pnpm",
|
| 30 |
+
"file_extension": ".ts",
|
| 31 |
+
"testing_frameworks": ["jest", "vitest", "cypress", "playwright"],
|
| 32 |
+
"doc_format": "tsdoc",
|
| 33 |
+
"bundlers": ["vite", "webpack", "rollup", "esbuild", "turbopack"]
|
| 34 |
+
},
|
| 35 |
+
"rust": {
|
| 36 |
+
"frameworks": ["actix", "rocket", "warp", "yew"],
|
| 37 |
+
"package_manager": "cargo",
|
| 38 |
+
"file_extension": ".rs",
|
| 39 |
+
"testing_frameworks": ["cargo test"],
|
| 40 |
+
"doc_format": "rustdoc",
|
| 41 |
+
},
|
| 42 |
+
"go": {
|
| 43 |
+
"frameworks": ["gin", "echo", "fiber", "buffalo"],
|
| 44 |
+
"package_manager": "go mod",
|
| 45 |
+
"file_extension": ".go",
|
| 46 |
+
"testing_frameworks": ["testing"],
|
| 47 |
+
"doc_format": "godoc",
|
| 48 |
+
},
|
| 49 |
+
"java": {
|
| 50 |
+
"frameworks": ["spring", "quarkus", "micronaut", "jakarta ee"],
|
| 51 |
+
"package_manager": "maven/gradle",
|
| 52 |
+
"file_extension": ".java",
|
| 53 |
+
"testing_frameworks": ["junit", "testng"],
|
| 54 |
+
"doc_format": "javadoc",
|
| 55 |
+
},
|
| 56 |
+
"kotlin": {
|
| 57 |
+
"frameworks": ["spring", "ktor", "compose"],
|
| 58 |
+
"package_manager": "maven/gradle",
|
| 59 |
+
"file_extension": ".kt",
|
| 60 |
+
"testing_frameworks": ["junit", "kotlintest"],
|
| 61 |
+
"doc_format": "kdoc",
|
| 62 |
+
},
|
| 63 |
+
"cpp": {
|
| 64 |
+
"frameworks": ["qt", "boost", "opencv", "llvm"],
|
| 65 |
+
"package_manager": "vcpkg/conan/cmake",
|
| 66 |
+
"file_extension": ".cpp",
|
| 67 |
+
"testing_frameworks": ["gtest", "catch2", "doctest"],
|
| 68 |
+
"doc_format": "doxygen",
|
| 69 |
+
"ide_support": ["visual-studio", "clion", "qt-creator"]
|
| 70 |
+
},
|
| 71 |
+
"dart": {
|
| 72 |
+
"frameworks": ["flutter", "shelf", "aqueduct"],
|
| 73 |
+
"package_manager": "pub",
|
| 74 |
+
"file_extension": ".dart",
|
| 75 |
+
"testing_frameworks": ["test", "flutter_test"],
|
| 76 |
+
"doc_format": "dartdoc",
|
| 77 |
+
"ide_support": ["android-studio", "vscode"]
|
| 78 |
+
},
|
| 79 |
+
"swift": {
|
| 80 |
+
"frameworks": ["swiftui", "vapor", "perfect"],
|
| 81 |
+
"package_manager": "swift-package-manager/cocoapods",
|
| 82 |
+
"file_extension": ".swift",
|
| 83 |
+
"testing_frameworks": ["xctest"],
|
| 84 |
+
"doc_format": "markdown",
|
| 85 |
+
"ide_support": ["xcode"]
|
| 86 |
+
},
|
| 87 |
+
"matlab": {
|
| 88 |
+
"frameworks": ["simulink", "app-designer"],
|
| 89 |
+
"package_manager": "matlab-package-installer",
|
| 90 |
+
"file_extension": ".m",
|
| 91 |
+
"testing_frameworks": ["matlab.unittest"],
|
| 92 |
+
"doc_format": "matlab-doc",
|
| 93 |
+
"ide_support": ["matlab-ide"]
|
| 94 |
+
},
|
| 95 |
+
"bash": {
|
| 96 |
+
"frameworks": ["bash-it", "oh-my-bash"],
|
| 97 |
+
"package_manager": "apt/yum/brew",
|
| 98 |
+
"file_extension": ".sh",
|
| 99 |
+
"testing_frameworks": ["bats", "shunit2"],
|
| 100 |
+
"doc_format": "man-pages",
|
| 101 |
+
"ide_support": ["vscode", "bash-ide"]
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
def get_language_config(self, language: str) -> Optional[dict]:
|
| 106 |
+
return self.language_configs.get(language.lower())
|
| 107 |
+
|
| 108 |
+
def generate_boilerplate(self, language: str, framework: str) -> str:
|
| 109 |
+
config = self.get_language_config(language)
|
| 110 |
+
if not config or framework not in config["frameworks"]:
|
| 111 |
+
raise ValueError(f"Unsupported language or framework: {language}/{framework}")
|
| 112 |
+
|
| 113 |
+
# Add framework-specific boilerplate generation here
|
| 114 |
+
return f"// Generated {framework} boilerplate for {language}"
|
| 115 |
+
|
| 116 |
+
def generate_hello_world(self, language: str) -> str:
|
| 117 |
+
templates = {
|
| 118 |
+
"python": 'print("Hello, World!")',
|
| 119 |
+
"javascript": 'console.log("Hello, World!");',
|
| 120 |
+
"typescript": 'console.log("Hello, World!");',
|
| 121 |
+
"rust": 'fn main() {\n println!("Hello, World!");\n}',
|
| 122 |
+
"go": 'package main\n\nfunc main() {\n println("Hello, World!")\n}',
|
| 123 |
+
"java": 'public class Main {\n public static void main(String[] args) {\n System.out.println("Hello, World!");\n }\n}',
|
| 124 |
+
"kotlin": 'fun main() {\n println("Hello, World!")\n}'
|
| 125 |
+
}
|
| 126 |
+
return templates.get(language.lower(), "// Language not supported")
|
cogenbai/languages/modern_frameworks.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Optional
|
| 2 |
+
|
| 3 |
+
class ModernFrameworkSupport:
|
| 4 |
+
def __init__(self):
|
| 5 |
+
self.framework_configs = {
|
| 6 |
+
"astro": {
|
| 7 |
+
"package_manager": "npm/pnpm",
|
| 8 |
+
"setup_command": "npm create astro@latest",
|
| 9 |
+
"build_command": "npm run build",
|
| 10 |
+
"dev_command": "npm run dev",
|
| 11 |
+
"testing": ["vitest", "playwright"],
|
| 12 |
+
"deployment": ["vercel", "netlify", "cloudflare"]
|
| 13 |
+
},
|
| 14 |
+
"sveltekit": {
|
| 15 |
+
"package_manager": "npm/pnpm",
|
| 16 |
+
"setup_command": "npm create svelte@latest",
|
| 17 |
+
"build_command": "npm run build",
|
| 18 |
+
"dev_command": "npm run dev",
|
| 19 |
+
"testing": ["vitest", "playwright"],
|
| 20 |
+
"deployment": ["vercel", "netlify"]
|
| 21 |
+
},
|
| 22 |
+
"remix": {
|
| 23 |
+
"package_manager": "npm/pnpm",
|
| 24 |
+
"setup_command": "npx create-remix@latest",
|
| 25 |
+
"build_command": "npm run build",
|
| 26 |
+
"dev_command": "npm run dev",
|
| 27 |
+
"testing": ["vitest", "cypress"],
|
| 28 |
+
"deployment": ["vercel", "fly.io"]
|
| 29 |
+
},
|
| 30 |
+
"nextjs": {
|
| 31 |
+
"package_manager": "npm/pnpm",
|
| 32 |
+
"setup_command": "npx create-next-app@latest",
|
| 33 |
+
"build_command": "npm run build",
|
| 34 |
+
"dev_command": "npm run dev",
|
| 35 |
+
"testing": ["jest", "cypress"],
|
| 36 |
+
"deployment": ["vercel", "netlify"]
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
def get_deployment_config(self, framework: str, platform: str) -> Dict:
|
| 41 |
+
if framework not in self.framework_configs:
|
| 42 |
+
raise ValueError(f"Unsupported framework: {framework}")
|
| 43 |
+
|
| 44 |
+
if platform not in self.framework_configs[framework]["deployment"]:
|
| 45 |
+
raise ValueError(f"Unsupported deployment platform: {platform}")
|
| 46 |
+
|
| 47 |
+
return {
|
| 48 |
+
"platform": platform,
|
| 49 |
+
"framework": framework,
|
| 50 |
+
"config": self._get_platform_config(framework, platform)
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
def _get_platform_config(self, framework: str, platform: str) -> Dict:
|
| 54 |
+
configs = {
|
| 55 |
+
"vercel": {
|
| 56 |
+
"file": "vercel.json",
|
| 57 |
+
"content": {
|
| 58 |
+
"buildCommand": self.framework_configs[framework]["build_command"],
|
| 59 |
+
"devCommand": self.framework_configs[framework]["dev_command"],
|
| 60 |
+
"framework": framework
|
| 61 |
+
}
|
| 62 |
+
},
|
| 63 |
+
"netlify": {
|
| 64 |
+
"file": "netlify.toml",
|
| 65 |
+
"content": f"""
|
| 66 |
+
[build]
|
| 67 |
+
command = "{self.framework_configs[framework]['build_command']}"
|
| 68 |
+
publish = "dist"
|
| 69 |
+
"""
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
return configs.get(platform, {})
|
cogenbai/optimization/optimizer.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List, Dict, Any
|
| 2 |
+
import ast
|
| 3 |
+
import autopep8
|
| 4 |
+
import black
|
| 5 |
+
from yapf.yapflib.yapf_api import FormatCode
|
| 6 |
+
|
| 7 |
+
class CodeOptimizer:
|
| 8 |
+
def __init__(self):
|
| 9 |
+
self.formatters = {
|
| 10 |
+
'python': self._optimize_python,
|
| 11 |
+
'javascript': self._optimize_javascript
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
def optimize(self, code: str, language: str) -> str:
|
| 15 |
+
optimizer = self.formatters.get(language.lower())
|
| 16 |
+
if not optimizer:
|
| 17 |
+
return code
|
| 18 |
+
return optimizer(code)
|
| 19 |
+
|
| 20 |
+
def _optimize_python(self, code: str) -> str:
|
| 21 |
+
# First pass: Basic PEP 8 formatting
|
| 22 |
+
code = autopep8.fix_code(code)
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
# Second pass: Black formatting
|
| 26 |
+
code = black.format_str(code, mode=black.FileMode())
|
| 27 |
+
except:
|
| 28 |
+
pass
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
# Third pass: YAPF formatting
|
| 32 |
+
code, _ = FormatCode(code)
|
| 33 |
+
except:
|
| 34 |
+
pass
|
| 35 |
+
|
| 36 |
+
return code
|
| 37 |
+
|
| 38 |
+
def _optimize_javascript(self, code: str) -> str:
|
| 39 |
+
# Add JavaScript optimization logic here
|
| 40 |
+
return code
|
| 41 |
+
|
| 42 |
+
def analyze_complexity(self, code: str) -> Dict[str, Any]:
|
| 43 |
+
try:
|
| 44 |
+
tree = ast.parse(code)
|
| 45 |
+
return {
|
| 46 |
+
'cyclomatic_complexity': self._calculate_complexity(tree),
|
| 47 |
+
'line_count': len(code.splitlines()),
|
| 48 |
+
'function_count': len([node for node in ast.walk(tree)
|
| 49 |
+
if isinstance(node, ast.FunctionDef)])
|
| 50 |
+
}
|
| 51 |
+
except:
|
| 52 |
+
return {}
|
| 53 |
+
|
| 54 |
+
def _calculate_complexity(self, tree: ast.AST) -> int:
|
| 55 |
+
complexity = 1
|
| 56 |
+
for node in ast.walk(tree):
|
| 57 |
+
if isinstance(node, (ast.If, ast.While, ast.For, ast.ExceptHandler)):
|
| 58 |
+
complexity += 1
|
| 59 |
+
return complexity
|
cogenbai/review/analyzer.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List, Dict, Any
|
| 2 |
+
import ast
|
| 3 |
+
import re
|
| 4 |
+
|
| 5 |
+
class CodeReviewAnalyzer:
|
| 6 |
+
def __init__(self):
|
| 7 |
+
self.metrics = {
|
| 8 |
+
'complexity': self._analyze_complexity,
|
| 9 |
+
'naming': self._analyze_naming,
|
| 10 |
+
'documentation': self._analyze_documentation,
|
| 11 |
+
'security': self._analyze_security
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
def review_code(self, code: str, language: str) -> Dict[str, Any]:
|
| 15 |
+
results = {}
|
| 16 |
+
for metric_name, analyzer in self.metrics.items():
|
| 17 |
+
results[metric_name] = analyzer(code, language)
|
| 18 |
+
return results
|
| 19 |
+
|
| 20 |
+
def _analyze_complexity(self, code: str, language: str) -> Dict[str, Any]:
|
| 21 |
+
if language == 'python':
|
| 22 |
+
tree = ast.parse(code)
|
| 23 |
+
return {
|
| 24 |
+
'cyclomatic_complexity': self._count_branches(tree),
|
| 25 |
+
'cognitive_complexity': self._analyze_cognitive_complexity(tree)
|
| 26 |
+
}
|
| 27 |
+
return {}
|
| 28 |
+
|
| 29 |
+
def _analyze_naming(self, code: str, language: str) -> Dict[str, List[str]]:
|
| 30 |
+
issues = []
|
| 31 |
+
if language == 'python':
|
| 32 |
+
tree = ast.parse(code)
|
| 33 |
+
for node in ast.walk(tree):
|
| 34 |
+
if isinstance(node, ast.Name):
|
| 35 |
+
if not self._is_valid_name(node.id):
|
| 36 |
+
issues.append(f"Invalid name: {node.id}")
|
| 37 |
+
return {'issues': issues}
|
| 38 |
+
|
| 39 |
+
def _analyze_documentation(self, code: str, language: str) -> Dict[str, Any]:
|
| 40 |
+
doc_ratio = len(re.findall(r'"""[\s\S]*?"""|\'\'\'[\s\S]*?\'\'\'', code)) / max(1, len(code.splitlines()))
|
| 41 |
+
return {
|
| 42 |
+
'documentation_ratio': doc_ratio,
|
| 43 |
+
'has_module_docstring': code.lstrip().startswith('"""') or code.lstrip().startswith("'''")
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
def _analyze_security(self, code: str, language: str) -> Dict[str, List[str]]:
|
| 47 |
+
vulnerabilities = []
|
| 48 |
+
dangerous_patterns = {
|
| 49 |
+
'python': [
|
| 50 |
+
(r'eval\(', 'Dangerous eval() usage'),
|
| 51 |
+
(r'exec\(', 'Dangerous exec() usage'),
|
| 52 |
+
(r'os\.system\(', 'Unsafe system command execution')
|
| 53 |
+
]
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
for pattern, message in dangerous_patterns.get(language, []):
|
| 57 |
+
if re.search(pattern, code):
|
| 58 |
+
vulnerabilities.append(message)
|
| 59 |
+
return {'vulnerabilities': vulnerabilities}
|
| 60 |
+
|
| 61 |
+
def _count_branches(self, tree: ast.AST) -> int:
|
| 62 |
+
count = 0
|
| 63 |
+
for node in ast.walk(tree):
|
| 64 |
+
if isinstance(node, (ast.If, ast.For, ast.While, ast.Try)):
|
| 65 |
+
count += 1
|
| 66 |
+
return count
|
| 67 |
+
|
| 68 |
+
def _analyze_cognitive_complexity(self, tree: ast.AST) -> int:
|
| 69 |
+
complexity = 0
|
| 70 |
+
for node in ast.walk(tree):
|
| 71 |
+
if isinstance(node, (ast.If, ast.While, ast.For)):
|
| 72 |
+
complexity += 1
|
| 73 |
+
# Add nesting penalty
|
| 74 |
+
complexity += self._get_nesting_level(node) * 0.5
|
| 75 |
+
return int(complexity)
|
| 76 |
+
|
| 77 |
+
def _get_nesting_level(self, node: ast.AST, level: int = 0) -> int:
|
| 78 |
+
parent = getattr(node, 'parent', None)
|
| 79 |
+
if parent is None:
|
| 80 |
+
return level
|
| 81 |
+
return self._get_nesting_level(parent, level + 1)
|
| 82 |
+
|
| 83 |
+
def _is_valid_name(self, name: str) -> bool:
|
| 84 |
+
if len(name) < 2:
|
| 85 |
+
return False
|
| 86 |
+
if not name.isidentifier():
|
| 87 |
+
return False
|
| 88 |
+
return True
|
cogenbai/storage/project_tracker.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sqlite3
|
| 2 |
+
from typing import Dict, List, Optional
|
| 3 |
+
from dataclasses import dataclass
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
import json
|
| 6 |
+
|
| 7 |
+
@dataclass
|
| 8 |
+
class ProjectState:
|
| 9 |
+
project_id: str
|
| 10 |
+
name: str
|
| 11 |
+
language: str
|
| 12 |
+
framework: str
|
| 13 |
+
status: str
|
| 14 |
+
completion_percentage: float
|
| 15 |
+
last_modified: datetime
|
| 16 |
+
code_snippets: Dict[str, str]
|
| 17 |
+
dependencies: List[str]
|
| 18 |
+
|
| 19 |
+
class ProjectTracker:
|
| 20 |
+
def __init__(self, db_path: str = "cogenbai_projects.db"):
|
| 21 |
+
self.conn = sqlite3.connect(db_path)
|
| 22 |
+
self._init_db()
|
| 23 |
+
|
| 24 |
+
def _init_db(self):
|
| 25 |
+
cursor = self.conn.cursor()
|
| 26 |
+
cursor.execute('''
|
| 27 |
+
CREATE TABLE IF NOT EXISTS projects (
|
| 28 |
+
project_id TEXT PRIMARY KEY,
|
| 29 |
+
name TEXT,
|
| 30 |
+
language TEXT,
|
| 31 |
+
framework TEXT,
|
| 32 |
+
status TEXT,
|
| 33 |
+
completion_percentage REAL,
|
| 34 |
+
last_modified TIMESTAMP,
|
| 35 |
+
code_snippets TEXT,
|
| 36 |
+
dependencies TEXT
|
| 37 |
+
)
|
| 38 |
+
''')
|
| 39 |
+
self.conn.commit()
|
| 40 |
+
|
| 41 |
+
def create_project(self, project: ProjectState) -> bool:
|
| 42 |
+
try:
|
| 43 |
+
cursor = self.conn.cursor()
|
| 44 |
+
cursor.execute('''
|
| 45 |
+
INSERT INTO projects VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
| 46 |
+
''', (
|
| 47 |
+
project.project_id,
|
| 48 |
+
project.name,
|
| 49 |
+
project.language,
|
| 50 |
+
project.framework,
|
| 51 |
+
project.status,
|
| 52 |
+
project.completion_percentage,
|
| 53 |
+
project.last_modified.isoformat(),
|
| 54 |
+
json.dumps(project.code_snippets),
|
| 55 |
+
json.dumps(project.dependencies)
|
| 56 |
+
))
|
| 57 |
+
self.conn.commit()
|
| 58 |
+
return True
|
| 59 |
+
except Exception as e:
|
| 60 |
+
print(f"Error creating project: {e}")
|
| 61 |
+
return False
|
| 62 |
+
|
| 63 |
+
def update_project(self, project_id: str, updates: Dict) -> bool:
|
| 64 |
+
try:
|
| 65 |
+
cursor = self.conn.cursor()
|
| 66 |
+
set_clause = ", ".join([f"{k} = ?" for k in updates.keys()])
|
| 67 |
+
query = f"UPDATE projects SET {set_clause} WHERE project_id = ?"
|
| 68 |
+
cursor.execute(query, list(updates.values()) + [project_id])
|
| 69 |
+
self.conn.commit()
|
| 70 |
+
return True
|
| 71 |
+
except Exception as e:
|
| 72 |
+
print(f"Error updating project: {e}")
|
| 73 |
+
return False
|
| 74 |
+
|
| 75 |
+
def get_project(self, project_id: str) -> Optional[ProjectState]:
|
| 76 |
+
cursor = self.conn.cursor()
|
| 77 |
+
cursor.execute("SELECT * FROM projects WHERE project_id = ?", (project_id,))
|
| 78 |
+
row = cursor.fetchone()
|
| 79 |
+
if row:
|
| 80 |
+
return ProjectState(
|
| 81 |
+
project_id=row[0],
|
| 82 |
+
name=row[1],
|
| 83 |
+
language=row[2],
|
| 84 |
+
framework=row[3],
|
| 85 |
+
status=row[4],
|
| 86 |
+
completion_percentage=row[5],
|
| 87 |
+
last_modified=datetime.fromisoformat(row[6]),
|
| 88 |
+
code_snippets=json.loads(row[7]),
|
| 89 |
+
dependencies=json.loads(row[8])
|
| 90 |
+
)
|
| 91 |
+
return None
|
cogenbai/templates/code_templates.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Optional
|
| 2 |
+
|
| 3 |
+
class CodeTemplates:
|
| 4 |
+
"""Code templates for various programming patterns and frameworks."""
|
| 5 |
+
|
| 6 |
+
def __init__(self):
|
| 7 |
+
self.templates: Dict[str, Dict[str, str]] = {
|
| 8 |
+
"api": {
|
| 9 |
+
"python-fastapi": self._python_fastapi_template(),
|
| 10 |
+
"python-flask": self._python_flask_template(),
|
| 11 |
+
"node-express": self._node_express_template(),
|
| 12 |
+
"go-gin": self._go_gin_template(),
|
| 13 |
+
"rust-actix": self._rust_actix_template()
|
| 14 |
+
},
|
| 15 |
+
"cli": {
|
| 16 |
+
"python-click": self._python_click_template(),
|
| 17 |
+
"rust-clap": self._rust_clap_template(),
|
| 18 |
+
"go-cobra": self._go_cobra_template()
|
| 19 |
+
},
|
| 20 |
+
"gui": {
|
| 21 |
+
"python-tkinter": self._python_tkinter_template(),
|
| 22 |
+
"typescript-react": self._typescript_react_template(),
|
| 23 |
+
"kotlin-compose": self._kotlin_compose_template()
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
def get_template(self, category: str, tech_stack: str) -> Optional[str]:
|
| 28 |
+
"""Get a specific template by category and technology stack."""
|
| 29 |
+
return self.templates.get(category, {}).get(tech_stack)
|
| 30 |
+
|
| 31 |
+
def _python_fastapi_template(self) -> str:
|
| 32 |
+
return '''
|
| 33 |
+
from fastapi import FastAPI, HTTPException
|
| 34 |
+
from pydantic import BaseModel
|
| 35 |
+
|
| 36 |
+
app = FastAPI()
|
| 37 |
+
|
| 38 |
+
@app.get("/")
|
| 39 |
+
async def root():
|
| 40 |
+
return {"message": "Hello World"}
|
| 41 |
+
|
| 42 |
+
@app.get("/items/{item_id}")
|
| 43 |
+
async def read_item(item_id: int):
|
| 44 |
+
return {"item_id": item_id}
|
| 45 |
+
'''
|
| 46 |
+
|
| 47 |
+
def _python_flask_template(self) -> str:
|
| 48 |
+
return '''
|
| 49 |
+
from flask import Flask, jsonify
|
| 50 |
+
|
| 51 |
+
app = Flask(__name__)
|
| 52 |
+
|
| 53 |
+
@app.route("/")
|
| 54 |
+
def hello_world():
|
| 55 |
+
return jsonify({"message": "Hello World"})
|
| 56 |
+
|
| 57 |
+
if __name__ == "__main__":
|
| 58 |
+
app.run(debug=True)
|
| 59 |
+
'''
|
| 60 |
+
|
| 61 |
+
# Add more template methods for other frameworks...
|
cogenbai/templates/frameworks/qt_template.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class QtTemplate:
|
| 2 |
+
@staticmethod
|
| 3 |
+
def generate_main_window() -> str:
|
| 4 |
+
return '''
|
| 5 |
+
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout
|
| 6 |
+
import sys
|
| 7 |
+
|
| 8 |
+
class MainWindow(QMainWindow):
|
| 9 |
+
def __init__(self):
|
| 10 |
+
super().__init__()
|
| 11 |
+
self.setWindowTitle("Qt Application")
|
| 12 |
+
self.setup_ui()
|
| 13 |
+
|
| 14 |
+
def setup_ui(self):
|
| 15 |
+
central_widget = QWidget()
|
| 16 |
+
self.setCentralWidget(central_widget)
|
| 17 |
+
layout = QVBoxLayout(central_widget)
|
| 18 |
+
# Add your widgets here
|
| 19 |
+
|
| 20 |
+
if __name__ == '__main__':
|
| 21 |
+
app = QApplication(sys.argv)
|
| 22 |
+
window = MainWindow()
|
| 23 |
+
window.show()
|
| 24 |
+
sys.exit(app.exec())
|
| 25 |
+
'''
|
| 26 |
+
|
| 27 |
+
@staticmethod
|
| 28 |
+
def generate_widget() -> str:
|
| 29 |
+
return '''
|
| 30 |
+
from PySide6.QtWidgets import QWidget, QVBoxLayout
|
| 31 |
+
|
| 32 |
+
class CustomWidget(QWidget):
|
| 33 |
+
def __init__(self, parent=None):
|
| 34 |
+
super().__init__(parent)
|
| 35 |
+
self.setup_ui()
|
| 36 |
+
|
| 37 |
+
def setup_ui(self):
|
| 38 |
+
layout = QVBoxLayout(self)
|
| 39 |
+
# Add your widget components here
|
| 40 |
+
'''
|
cogenbai/templates/modern/astro_template.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class AstroTemplate:
|
| 2 |
+
@staticmethod
|
| 3 |
+
def generate_page() -> str:
|
| 4 |
+
return '''---
|
| 5 |
+
import Layout from '../layouts/Layout.astro';
|
| 6 |
+
import Card from '../components/Card.astro';
|
| 7 |
+
|
| 8 |
+
const title = "Welcome to Astro";
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
<Layout title={title}>
|
| 12 |
+
<main>
|
| 13 |
+
<h1>{title}</h1>
|
| 14 |
+
<Card
|
| 15 |
+
href="https://docs.astro.build/"
|
| 16 |
+
title="Documentation"
|
| 17 |
+
body="Learn how Astro works and explore the official API docs."
|
| 18 |
+
/>
|
| 19 |
+
</main>
|
| 20 |
+
</Layout>
|
| 21 |
+
|
| 22 |
+
<style>
|
| 23 |
+
main {
|
| 24 |
+
margin: auto;
|
| 25 |
+
padding: 1rem;
|
| 26 |
+
width: 800px;
|
| 27 |
+
max-width: calc(100% - 2rem);
|
| 28 |
+
font-size: 20px;
|
| 29 |
+
line-height: 1.6;
|
| 30 |
+
}
|
| 31 |
+
</style>
|
| 32 |
+
'''
|
| 33 |
+
|
| 34 |
+
@staticmethod
|
| 35 |
+
def generate_component() -> str:
|
| 36 |
+
return '''---
|
| 37 |
+
interface Props {
|
| 38 |
+
title: string;
|
| 39 |
+
body: string;
|
| 40 |
+
href: string;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
const { href, title, body } = Astro.props;
|
| 44 |
+
---
|
| 45 |
+
|
| 46 |
+
<div class="card">
|
| 47 |
+
<a href={href}>
|
| 48 |
+
<h2>
|
| 49 |
+
{title}
|
| 50 |
+
<span>→</span>
|
| 51 |
+
</h2>
|
| 52 |
+
<p>
|
| 53 |
+
{body}
|
| 54 |
+
</p>
|
| 55 |
+
</a>
|
| 56 |
+
</div>
|
| 57 |
+
|
| 58 |
+
<style>
|
| 59 |
+
.card {
|
| 60 |
+
padding: 1rem;
|
| 61 |
+
background-color: #fff;
|
| 62 |
+
border-radius: 0.5rem;
|
| 63 |
+
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
| 64 |
+
}
|
| 65 |
+
</style>
|
| 66 |
+
'''
|
cogenbai/templates/registry.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Optional
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
class TemplateRegistry:
|
| 6 |
+
def __init__(self):
|
| 7 |
+
self.templates: Dict[str, Dict] = {}
|
| 8 |
+
self.template_dir = os.path.join(os.path.dirname(__file__), 'data')
|
| 9 |
+
self._load_templates()
|
| 10 |
+
|
| 11 |
+
def _load_templates(self):
|
| 12 |
+
if not os.path.exists(self.template_dir):
|
| 13 |
+
os.makedirs(self.template_dir)
|
| 14 |
+
return
|
| 15 |
+
|
| 16 |
+
for filename in os.listdir(self.template_dir):
|
| 17 |
+
if filename.endswith('.json'):
|
| 18 |
+
with open(os.path.join(self.template_dir, filename), 'r') as f:
|
| 19 |
+
lang_templates = json.load(f)
|
| 20 |
+
self.templates.update(lang_templates)
|
| 21 |
+
|
| 22 |
+
def get_template(self, language: str, template_name: str) -> Optional[str]:
|
| 23 |
+
return self.templates.get(language, {}).get(template_name)
|
| 24 |
+
|
| 25 |
+
def add_template(self, language: str, name: str, content: str):
|
| 26 |
+
if language not in self.templates:
|
| 27 |
+
self.templates[language] = {}
|
| 28 |
+
self.templates[language][name] = content
|
| 29 |
+
self._save_templates(language)
|
| 30 |
+
|
| 31 |
+
def _save_templates(self, language: str):
|
| 32 |
+
filepath = os.path.join(self.template_dir, f"{language}.json")
|
| 33 |
+
with open(filepath, 'w') as f:
|
| 34 |
+
json.dump({language: self.templates[language]}, f, indent=2)
|
cogenbai/templates/scaffolds/python_project.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"structure": {
|
| 3 |
+
"src": {
|
| 4 |
+
"__init__.py": "",
|
| 5 |
+
"main.py": "def main():\n pass\n\nif __name__ == '__main__':\n main()",
|
| 6 |
+
"config.py": "from dataclasses import dataclass\n\n@dataclass\nclass Config:\n pass"
|
| 7 |
+
},
|
| 8 |
+
"tests": {
|
| 9 |
+
"__init__.py": "",
|
| 10 |
+
"test_main.py": "import unittest\n\nclass TestMain(unittest.TestCase):\n def test_sample(self):\n self.assertTrue(True)"
|
| 11 |
+
},
|
| 12 |
+
"docs": {
|
| 13 |
+
"README.md": "# ${project_name}\n\n${project_description}"
|
| 14 |
+
},
|
| 15 |
+
"requirements.txt": "pytest>=6.0.0\npytest-cov>=2.0.0",
|
| 16 |
+
"setup.py": "from setuptools import setup, find_packages\n\nsetup(\n name='${project_name}',\n version='0.1.0',\n packages=find_packages()\n)"
|
| 17 |
+
}
|
| 18 |
+
}
|
cogenbai/testing/generator.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ast
|
| 2 |
+
from typing import List, Dict, Any
|
| 3 |
+
import black
|
| 4 |
+
|
| 5 |
+
class TestGenerator:
|
| 6 |
+
def __init__(self):
|
| 7 |
+
self.test_templates = {
|
| 8 |
+
'python': {
|
| 9 |
+
'unit': self._generate_python_unit_test,
|
| 10 |
+
'integration': self._generate_python_integration_test
|
| 11 |
+
}
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
def generate_tests(self, code: str, language: str, test_type: str = 'unit') -> str:
|
| 15 |
+
generator = self.test_templates.get(language, {}).get(test_type)
|
| 16 |
+
if not generator:
|
| 17 |
+
raise ValueError(f"Unsupported language or test type: {language}/{test_type}")
|
| 18 |
+
|
| 19 |
+
test_code = generator(code)
|
| 20 |
+
try:
|
| 21 |
+
return black.format_str(test_code, mode=black.FileMode())
|
| 22 |
+
except:
|
| 23 |
+
return test_code
|
| 24 |
+
|
| 25 |
+
def _generate_python_unit_test(self, code: str) -> str:
|
| 26 |
+
tree = ast.parse(code)
|
| 27 |
+
test_cases = []
|
| 28 |
+
|
| 29 |
+
for node in ast.walk(tree):
|
| 30 |
+
if isinstance(node, ast.FunctionDef):
|
| 31 |
+
test_cases.append(self._generate_function_test(node))
|
| 32 |
+
|
| 33 |
+
return self._format_test_class(test_cases)
|
| 34 |
+
|
| 35 |
+
def _generate_function_test(self, func_node: ast.FunctionDef) -> str:
|
| 36 |
+
args = [arg.arg for arg in func_node.args.args]
|
| 37 |
+
test_name = f"test_{func_node.name}"
|
| 38 |
+
|
| 39 |
+
test_template = f"""
|
| 40 |
+
def {test_name}(self):
|
| 41 |
+
# Arrange
|
| 42 |
+
{''.join(f'{arg} = None # TODO: Add test value\n ' for arg in args)}
|
| 43 |
+
|
| 44 |
+
# Act
|
| 45 |
+
result = {func_node.name}({', '.join(args)})
|
| 46 |
+
|
| 47 |
+
# Assert
|
| 48 |
+
self.assertIsNotNone(result) # TODO: Add specific assertions
|
| 49 |
+
"""
|
| 50 |
+
return test_template
|
| 51 |
+
|
| 52 |
+
def _format_test_class(self, test_cases: List[str]) -> str:
|
| 53 |
+
return f"""import unittest
|
| 54 |
+
|
| 55 |
+
class TestGeneratedCode(unittest.TestCase):
|
| 56 |
+
{''.join(test_cases)}
|
| 57 |
+
|
| 58 |
+
if __name__ == '__main__':
|
| 59 |
+
unittest.main()
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
def _generate_python_integration_test(self, code: str) -> str:
|
| 63 |
+
# Similar to unit test but with more complex scenarios
|
| 64 |
+
return "# TODO: Implement integration tests\n"
|
cogenbai/voice/synthesizer.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pyttsx3
|
| 2 |
+
|
| 3 |
+
class VoiceSynthesizer:
|
| 4 |
+
def __init__(self):
|
| 5 |
+
self.engine = pyttsx3.init()
|
| 6 |
+
|
| 7 |
+
def explain_code(self, code, explanation):
|
| 8 |
+
"""Provides voice explanation for code"""
|
| 9 |
+
self.engine.say(explanation)
|
| 10 |
+
self.engine.runAndWait()
|
| 11 |
+
|
| 12 |
+
def debug_assist(self, error_message):
|
| 13 |
+
"""Provides voice assistance for debugging"""
|
| 14 |
+
debug_explanation = f"Debug suggestion: {error_message}"
|
| 15 |
+
self.engine.say(debug_explanation)
|
| 16 |
+
self.engine.runAndWait()
|
config.yaml
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model:
|
| 2 |
+
name: cogenbai
|
| 3 |
+
version: 7.5b
|
| 4 |
+
base: codellama
|
| 5 |
+
parameters:
|
| 6 |
+
temperature: 0.7
|
| 7 |
+
top_k: 50
|
| 8 |
+
top_p: 0.9
|
| 9 |
+
num_ctx: 4096
|
| 10 |
+
num_threads: 8
|
| 11 |
+
seed: 42
|
| 12 |
+
|
| 13 |
+
capabilities:
|
| 14 |
+
languages:
|
| 15 |
+
- python
|
| 16 |
+
- javascript
|
| 17 |
+
- typescript
|
| 18 |
+
- java
|
| 19 |
+
- go
|
| 20 |
+
- rust
|
| 21 |
+
- cpp
|
| 22 |
+
- csharp
|
| 23 |
+
- php
|
| 24 |
+
- ruby
|
| 25 |
+
- kotlin
|
| 26 |
+
- swift
|
| 27 |
+
- dart
|
| 28 |
+
|
| 29 |
+
frameworks:
|
| 30 |
+
backend:
|
| 31 |
+
- django
|
| 32 |
+
- flask
|
| 33 |
+
- fastapi
|
| 34 |
+
- spring
|
| 35 |
+
- express
|
| 36 |
+
frontend:
|
| 37 |
+
- react
|
| 38 |
+
- vue
|
| 39 |
+
- angular
|
| 40 |
+
- svelte
|
| 41 |
+
mobile:
|
| 42 |
+
- flutter
|
| 43 |
+
- react-native
|
docker-compose.yml
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
api:
|
| 5 |
+
build: .
|
| 6 |
+
ports:
|
| 7 |
+
- "8000:8000"
|
| 8 |
+
environment:
|
| 9 |
+
- CUDA_VISIBLE_DEVICES=0
|
| 10 |
+
volumes:
|
| 11 |
+
- ./models:/app/models
|
| 12 |
+
deploy:
|
| 13 |
+
resources:
|
| 14 |
+
reservations:
|
| 15 |
+
devices:
|
| 16 |
+
- driver: nvidia
|
| 17 |
+
count: 1
|
| 18 |
+
capabilities: [gpu]
|
| 19 |
+
|
| 20 |
+
prometheus:
|
| 21 |
+
image: prom/prometheus
|
| 22 |
+
ports:
|
| 23 |
+
- "9090:9090"
|
| 24 |
+
volumes:
|
| 25 |
+
- ./prometheus.yml:/etc/prometheus/prometheus.yml
|
| 26 |
+
|
| 27 |
+
grafana:
|
| 28 |
+
image: grafana/grafana
|
| 29 |
+
ports:
|
| 30 |
+
- "3000:3000"
|
| 31 |
+
environment:
|
| 32 |
+
- GF_SECURITY_ADMIN_PASSWORD=admin
|
| 33 |
+
depends_on:
|
| 34 |
+
- prometheus
|
requirements.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch>=2.0.0
|
| 2 |
+
transformers>=4.30.0
|
| 3 |
+
fastapi>=0.100.0
|
| 4 |
+
pydantic>=2.0.0
|
| 5 |
+
uvicorn>=0.22.0
|
| 6 |
+
python-dotenv>=1.0.0
|
| 7 |
+
prometheus-client>=0.17.0
|
| 8 |
+
pytest>=7.0.0
|
| 9 |
+
black>=23.0.0
|
| 10 |
+
isort>=5.12.0
|
| 11 |
+
mypy>=1.0.0
|
| 12 |
+
pytest-cov>=4.0.0
|
setup.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from setuptools import setup, find_packages
|
| 2 |
+
import subprocess
|
| 3 |
+
import yaml
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
def setup_cogenbai():
|
| 7 |
+
"""Setup COGENBAI model"""
|
| 8 |
+
print("Setting up COGENBAI...")
|
| 9 |
+
|
| 10 |
+
# Create model
|
| 11 |
+
subprocess.run(["ollama", "create", "cogenbai:7.5b", "-f", "Modelfile"])
|
| 12 |
+
|
| 13 |
+
# Load configuration
|
| 14 |
+
with open("config.yaml", "r") as f:
|
| 15 |
+
config = yaml.safe_load(f)
|
| 16 |
+
|
| 17 |
+
print(f"\nCOGENBAI {config['model']['version']} setup complete!")
|
| 18 |
+
print("\nTest the model with:")
|
| 19 |
+
print("ollama run cogenbai:7.5b \"Write a hello world in Python\"")
|
| 20 |
+
|
| 21 |
+
if __name__ == "__main__":
|
| 22 |
+
setup_cogenbai()
|
| 23 |
+
|
| 24 |
+
setup(
|
| 25 |
+
name="cogenbai",
|
| 26 |
+
version="1.0.0",
|
| 27 |
+
packages=find_packages(),
|
| 28 |
+
install_requires=[
|
| 29 |
+
"torch>=1.9.0",
|
| 30 |
+
"transformers>=4.11.0",
|
| 31 |
+
"pyttsx3>=2.90",
|
| 32 |
+
"fastapi>=0.68.0",
|
| 33 |
+
"uvicorn>=0.15.0",
|
| 34 |
+
"click>=8.0.0",
|
| 35 |
+
"autopep8>=1.5.7",
|
| 36 |
+
"black>=21.5b2",
|
| 37 |
+
"yapf>=0.31.0",
|
| 38 |
+
"websockets>=10.0",
|
| 39 |
+
"python-socketio>=5.5.0"
|
| 40 |
+
],
|
| 41 |
+
entry_points={
|
| 42 |
+
'console_scripts': [
|
| 43 |
+
'cogenbai=cogenbai.cli.main:cli',
|
| 44 |
+
],
|
| 45 |
+
},
|
| 46 |
+
author="Shahrear Hossain Shawon",
|
| 47 |
+
author_email="contact@algoscienceacademy.com",
|
| 48 |
+
description="Advanced AI model for coding experts by Algo Science Academy",
|
| 49 |
+
long_description=open('README.md').read(),
|
| 50 |
+
long_description_content_type="text/markdown",
|
| 51 |
+
url="https://algoscienceacademy.com/cogenbai",
|
| 52 |
+
classifiers=[
|
| 53 |
+
"Development Status :: 5 - Production/Stable",
|
| 54 |
+
"Intended Audience :: Developers",
|
| 55 |
+
"License :: Other/Proprietary License",
|
| 56 |
+
"Programming Language :: Python :: 3.8",
|
| 57 |
+
],
|
| 58 |
+
python_requires=">=3.8",
|
| 59 |
+
)
|
tests/integration/test_workflow.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import unittest
|
| 2 |
+
from cogenbai import CogenBAI, CodeAnalyzer, LanguageGenerator
|
| 3 |
+
|
| 4 |
+
class TestIntegrationWorkflow(unittest.TestCase):
|
| 5 |
+
def setUp(self):
|
| 6 |
+
self.model = CogenBAI()
|
| 7 |
+
self.analyzer = CodeAnalyzer()
|
| 8 |
+
self.generator = LanguageGenerator()
|
| 9 |
+
|
| 10 |
+
def test_complete_workflow(self):
|
| 11 |
+
# Generate code
|
| 12 |
+
code = self.model.generate_code(
|
| 13 |
+
"Create a function to sort a list",
|
| 14 |
+
"python"
|
| 15 |
+
)
|
| 16 |
+
self.assertIsNotNone(code)
|
| 17 |
+
|
| 18 |
+
# Analyze generated code
|
| 19 |
+
issues = self.analyzer.analyze_python(code)
|
| 20 |
+
self.assertIsInstance(issues, list)
|
| 21 |
+
|
| 22 |
+
# Check language support
|
| 23 |
+
config = self.generator.get_language_config("python")
|
| 24 |
+
self.assertIsNotNone(config)
|
| 25 |
+
self.assertIn("frameworks", config)
|
| 26 |
+
|
| 27 |
+
if __name__ == '__main__':
|
| 28 |
+
unittest.main()
|
tests/test_model.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
from cogenbai.core.model import CogenBAI
|
| 3 |
+
|
| 4 |
+
def test_model_initialization():
|
| 5 |
+
model = CogenBAI()
|
| 6 |
+
assert model is not None
|
| 7 |
+
assert model.device in ["cuda", "cpu"]
|
| 8 |
+
|
| 9 |
+
def test_code_generation():
|
| 10 |
+
model = CogenBAI()
|
| 11 |
+
prompt = "def calculate_fibonacci(n):"
|
| 12 |
+
result = model.generate_code(prompt)
|
| 13 |
+
assert isinstance(result, str)
|
| 14 |
+
assert len(result) > 0
|
| 15 |
+
|
| 16 |
+
import unittest
|
| 17 |
+
from cogenbai.core.model import CogenBAI
|
| 18 |
+
|
| 19 |
+
class TestCogenBAI(unittest.TestCase):
|
| 20 |
+
def setUp(self):
|
| 21 |
+
self.model = CogenBAI()
|
| 22 |
+
|
| 23 |
+
def test_generate_code(self):
|
| 24 |
+
prompt = "Create a function that adds two numbers"
|
| 25 |
+
language = "python"
|
| 26 |
+
result = self.model.generate_code(prompt, language)
|
| 27 |
+
self.assertIsInstance(result, str)
|
| 28 |
+
self.assertGreater(len(result), 0)
|
| 29 |
+
|
| 30 |
+
if __name__ == '__main__':
|
| 31 |
+
unittest.main()
|