-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CI/CD pipeline configuration, requirements, and test files
- Loading branch information
1 parent
5067f0a
commit 3e2d819
Showing
4 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: NeuroCoder CI/CD Pipeline | ||
|
||
on: | ||
push: | ||
branches: | ||
- neurocoder-development | ||
pull_request: | ||
branches: | ||
- neurocoder-development | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.9' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Run tests | ||
run: | | ||
pytest | ||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Deploy to Docker | ||
run: | | ||
docker build -t neurocoder . | ||
docker run -d -p 80:80 neurocoder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# NeuroCoder Project Dependencies | ||
|
||
# FastAPI for creating APIs | ||
fastapi==0.78.0 | ||
|
||
# PyTorch for model development | ||
torch==1.12.1 | ||
|
||
# Transformers for advanced architecture | ||
transformers==4.21.1 | ||
|
||
# pytest for testing | ||
pytest==7.1.2 | ||
|
||
# Docker for containerization | ||
docker==5.0.3 | ||
|
||
# Additional dependencies | ||
requests==2.28.1 | ||
pydantic==1.9.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import pytest | ||
import torch | ||
from src.models.model_training import AdvancedNeuroCoder | ||
from src.api import app | ||
from fastapi.testclient import TestClient | ||
|
||
@pytest.fixture | ||
def client(): | ||
return TestClient(app) | ||
|
||
@pytest.fixture | ||
def model(): | ||
return AdvancedNeuroCoder(vocab_size=10000) | ||
|
||
def test_api_generate_code(client, model): | ||
input_data = { | ||
"input_ids": [1, 2, 3, 4], | ||
"attention_mask": [1, 1, 1, 1], | ||
"task": "generate" | ||
} | ||
response = client.post("/generate-code", json=input_data) | ||
assert response.status_code == 200 | ||
assert "output" in response.json() | ||
|
||
def test_api_feedback(client): | ||
feedback_data = { | ||
"code_id": "1234", | ||
"rating": 5, | ||
"comments": "Great code generation!" | ||
} | ||
response = client.post("/feedback", json=feedback_data) | ||
assert response.status_code == 200 | ||
assert response.json()["status"] == "success" | ||
|
||
def test_api_benchmarks(client): | ||
response = client.get("/benchmarks") | ||
assert response.status_code == 200 | ||
assert "benchmarks" in response.json() | ||
assert "comparisons" in response.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
import torch | ||
from src.models.advanced_architecture import AdvancedNeuroCoder | ||
|
||
@pytest.fixture | ||
def model(): | ||
return AdvancedNeuroCoder(vocab_size=10000) | ||
|
||
def test_model_initialization(model): | ||
assert model is not None | ||
assert model.embedding.num_embeddings == 10000 | ||
|
||
def test_forward_pass(model): | ||
input_ids = torch.tensor([[1, 2, 3, 4]]) | ||
attention_mask = torch.tensor([[1, 1, 1, 1]]) | ||
output = model(input_ids, attention_mask) | ||
assert output is not None | ||
assert output.shape == (1, 4, 10000) # (batch_size, sequence_length, vocab_size) | ||
|
||
def test_model_output_range(model): | ||
input_ids = torch.tensor([[1, 2, 3, 4]]) | ||
attention_mask = torch.tensor([[1, 1, 1, 1]]) | ||
output = model(input_ids, attention_mask) | ||
assert torch.all(output >= 0) and torch.all(output <= 1) # Assuming output is probabilities | ||
|
||
def test_model_parameters(model): | ||
total_params = sum(p.numel() for p in model.parameters()) | ||
assert total_params > 0, "Model should have parameters" | ||
|
||
def test_model_training_mode(model): | ||
model.train() | ||
assert model.training == True | ||
model.eval() | ||
assert model.training == False |