Skip to content

About

LangChain-Orchestrated Code Generation Notebook

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

CodeGen AI

A professional Python package for generating code with Google Gemini via LangChain.

Project Overview

This repository is focused on a clean code generation package and deployment-ready examples.

Included in this repository:

  • codegen/ — reusable package with Gemini integration, prompt generation, validation, and auto-fix support.
  • codegen_demo.py — polished command-line demo showcasing package usage.
  • app_fastapi.py — REST API for remote code generation.
  • app_streamlit.py — interactive Streamlit UI for generation, validation, and runtime execution.
  • Dockerfile — container image definition for production deployment.
  • Procfile — process configuration for platform deployment.
  • .env.example — environment variable template.

Installation

Install the package in editable mode:

pip install -e .

Or install dependencies directly:

pip install -r requirements.txt

Configuration

Copy .env.example to .env and add your Gemini API key:

copy .env.example .env

Set one of the following environment variables:

  • GOOGLE_API_KEY
  • GEMINI_API_KEY

Running the Demo

python codegen_demo.py

CLI Usage

The package exposes a CLI entrypoint named codegen:

codegen "generate a Python function that reverses a list" --validate --auto-fix

FastAPI Server

Start the API locally:

uvicorn app_fastapi:app --host 0.0.0.0 --port 8000

Example request body:

{
  "task": "generate a Python helper that removes duplicates from a list",
  "language": "python",
  "style": "idiomatic",
  "include_docstrings": true,
  "include_type_hints": true,
  "validate": true,
  "auto_fix": false
}

Streamlit UI

Run the interactive front-end:

streamlit run app_streamlit.py

Deployment

Docker

Build and run the container:

docker build -t codegen-app .
docker run -p 8000:8000 --env-file .env codegen-app

Platform Deployment

The Procfile is included to support deployment on process-based platforms.

Package Structure

  • codegen/llm_client.py — Gemini LLM abstraction with retries and structured logging.
  • codegen/prompts.py — prompt builder for generation and examples.
  • codegen/generator.py — code generation, validation, and auto-fix workflow.
  • codegen/sandbox.py — safe Python execution sandbox.
  • codegen/cli.py — CLI wrapper.
  • app_fastapi.py — FastAPI application entrypoint.
  • app_streamlit.py — Streamlit application entrypoint.
  • codegen_demo.py — polished demo script.

Notes

  • Keep secret keys out of source control and never commit .env.
  • Use python -m venv .venv for isolated development.
  • Update dependencies carefully when changing LangChain or Gemini SDK versions.

About

LangChain-Orchestrated Code Generation Notebook

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages