codecache


Namecodecache JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/dineshrai/codecache
SummaryProvide LLMs with codebase context for improved coding assistance.
upload_time2024-09-13 18:54:12
maintainerNone
docs_urlNone
authorDinesh Rai
requires_python>=3.7
licenseNone
keywords codebase analysis gemini api context caching code summarization cli tool llm coding assistance
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # CodeCache

CodeCache is a Python package that allows developers to analyze their codebase and cache the context using the Gemini API's context caching feature. This tool helps in generating summaries and insights about your codebase, enabling efficient querying and interaction with large codebases.

## Features

- **Codebase Analysis**: Recursively analyzes your codebase, generating summaries for each file.
- **Context Caching**: Utilizes the Gemini API to cache the context of your codebase, reducing the need to pass the same input tokens repeatedly.
- **Querying**: Allows querying the cached context to get insights or answers related to your codebase.
- **Summarization**: Supports both quick and detailed summaries of your codebase.
- **Customizable**: Configurable options for ignoring files/directories, setting cache TTL, and choosing summary modes.
- **CLI Interface**: Provides a user-friendly command-line interface for all functionalities.

## Installation

You can install CodeCache via pip:

```bash
pip install codecache
```

Alternatively, you can install it from source:

```bash
git clone https://github.com/DineshRai/codecache.git
cd codecache
pip install .
```

### Prerequisites

- Python 3.7 or higher
- Gemini API key (you can get one from Google AI Studio)

## Usage

### Setting Up the Environment

Before using CodeCache, you need to set the `GEMINI_API_KEY` environment variable:

```bash
export GEMINI_API_KEY='your_api_key_here'
```

You can also create a `.env` file in your project root:

```
GEMINI_API_KEY=your_api_key_here
```

### Command-Line Interface

CodeCache provides a CLI with several commands. You can get help by running:

```bash
codecache --help
```

#### Analyzing and Caching Context

To analyze your codebase and cache the context:

```bash
codecache cache [DIRECTORY] [OPTIONS]
```

- `DIRECTORY`: The root directory of your codebase (default is the current directory).
- Options:
  - `--ignore-file`: Path to a custom ignore file. If not provided, `.codecachignore` in the root directory will be used if it exists.
  - `--ttl`: Cache time-to-live in seconds (default: 3600).
  - `--summary-mode`: Summary mode to use (quick or detailed, default: quick).
  - `--model`: Gemini model to use (e.g., gemini-1.5-flash-001).
  - `--verbose` or `-v`: Enable verbose output.

Example:

```bash
codecache cache . --ttl 7200 --summary-mode detailed --model gemini-1.5-pro-001 --verbose
```

#### Querying the Cached Context

To query the cached context:

```bash
codecache query CACHE_KEY QUERY
```

- `CACHE_KEY`: The cache key returned when you cached the context.
- `QUERY`: The question or query you want to ask about your codebase.

Example:

```bash
codecache query your_cache_key "What does the CacheManager class do?"
```

#### Other Commands

- List cached contexts: `codecache list-caches`
- Update cache TTL: `codecache update-ttl CACHE_KEY NEW_TTL`
- Delete a cached context: `codecache delete-cache CACHE_KEY`

## Configuration

### Ignore Files

You can specify files or directories to ignore during analysis by creating a `.codecachignore` file in your project root:

```
# Ignore all .pyc files
*.pyc

# Ignore the build directory
build/

# Ignore specific files
secret_config.py
```

Alternatively, you can specify a custom ignore file using the `--ignore-file` option.

### Config File

You can configure default settings by creating a `.codebase_context` file in your project root (in TOML format):

```toml
[settings]
gemini_model = "gemini-1.5-flash-001"
default_ttl = 3600
ignore_file = ".codecachignore"
```

## Examples

### Quick Start

Analyze and Cache Context:

```bash
codecache cache .
```

Query the Cached Context:

```bash
codecache query your_cache_key "Explain the purpose of the Summarizer class."
```

### Logging and Verbose Output

To enable verbose logging, add the `--verbose` or `-v` flag to any command:

```bash
codecache cache . --verbose
```

## Development and Contribution

Contributions are welcome! Please follow these steps to contribute:

1. Fork the repository.
2. Create a new branch for your feature or bug fix.
3. Write your code and tests.
4. Submit a pull request.

