offbs-gen
v1.0.0
Published
A Node.js CLI to generate code snippets using the Google Gemini API.
Readme
ai-gen: Code Generation CLI
ai-gen is a command-line tool that uses Google's Gemini AI to generate code snippets directly in your terminal.
Features
- Generate code from a natural-language prompt.
- Interactive mode if no prompt is given.
- Specify a programming language for more accurate results.
- Request a natural-language explanation of the generated code.
- Securely uses your Gemini API key from a
.envfile.
Setup and Installation
Follow these steps to set up and run the ai-gen tool.
1. Prerequisites
- Node.js (version 18 or higher)
- An active Google Gemini API key. You can get one from Google AI Studio.
2. Install Dependencies
Clone or download the project, navigate into the project directory, and install the required npm packages:
npm install3. Set Your API Key
Create a file named .env in the root of the project directory. You can do this by copying the example file:
cp .env.example .envNow, open the .env file and replace your_api_key_here with your actual Gemini API key.
# .env
GEMINI_API_KEY=AIzaSy...your...key...4. Make the CLI Executable
To run the ai-gen command directly, you need to make the index.js file executable:
chmod +x index.js5. Install Globally (Optional but Recommended)
To use the ai-gen command from anywhere on your system, link the package globally:
npm install -g .Usage
You can now run the tool from any directory.
Basic Usage
Provide your request as a string argument.
ai-gen "Create a React button component with a click handler"Language Specificity
Use the --lang flag to hint the programming language.
ai-gen "A function that reads a file and returns its content" --lang pythonRequest an Explanation
Use the --explain flag to get a brief explanation of the code below the snippet.
ai-gen "Express.js server with a single GET endpoint" --explainInteractive Mode
Run the command without any arguments to enter interactive mode.
ai-genThe tool will then prompt you to enter your code generation request.
