A Rust CLI application that interfaces with Google's Gemini API to generate and execute code.
- Interactive Chat with Gemini: Continuous chat experience with the Gemini 2.0 Flash Thinking model
- Execute Code: Use the Gemini 1.5 Flash model to execute code snippets
- Create Codebases: Generate complete codebases from natural language descriptions
- Command feedback loop for iterative improvements
- Support for file and folder creation, code writing, and command execution
- Direct code execution using Gemini 1.5 Flash model
- Configurable API endpoint and model selection
- Robust error handling with custom error types and proper error propagation
- Configurable logging for better debugging and verbosity control
- Rust and Cargo installed
- Google Gemini API key (environment variable:
GEMINI_API_KEY)
- Clone the repository:
git clone https://github.com/yourusername/gemini-codemaker.git cd gemini-codemaker - Build the project:
cargo build --release - Set your Gemini API key:
export GEMINI_API_KEY="your-api-key-here"
To start an interactive chat session with the Gemini model:
# Start chat with an initial query
cargo run -- chat --query "What is Rust programming language?"
# Start chat without an initial query (will prompt for input)
cargo run -- chatIn the interactive chat mode:
- Type your queries and receive responses
- The chat maintains context across multiple interactions
- Type
exitorquitto end the chat session
To execute code using the Gemini 1.5 Flash model:
cargo run -- execute --query "Write a Python function to calculate the factorial of a number and show its usage"To create a complete codebase from a description:
cargo run -- create-codebase --description "A React application with a Node.js backend that provides a simple todo list functionality" --output-dir my_projectThis will generate a complete codebase based on your description in the specified output directory.
The application uses the env_logger crate for logging. You can control the log level using the RUST_LOG environment variable:
# Show only error messages
RUST_LOG=error cargo run -- chat --query "What is Rust?"
# Show info and above (info, warn, error)
RUST_LOG=info cargo run -- execute --query "Write a Python hello world"
# Show all log messages including debug and trace
RUST_LOG=trace cargo run -- create-codebase --description "Simple web app" --output-dir test_appCommon log levels from least to most verbose: error, warn, info, debug, trace
The application requires a valid Gemini API key to function. You can obtain one from the Google AI Studio.
GEMINI_API_KEY: Required for authenticating API requestsGEMINI_MODEL: Optional variable to specify which model to use (defaults to gemini-2.0-flash-thinking-exp-01-21)GEMINI_API_ENDPOINT: Optional variable to specify a custom API endpoint
The application supports three main modes:
In the interactive chat mode:
- The Gemini model responds with structured commands that this CLI can execute
- Feedback from command execution is sent back to Gemini in subsequent queries
- The chat maintains context across multiple interactions
- Commands that can be executed:
create_folder: Create a new directorycreate_file: Create an empty filewrite_code_to_file: Write code to a specified fileexecute_command: Execute a shell command
In execute mode, the application uses Gemini 1.5 Flash with code execution capabilities:
- The model generates code based on your query
- The model executes the code and returns the results
- All execution happens on Google's servers, not locally
In create codebase mode, the application generates a complete codebase based on your description.
After executing commands in chat mode, the application sends feedback to Gemini in subsequent queries, allowing it to adjust its approach based on command success or failure. This feedback loop is maintained throughout the chat session.
- serde, serde_json: For JSON serialization/deserialization
- clap: For command-line argument parsing
- reqwest: For making HTTP requests
- tokio: For asynchronous runtime
- log, env_logger: For configurable logging
- thiserror: For custom error types
- regex: For pattern matching in code extraction