Git Product home page Git Product logo

error-explainer's Introduction

Code Explainer: An Error Explanation Assistant

A Python script designed to run in the background, listening for specific hotkeys. When triggered, it uses the OLLAMA Large Language Model to explain coding errors in the selected text, displaying the explanations in a sleek, macOS lookup-style popup. This utility, consisting of less than 100 lines of code, enhances coding efficiency by providing instant, in-context explanations of errors directly within your text editor or IDE.

This project extends the concept by leveraging AI not just for corrections but for providing insights into coding mistakes, facilitating a faster and more informed coding process.

Getting Started

1. Set up OLLAMA

First, ensure you have OLLAMA installed and running on your system. OLLAMA is an AI model server that can be easily set up and queried for various tasks, including explaining coding errors.

Installation guide for OLLAMA: https://github.com/ollama/ollama

Start the model suitable for explaining code:

ollama run codellama

While the Mistral 7B Instruct model is recommended for its adeptness at explaining code, feel free to explore and utilize other models that OLLAMA supports.

2. Install Required Dependencies

Ensure the following Python libraries are installed to use the script effectively:

pip install pynput pyperclip httpx tkinter
  • pynput: For monitoring and controlling the keyboard. Documentation
  • pyperclip: For accessing and modifying the system clipboard. GitHub
  • httpx: A fully featured HTTP client for Python 3. Documentation
  • tkinter: Python's de-facto standard GUI (Graphical User Interface) package.

3. Run the Assistant

Execute the script to start the typing assistant:

python main.py

Hotkeys to trigger explanations:

  • Ctrl+Cmd+e: Explain the error in the current selection.

Ensure you select the piece of code with a potential error before pressing the hotkey.

Note: This script is tailored for macOS. Key bindings such as Key.cmd might require adjustments for compatibility with other operating systems, e.g., changing to Key.ctrl for Windows or Linux environments.

Customization

The script offers flexible customization options, including hotkeys, prompt templates, and OLLAMA configuration, to suit your preferences and needs.

Example Prompt Templates

Customize your prompts to OLLAMA for different tasks. Here are some examples you might find useful:

from string import Template

# Template for explaining coding errors
PROMPT_TEMPLATE_EXPLAIN_ERROR = Template(
    """Explain the following coding error in detail:

$error
"""
)

# Template for generating text based on a topic
PROMPT_TEMPLATE_GENERATE_TEXT = Template(
    """Generate a paragraph about the following topic, incorporating humor and insight:

$text
"""
)

# Template for summarizing text
PROMPT_TEMPLATE_SUMMARIZE_TEXT = Template(
    """Summarize the following text in a concise and informative manner:

$text
"""
)

Adapt and expand these templates as needed to harness the full potential of the OLLAMA model for your coding and writing tasks.

error-explainer's People

Contributors

hamedyaghoobian avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.