### Setting Up for Development

```bash
git clone https://github.com/DineshRai/codecache.git
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install -e .
```

### Running Tests

We use pytest for testing. To run tests:

```bash
pytest tests/
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Acknowledgments

- Google Gemini API for the context caching feature.
- Click for the command-line interface.
- Python dotenv for managing environment variables.

## Contact

For questions, feedback, or issues related to CodeCache:

- GitHub: [@DineshRai](https://github.com/DineshRai)
- Email: drai89@gmail.com
- Bug reports and feature requests: Please use the [GitHub issue tracker](https://github.com/DineshRai/codecache/issues)

For security-related concerns, please email directly rather than creating a public issue.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dineshrai/codecache",
    "name": "codecache",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "codebase analysis, gemini api, context caching, code summarization, cli tool, LLM, coding assistance",
    "author": "Dinesh Rai",
    "author_email": "drai89@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b6/29/1af242aa4ba132821e879a7a634699ae32b30cb75b5e68c443355d2e7347/codecache-0.1.1.tar.gz",
    "platform": null,
    "description": "# CodeCache\n\nCodeCache is a Python package that allows developers to analyze their codebase and cache the context using the Gemini API's context caching feature. This tool helps in generating summaries and insights about your codebase, enabling efficient querying and interaction with large codebases.\n\n## Features\n\n- **Codebase Analysis**: Recursively analyzes your codebase, generating summaries for each file.\n- **Context Caching**: Utilizes the Gemini API to cache the context of your codebase, reducing the need to pass the same input tokens repeatedly.\n- **Querying**: Allows querying the cached context to get insights or answers related to your codebase.\n- **Summarization**: Supports both quick and detailed summaries of your codebase.\n- **Customizable**: Configurable options for ignoring files/directories, setting cache TTL, and choosing summary modes.\n- **CLI Interface**: Provides a user-friendly command-line interface for all functionalities.\n\n## Installation\n\nYou can install CodeCache via pip:\n\n```bash\npip install codecache\n```\n\nAlternatively, you can install it from source:\n\n```bash\ngit clone https://github.com/DineshRai/codecache.git\ncd codecache\npip install .\n```\n\n### Prerequisites\n\n- Python 3.7 or higher\n- Gemini API key (you can get one from Google AI Studio)\n\n## Usage\n\n### Setting Up the Environment\n\nBefore using CodeCache, you need to set the `GEMINI_API_KEY` environment variable:\n\n```bash\nexport GEMINI_API_KEY='your_api_key_here'\n```\n\nYou can also create a `.env` file in your project root:\n\n```\nGEMINI_API_KEY=your_api_key_here\n```\n\n### Command-Line Interface\n\nCodeCache provides a CLI with several commands. You can get help by running:\n\n```bash\ncodecache --help\n```\n\n#### Analyzing and Caching Context\n\nTo analyze your codebase and cache the context:\n\n```bash\ncodecache cache [DIRECTORY] [OPTIONS]\n```\n\n- `DIRECTORY`: The root directory of your codebase (default is the current directory).\n- Options:\n  - `--ignore-file`: Path to a custom ignore file. If not provided, `.codecachignore` in the root directory will be used if it exists.\n  - `--ttl`: Cache time-to-live in seconds (default: 3600).\n  - `--summary-mode`: Summary mode to use (quick or detailed, default: quick).\n  - `--model`: Gemini model to use (e.g., gemini-1.5-flash-001).\n  - `--verbose` or `-v`: Enable verbose output.\n\nExample:\n\n```bash\ncodecache cache . --ttl 7200 --summary-mode detailed --model gemini-1.5-pro-001 --verbose\n```\n\n#### Querying the Cached Context\n\nTo query the cached context:\n\n```bash\ncodecache query CACHE_KEY QUERY\n```\n\n- `CACHE_KEY`: The cache key returned when you cached the context.\n- `QUERY`: The question or query you want to ask about your codebase.\n\nExample:\n\n```bash\ncodecache query your_cache_key \"What does the CacheManager class do?\"\n```\n\n#### Other Commands\n\n- List cached contexts: `codecache list-caches`\n- Update cache TTL: `codecache update-ttl CACHE_KEY NEW_TTL`\n- Delete a cached context: `codecache delete-cache CACHE_KEY`\n\n## Configuration\n\n### Ignore Files\n\nYou can specify files or directories to ignore during analysis by creating a `.codecachignore` file in your project root:\n\n```\n# Ignore all .pyc files\n*.pyc\n\n# Ignore the build directory\nbuild/\n\n# Ignore specific files\nsecret_config.py\n```\n\nAlternatively, you can specify a custom ignore file using the `--ignore-file` option.\n\n### Config File\n\nYou can configure default settings by creating a `.codebase_context` file in your project root (in TOML format):\n\n```toml\n[settings]\ngemini_model = \"gemini-1.5-flash-001\"\ndefault_ttl = 3600\nignore_file = \".codecachignore\"\n```\n\n## Examples\n\n### Quick Start\n\nAnalyze and Cache Context:\n\n```bash\ncodecache cache .\n```\n\nQuery the Cached Context:\n\n```bash\ncodecache query your_cache_key \"Explain the purpose of the Summarizer class.\"\n```\n\n### Logging and Verbose Output\n\nTo enable verbose logging, add the `--verbose` or `-v` flag to any command:\n\n```bash\ncodecache cache . --verbose\n```\n\n## Development and Contribution\n\nContributions are welcome! Please follow these steps to contribute:\n\n1. Fork the repository.\n2. Create a new branch for your feature or bug fix.\n3. Write your code and tests.\n4. Submit a pull request.\n\n### Setting Up for Development\n\n```bash\ngit clone https://github.com/DineshRai/codecache.git\npython3 -m venv venv\nsource venv/bin/activate\npip install -r requirements.txt\npip install -e .\n```\n\n### Running Tests\n\nWe use pytest for testing. To run tests:\n\n```bash\npytest tests/\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n\n- Google Gemini API for the context caching feature.\n- Click for the command-line interface.\n- Python dotenv for managing environment variables.\n\n## Contact\n\nFor questions, feedback, or issues related to CodeCache:\n\n- GitHub: [@DineshRai](https://github.com/DineshRai)\n- Email: drai89@gmail.com\n- Bug reports and feature requests: Please use the [GitHub issue tracker](https://github.com/DineshRai/codecache/issues)\n\nFor security-related concerns, please email directly rather than creating a public issue.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Provide LLMs with codebase context for improved coding assistance.",
    "version": "0.1.1",
    "project_urls": {
        "Bug Reports": "https://github.com/dineshrai/codecache/issues",
        "Homepage": "https://github.com/dineshrai/codecache",
        "Source": "https://github.com/dineshrai/codecache"
    },
    "split_keywords": [
        "codebase analysis",
        " gemini api",
        " context caching",
        " code summarization",
        " cli tool",
        " llm",
        " coding assistance"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "08d527bea17ddfa5f2ae053d8a942b267fadba2667e844435dbad021f20467f0",
                "md5": "daa5e4ddb6455360c693b53f629c3806",
                "sha256": "03ba7eb17325c272d4302af49777b4e67c5f4bcc57f8c844dbd8c17f2e0f38e5"
            },
            "downloads": -1,
            "filename": "codecache-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "daa5e4ddb6455360c693b53f629c3806",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 13316,
            "upload_time": "2024-09-13T18:54:10",
            "upload_time_iso_8601": "2024-09-13T18:54:10.335415Z",
            "url": "https://files.pythonhosted.org/packages/08/d5/27bea17ddfa5f2ae053d8a942b267fadba2667e844435dbad021f20467f0/codecache-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b6291af242aa4ba132821e879a7a634699ae32b30cb75b5e68c443355d2e7347",
                "md5": "923e271a30dc659f1d43572ec3e3c959",
                "sha256": "737844182ca139d46c2159469a872e8f8cb32c9941897b49d2e477ece0ed3afe"
            },
            "downloads": -1,
            "filename": "codecache-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "923e271a30dc659f1d43572ec3e3c959",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 13699,
            "upload_time": "2024-09-13T18:54:12",
            "upload_time_iso_8601": "2024-09-13T18:54:12.005642Z",
            "url": "https://files.pythonhosted.org/packages/b6/29/1af242aa4ba132821e879a7a634699ae32b30cb75b5e68c443355d2e7347/codecache-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-13 18:54:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dineshrai",
    "github_project": "codecache",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "codecache"
}
        
Elapsed time: 0.57758s