CodeCraft is an AI-powered iterative code refinement tool that utilizes Large Language Models (LLMs) to generate, test, and refine code until it meets the expected output. It follows a structured feedback loop incorporating Chain of Thought prompting techniques for enhanced reasoning and explainability.
- Automated Code Generation: Generates code based on a given programming question, example input, and language.
- Iterative Refinement: Uses test cases and feedback loops to debug and enhance code quality.
- Edge Case Handling: Automatically generates five test cases, including edge cases.
- Compiler Execution: Runs the generated code and verifies outputs against expected results.
- LLM Debugging Assistance: If the output doesn't match expectations, the model iteratively refines the code.
- Supports Multiple Programming Languages: Users can specify their preferred language for code generation.
- Groq API Integration: Users can input their Groq API key to interact with the application.
Deployed URL: https://www.codecraftai.tech
The backend is built using FastAPI and utilizes PostgreSQL as its database.
-
Set up environment variables: Create a
.envfile in the root directory with the following variables:COMPILER_API_ENDPOINT= DATABASE_URL= CORS_ORIGINS=
COMPILER_API_ENDPOINT: URL of Judge0 API (either self-hosted or from RapidAPI).DATABASE_URL: PostgreSQL database connection string.CORS_ORIGINS: Allowed origins for CORS ie http://localhost:3000 for frontend
-
Set up a Python virtual environment:
cd backend python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate` pip install -r requirements.txt
-
Run database migrations:
cd backend/src # edit alembic.ini from script_location = src/migrations to script_location = migrations alembic upgrade head
-
Start the server:
cd backend/src uvicorn llama_agent:app --reload
The frontend is built using Next.js.
- Navigate to the frontend directory:
cd frontend - Create an
.envfile: Copy.env.exampleand fill in the necessary values:NEXT_PUBLIC_API_URL= - Install dependencies and start the frontend:
yarn install yarn dev
- User Input:
- Model selection
- Programming question
- Language
- Example input
- Number of iterations
- Test Case Generation:
- The model generates five test cases, including edge cases.
- Code Generation:
- Code is generated based on the input parameters.
- Compilation and Execution:
- The code is compiled and executed using the Judge0 API.
- Verification:
- The output is compared with expected results.
- Feedback Loop:
- If errors occur or outputs do not match, additional debugging information is fed back to the model for refinement.
- Final Output:
- Once the expected output is achieved, the final refined code is presented to the user.
Contributions are welcome! Feel free to fork this repo and submit pull requests.
This project is licensed under the MIT License.