Skip to main content

GenSh - Generate and execute code using natural language

Project description

GenSh - Generate and Execute Shell

GenSh is a command-line tool that allows you to generate and execute code using natural language prompts. It leverages large language models to translate your queries into Python or shell code and then executes the generated code. The intenation of this tool is to assist in software and security research.

Requirements

GenSh requires the following:

  • Python 3.11 or higher
  • OpenAI API key (for GPT-3.5 or GPT-4 access)
  • Anthropic API key (for Claude access)
  • Ollama installed locally (for running local models)
  • Dependencies (installed automatically):
    • openai>=1.0.0
    • anthropic>=0.3.0
    • PyYAML>=6.0
    • ollama>=0.1.0
    • python-dotenv>=0.19.0
    • markdown>=3.3.0
    • requests>=2.25.0
    • beautifulsoup4>=4.9.3

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/gensh.git
    cd gensh
    
  2. Install the package:

    pip install .
    

Setting up API Keys

Create a .env file in the root directory of your project and add your API keys:

OPENAI_API_KEY=your_openai_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here

Usage

Interactive Mode

To start the interactive shell:

gensh

Command-Line Execution

To run a single command:

gensh -c 'python_code "find your ip address" | exec_python'

Prepare Templates for copying

To read inbuilt templates for processing by genai agents:

gensh -l book | pbcopy

TODO: Batch Processing

To process commands from a file:

gensh -f example_batch.gensh

Verbose Mode

Enable verbose output:

gensh -v

Custom Configuration

Use a custom configuration file:

gensh --config /path/to/custom_config.json

Configuration

Create a configuration file at ~/.gensh_config.json with the following structure:

{
    "template_dir": "templates",
    "model": "gpt-3.5-turbo",
    "execution_timeout": 30,
    "max_retries": 3,
    "retry_delay": 1,
    "db_path": "gensh_logs.db",
    "output_format": "text"
}

Development

To set up a development environment:

  1. Clone the repository
  2. Install dependencies: pip install -e ".[dev]" or poetry install
  3. Run tests: pytest tests/

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Inspirations

BUGS / FEATURES / TODO

[x] Generate and execute Python or shell code from natural language queries [x] Support for multiple LLM backends: OpenAI GPT, Anthropic Claude, and Ollama [x] Web search integration to improve code generation [x] Interactive shell mode [x] Command-line execution mode [x] Configurable settings via JSON configuration file [x] Verbose mode for detailed output [x] Error handling and retry logic for code generation [x] Pre-defined templates for common tasks [x] Logging of language model calls to SQLite database [x] Session-based conversation history [x] API token management using .env file [x] Bug: Release base templates with the shell, list_templates is broken. DONE: added resources [x] Bug: History functionality doesnt work - DONE: added show_model commands [x] Feat: Ability to inject on variables in templates, ask for template input [ ] Feat: Add Experimental MCP Support [ ] Feat: Add test cases for functionality like generate | parse_context | exec_code [ ] Feat: Add an eval suite which is based on exercism.org code templates [ ] Feat: Add voice capability [ ] Feat: Multiple output formats: text, Markdown, and Word document (docx) [ ] Feat: Batch processing of commands from a file [ ] Feat: Refactor code [ ] Feat: Update docs [ ] Feat: Ability to edit files in the whole_format [ ] Feat: Generate sensible message for git commit changes [ ] Add analyze_logs use case to gensh

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gensh-0.8.11.tar.gz (32.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gensh-0.8.11-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file gensh-0.8.11.tar.gz.

File metadata

  • Download URL: gensh-0.8.11.tar.gz
  • Upload date:
  • Size: 32.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.2

File hashes

Hashes for gensh-0.8.11.tar.gz
Algorithm Hash digest
SHA256 ad14f436f32074140f3781b30b4245c372f8bccbc6c963068489fc1d73f41523
MD5 3c9880d6a10561e97a7fce0baad6bc2b
BLAKE2b-256 223bd1ec6a20c8e4916b97f3eb7183789995a496e0b3a4c4e85914c45698a639

See more details on using hashes here.

File details

Details for the file gensh-0.8.11-py3-none-any.whl.

File metadata

  • Download URL: gensh-0.8.11-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.2

File hashes

Hashes for gensh-0.8.11-py3-none-any.whl
Algorithm Hash digest
SHA256 5486cfd4c89114fe230161690bba7a25c9e086db3fd001c297a368161df2cff8
MD5 f2e5956d92916f9b311e60baaec7de6e
BLAKE2b-256 8bcb8674b4e289e7b375955e360aa0dd492ca408572509c2d89af64f90d2da63

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page