https://codegennie.vercel.app/
Codegennie.mp4
This application allows you to explain, refactor, and analyze your code using the Gemini API. Additionally, it integrates with a local Ollama instance to provide on-the-fly code generation from comments and AI-powered autocompletion/correction.
To enable code generation (Ctrl+Enter) and AI suggestion features, you need to run Ollama and the codellama:7b model on your local machine using Docker.
- Docker Desktop installed and running on your machine.
Open your terminal and run the following command. This will download the Ollama image and start a container named ollama.
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama -e OLLAMA_ORIGINS='*' ollama/ollamaCommand Breakdown:
-d: Run the container in detached mode (in the background).-v ollama:/root/.ollama: Creates a Docker volume to persist downloaded models, so you don't have to re-download them every time.-p 11434:11434: Maps port 11434 on your local machine to the container's port.--name ollama: Names the container for easy reference.-e OLLAMA_ORIGINS='*': CRUCIAL STEP. This configures Ollama to accept requests from any origin, which is required for this web app to communicate with it. Without this, you will get "Failed to fetch" errors.ollama/ollama: The official Ollama Docker image.
Optional GPU Acceleration: If you have a compatible NVIDIA GPU and have installed the NVIDIA Container Toolkit, you can run with GPU support for better performance:
docker run -d --gpus=all -v ollama:/root/.ollama -p 11434:11434 --name ollama -e OLLAMA_ORIGINS='*' ollama/ollamaOnce the container is running, execute the following command in your terminal to download the recommended model. This model offers a great balance of speed and quality for interactive features.
docker exec -it ollama ollama pull codellama:7bThis may take a few minutes to complete.
You can check that Ollama is running and accessible by running this curl command in your terminal:
curl http://localhost:11434/api/generate -d '{"model": "codellama:7b", "prompt": "Why is the sky blue?"}'If it's working correctly, you will see a JSON response from the model. If you get a "connection refused" error, your container is not running.
Error: "Failed to fetch" or "Could not connect to Ollama" in the web app.
This is the most common issue and is almost always a CORS problem. Follow these steps:
- Check if the container is running: Run
docker ps. You should see a container with the nameollamain the list. If not, start it withdocker start ollama. - Verify the
OLLAMA_ORIGINSflag: This is critical. If you started the container without-e OLLAMA_ORIGINS='*', the browser cannot connect to it. You must stop and remove the old container and create a new one with the correct command.# Stop and remove the old, misconfigured container docker stop ollama docker rm ollama # Re-run the command from Step 2 with the OLLAMA_ORIGINS flag docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama -e OLLAMA_ORIGINS='*' ollama/ollama
- Check for Firewalls or Proxies: Ensure no firewall or network proxy is blocking connections to
localhost:11434.