From 193c490f6150defa3e1daeaf3a46c6205e6d68fb Mon Sep 17 00:00:00 2001 From: Max P Date: Mon, 19 Aug 2024 16:30:31 +0200 Subject: [PATCH] Add README.md with usage instructions - Created a `README.md` file - Added descriptions for the project's purpose and features - Provided installation steps and prerequisites - Included usage instructions with command-line options - Detailed example configuration file - Added error handling information - Documented the license and contributing guidelines --- README.md | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b024158 --- /dev/null +++ b/README.md @@ -0,0 +1,100 @@ +# AI-Generated Messages from Git Diffs and Logs + +This script uses the OpenAI API to generate text based on the outputs of `git diff` and `git log` commands. It can be particularly useful for creating pull request descriptions, commit messages, or any other narrative that requires summarizing changes between different branches or commits in a Git repository. + +## Features + +- **Automated Message Generation**: The script generates text based on Git diffs and logs using OpenAI's GPT models. +- **Customizable Prompts**: You can configure both the system and user prompts to guide the generated text. +- **Flexible Configuration**: Supports custom configuration through JSON files, allowing for different setups and use cases. +- **Easy Configuration Management**: The script can load configurations via command-line arguments or shorthand keywords, making it convenient to switch between different setups. + +## Prerequisites + +- **Python 3.x** +- **Git**: Ensure that Git is installed and available in your system's PATH. +- **OpenAI API Key**: You need an OpenAI API key to use the GPT models. + +## Installation + +Clone the repository and navigate to the directory: + +```bash +git clone https://github.com/your-repository.git +cd your-repository +``` + +Install the necessary Python packages: + +```bash +pip install openai +``` + +## Usage + +### Basic Usage + +To generate a message based on the current branch's diff and log against the main branch, simply run: + +```bash +python ait.py +``` + +This will use the default configuration file (`ait.config.json`) located in the current directory. + +### Using Custom Configurations + +You can specify a different configuration file using the `--config` option: + +```bash +python ait.py --config custom_config.json +``` + +#### Shorthand Configuration Selection + +Alternatively, if you only provide a keyword, the script will look for a file named `ait..config.json` in the current directory: + +```bash +python ait.py --config KAI +``` + +This command will look for a configuration file named `ait.KAI.config`. + +### Command-Line Options + +- `--config`: Path to a JSON config file or a keyword to identify a specific config (`ait..config`). Default is `ait.config.json`. +- `--api_key`: Your OpenAI API key. If not provided, the script looks for it in the config file. +- `--diff_expression`: The Git diff expression to use. Default is `main...`. +- `--log_expression`: The Git log expression used to retrieve the commit history. Default is `main...`. +- `--system_prompt`: The system prompt to set the behavior of the assistant. +- `--prompt`: The user prompt to guide the description creation. +- `--model`: The model to use, such as `"gpt-4"`. You can change this depending on the available models in your API. +- `--max_tokens`: The maximum number of tokens (words or parts of words) in the API response. Default is `150`. +- `--temperature`: Controls the randomness or creativity of the model's output. Lower values make the output more deterministic, while higher values make it more random. Default is `0.7`. + +### Example Config File (`ait.config.json.sample`) + +```json +{ + "api_key": "YOUR_OPENAI_API_KEY_HERE", + "diff_expression": "main...", + "log_expression": "main...", + "system_prompt": "You are a helpful assistant that creates pull request descriptions.", + "prompt": "Please create a pull request description based on these changes.", + "model": "gpt-4", + "max_tokens": 150, + "temperature": 0.7 +} +``` + +### Error Handling + +The script will raise an error if the API key is not provided either via the command-line argument or the configuration file. + +## License + +This project is licensed under the MIT License. See the LICENSE file for more details. + +## Contributing + +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.