QuantumGenerator is a clean-architecture Python project for generating code with LLMs and retrieval-augmented context.
Current implementation includes:
- Model adapters: CodeGemma, DeepSeek, Qwen, CodeLlama
- RAG pipeline: Chroma or FAISS retrievers with reranking
- Fine-tuning: LoRA trainer on OPENCLAW quantum dataset
- API: FastAPI endpoint for code generation
src/quantumgenerator/
├── domain/ # Entities and interfaces
├── application/ # DTOs, use cases, services
├── infrastructure/ # Generators, RAG, fine-tuning, config, logging, time
└── interfaces/ # FastAPI entrypoints and schemas
High-level flow:
- API receives a prompt.
- Application use case fetches context via RAG pipeline.
- Prompt + context are passed to selected generator.
- Service returns generated result with execution time.
- Python 3.9+
- Optional GPU for faster inference/training
HF_TOKENin.envfor gated Hugging Face models (CodeGemma/CodeLlama)
Example .env:
HF_TOKEN=hf_xxxxx
pip install -e ".[dev]"If you only need runtime dependencies:
pip install -r requirements.txtfrom quantumgenerator.infrastructure.generators import ModelFactory
model = ModelFactory.create_model(
"codegemma",
model_name="google/codegemma-2b",
quantize=True,
)
result = model.generate("Generate OpenQASM 3 code for a Bell state")
print(result)from quantumgenerator.application.dto import GenerateQuantumCodeRequest
from quantumgenerator.interfaces.api.dependencies import DIContainer
container = DIContainer()
service = container.get_code_generation_service(
model_type="codegemma",
model_name="google/codegemma-2b",
)
response = service.generate(
GenerateQuantumCodeRequest(query="Implement 3-qubit phase estimation")
)
print(response.result)
print(response.execution_time)uvicorn quantumgenerator.interfaces.api.main:app --reloadEndpoints:
GET /api/v1/healthPOST /api/v1/generation
Example request:
{
"query": "Generate OpenQASM 3 code implementing Grover's algorithm"
}RAG defaults are loaded from config/config.yaml.
Important fields:
retriever.retriever_type:chromaorfaissretriever.vectordb_path: local vector DB pathretriever.documents.paths: PDF sources to ingestretriever.embedder: embedding model key (for exampleminilm-l6)retriever.search_kwargs: retrieval settings (k,lambda_mult)retriever.rerank_model: cross-encoder reranker model
Fine-tuning utilities are in quantumgenerator.infrastructure.fine_tuning.
Supported dataset key in code: openclaw_quantum.
from quantumgenerator.infrastructure.fine_tuning import LoRATrainer
from quantumgenerator.domain.entities import TrainingSession
session = TrainingSession(
model_name="google/codegemma-2b",
data_id="openclaw_quantum",
output_path="./checkpoints",
parameter={
"model_type": "codegemma",
"per_device_train_batch_size": 4,
"max_steps": 100,
"lora_task_type": "CAUSAL_LM",
"lora_r": 64,
"lora_alpha": 16,
"lora_dropout": 0.1,
},
)
trainer = LoRATrainer()
result = trainer.train(session)
print(result.adapter_path)Run all tests:
pytestRun only unit tests:
pytest tests/unitRun integration tests (downloads models/datasets and can be heavy):
pytest tests/integration -m integrationdocker build -t quantumgenerator .
docker run --rm -p 8080:8080 quantumgeneratorMIT. See LICENSE.