Gemini CLI LLM is a command-line interface for interacting with the Gemini API to generate content using a local large language model (LLM). This project provides a simple way to leverage the capabilities of the Gemini API directly from your terminal.
- Main Application (
src/main.py
): CLI interface with command support for input, context, and summarization - AI Agent (
src/utils/agent.py
): Implements GeminiAgent class with response generation, context awareness, and history tracking - Configuration (
src/config/settings.py
): Manages API keys and base settings - Helper Functions (
src/utils/helpers.py
): Handles request formatting, response parsing, and error management
β Implemented:
- Basic API integration
- Context-aware prompting
- Conversation history
- Text summarization
- Token usage tracking
- Unit testing foundation
- Python's
requests
library for API calls - Type hints for code quality
- In-memory conversation history
- Token usage logging
- Unit tests with
unittest
# Basic usage
python src/main.py --input "What is machine learning?"
# With context
python src/main.py --input "What are vectors?" --context "Machine learning concepts"
# Text summarization
python src/main.py --input "Long text here" --summarize
- Clone the repository:
git clone https://github.com/yourusername/gemini-cli.git cd gemini-cli
- Set up a virtual environment (optional but recommended):
python3 -m venv venv source venv/bin/activate
- Install the required dependencies:
pip install -r requirements.txt
- Replace the placeholder API key in
src/config/settings.py
with your actual Gemini API key.
src/main.py
: The entry point of the CLI application. It handles command-line arguments, sets up the API request to the Gemini API, and processes the response.src/utils/helpers.py
: Contains utility functions that assist with tasks such as formatting the API request and parsing the response from the Gemini API.src/utils/agent.py
: Implements the GeminiAgent class that handles advanced features like context-aware prompting, conversation history, and text summarization.src/config/settings.py
: Stores configuration settings, including the API key and any other necessary parameters for connecting to the Gemini API.tests/
: Contains test scripts to validate the functionality of the application, including unit tests for utility functions and integration tests for the main application..gitignore
: Specifies files and directories that should be ignored by Git, such as sensitive information like API keys and virtual environment folders.requirements.txt
: Lists the Python dependencies required for the project, including libraries for making HTTP requests and handling JSON data.README.md
: Comprehensive documentation for the project, explaining its purpose, setup, usage instructions, and next steps for further development.
The CLI now supports context-aware prompting to get more precise responses:
python src/main.py --input "What are vectors?" --context "Machine learning concepts"
Summarize long texts using the summarization feature:
python src/main.py --input "Your long text here" --summarize
The CLI maintains a history of interactions, including:
- Prompts
- Responses
- Timestamps
-
Add Unit Tests
- Write unit tests for utility functions and the main logic using
pytest
orunittest
. - Status: π§ Under Development
- Write unit tests for utility functions and the main logic using
-
Improve Error Handling
- Add robust error handling for API timeouts, invalid API keys, and malformed responses.
- Status: β Not Started
-
Support Multiple Commands
- Add commands like
--history
to view past token usage,--reset
to clear logs, or--config
to update the API key. - Status: β Not Started
- Add commands like
-
Add Configuration Management
- Replace
settings.py
with a.env
file and usepython-dotenv
for better security. - Status: β Not Started
- Replace
-
Add Logging
- Use Python's
logging
module to log API requests, responses, and errors for debugging. - Status: β Not Started
- Use Python's
-
Token Usage Analytics
- Parse the
token_usage.txt
file to calculate total tokens used over time and display usage statistics. - Status: β Not Started
- Parse the
-
Interactive Mode
- Add an interactive mode where users can input prompts continuously without restarting the script.
- Status: β Not Started
-
Dockerize the Project
- Create a
Dockerfile
to containerize the application for easier deployment. - Status: β Not Started
- Create a
-
Add a Web Interface
- Use Flask or FastAPI to create a web interface for the CLI.
- Status: β Not Started
-
Integrate with Other APIs
- Extend the project to integrate with other APIs, such as summarization, translation, or sentiment analysis.
- Status: β Not Started
-
Package as a Python Library
- Refactor the project into a Python package and add a
setup.py
file for distribution. - Status: β Not Started
- Refactor the project into a Python package and add a
-
Add Documentation
- Expand the
README.md
and use tools like Sphinx to generate detailed documentation.
- Expand the
- Status: β Not Started
-
Optimize for Performance
- Add caching for repeated prompts using
functools.lru_cache
or a database like SQLite. - Status: β Not Started
- Add caching for repeated prompts using
-
Publish to GitHub
- Publish the project to GitHub, add a license, and encourage contributions from the open-source community.
- Status: β Not Started
- β Context-Aware Prompting
- β Conversation History
- β Text Summarization
- β Enhanced Error Handling
- π§ Retry Mechanism (max_retries=3)
-
Implement PostgreSQL database to store conversations
-- Create extensions for vector search capabilities CREATE EXTENSION IF NOT EXISTS vector; -- Create enum for persona types CREATE TYPE persona_type AS ENUM ('gym_coach', 'teacher', 'programmer', 'default'); -- Create conversations table CREATE TABLE conversations ( id SERIAL PRIMARY KEY, timestamp TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP, user_input TEXT NOT NULL, ai_response TEXT NOT NULL, active_persona persona_type DEFAULT 'default', context_tags TEXT[], embedding vector(1536), -- For semantic search metadata JSONB ); -- Create index for efficient context search CREATE INDEX idx_conversations_timestamp ON conversations(timestamp); CREATE INDEX idx_conversations_persona ON conversations(active_persona); CREATE INDEX idx_conversations_embedding ON conversations USING ivfflat (embedding vector_cosine_ops);
-
Required PostgreSQL setup:
sudo apt install postgresql postgresql-contrib sudo systemctl start postgresql sudo -u postgres createdb gemini_cli
-
Dependencies to add in requirements.txt:
psycopg2-binary>=2.9.9 sqlalchemy>=2.0.0 alembic>=1.12.0
-
Status: β Not Started
- Create persona configuration system
- Add persona commands:
python src/main.py --set-persona "gym_coach" python src/main.py --list-personas
- Status: β Not Started
- Implement sliding context window
- Add context pruning strategies
- Status: β Not Started
- Short-term memory (current session)
- Long-term memory (persistent storage)
- Working memory (active context)
- Status: β Not Started
- Implement vector embeddings
- Add memory commands:
python src/main.py --search "previous workouts" python src/main.py --context-depth deep
- Status: β Not Started
- Add thread management:
python src/main.py --new-thread "workout_plan" python src/main.py --switch-thread "diet_advice"
- Status: β Not Started
- Periodic memory summarization
- Knowledge base updates
- Status: β Not Started
- Track user interactions
- Adapt persona behavior
- Status: β Not Started
- Enhance GeminiAgent class
- Add memory management methods
- Status: β Not Started
- Implement caching
- Optimize database queries
- Status: β Not Started
Let's get to work. There's a lot to be done.