Package: chatgpt-pre-commit-hooks
🤖 ChatGPT / OpenAI pre-commit-hooksPre-commit hooks collection that utilizes ChatGPT and OpenAI platform to validate changes made to the codebase.🎣 Hookschatgpt-commit-message📥 Prerequisites setupOpenAI PlatformAzure OpenAI ServiceSetting environment variablespre-commit setup📦 Hooks setupRemote repository reference (preferred)Local repository reference🛠️ Advanced configurationExtra environment variablesArguments--env-prefixVariables precedence💸 Payments👥 Contributing📄 License🎣 Hookschatgpt-commit-messageHook that uses OpenAI's ChatGPT API to generate a summary of changes made to a codebase and use it to populate the commit message automatically.⚙️ Read about hook's specificconfiguration.📥 Prerequisites setupHooks supportOpenAI PlatformandAzure OpenAI Service.OpenAI PlatformOpenAI API Key is mandatory to run hooks and has to be setup via an environment variable.Create yourAPI Key, and get your Organization ID fromOrganization settingsStore values as an environment variables:OPENAI_API_KEYfor API KeyOPENAI_ORGANIZATIONfor Organization IDExample:exportOPENAI_API_KEY="sk-xxxxxx"exportOPENAI_ORGANIZATION="org-xxxxxx"💡HINTHow to setup environment variables? see:Setting environment variablesAzure OpenAI ServiceGo toAzure Portal, and getAPI Key,Endpoint,Model deployment name, andapi-version.The latest supportedapi-versionyou can get fromAzure OpenAI ServiceStore values as an environment variables:OPENAI_API_TYPEputazureto specified OpenAI providerOPENAI_API_KEYfor API KeyOPENAI_API_BASEfor EndpointOPENAI_API_VERSIONforapi-versionOPENAI_MODELfor Model deployment nameExample:exportOPENAI_API_TYPE="azure"exportOPENAI_API_KEY="xxxxxx"exportOPENAI_API_BASE="https://xxxxxx.openai.azure.com/"exportOPENAI_API_VERSION="2023-03-15-preview"exportOPENAI_MODEL="xxxxx-gpt-35-turbo"💡HINTHow to setup environment variables? see:Setting environment variablesSetting environment variablesLinux/MacOS example:exportOPENAI_API_KEY="sk-xxxxxx"Windowspowershellexample:$env:OPENAI_API_KEY="sk-xxxxxx"Windowscmdexample:set OPENAI_API_KEY=sk-xxxxxx⚠️NOTEThe above example stores the environment variable temporarily for the current session. To store it permanently, please followBest Practices for API Key Safetypre-commit setupBefore you start, ensure you havepre-commitinstalled in your repository. Below is just an essential quick start. Follow official pre-commitinstalldocumentation for advanced scenarios.# install using pippipinstallpre-commit# check if working - expected print with version like `pre-commit 3.2.2`pre-commit--versionAdd to your.pre-commit-config.yamltop leveldefault_install_hook_typessection (for more information, followConfining hooks to run at certain stages)default_install_hook_types:-pre-commit# this is default hook type, equivalent to classic `pre-commit install` command-prepare-commit-msg# this type is not enabled by default, please enable it - equivalent to `pre-commit install --hook-type prepare-commit-msg` command-...# rest of hook types what are you using, if anynext:# setup the git repo for hookspre-commitinstall# (optional) periodically run updates to your pre-commit config to make sure you always have the latest version of the hookspre-commitautoupdate📦 Hooks setupRemote repository reference (preferred)Add to your.pre-commit-config.yamldefault_install_hook_types:-pre-commit-prepare-commit-msgrepos:-repo:https://github.com/DariuszPorowski/chatgpt-pre-commit-hooksrev:vX.Y.Z# Use the ref you want to point at, see ⚠️ NOTE below!hooks:-id:<id1># follow 🎣 Hooks section to see available hooks IDs-id:<id2># follow 🎣 Hooks section to see available hooks IDs-id:...Example:default_install_hook_types:-pre-commit-prepare-commit-msgrepos:-repo:https://github.com/DariuszPorowski/chatgpt-pre-commit-hooksrev:v0.1.3hooks:-id:chatgpt-commit-message⚠️NOTEFor therev:always try to use the latest version. You can check the latest release underGitHub ReleasesLocal repository referenceInstall or addPyPIpackage to your project.if you are usingpip:pipinstall--upgradechatgpt-pre-commit-hooksor include it in arequirements.txtfile in your project:chatgpt-pre-commit-hooks~=0.1.3and run:pipinstall-rrequirements.txtor, even better, in thedevsection of yourpyproject.tomlfile:[project.optional-dependencies]dev=["chatgpt-pre-commit-hooks"]and run:pipinstall.[dev]or, if you are usingpoetryas a package manager:poetryaddchatgpt-pre-commit-hooks--groupdevAdd to your.pre-commit-config.yamldefault_install_hook_types:-pre-commit-prepare-commit-msgrepos:-repo:localhooks:-id:<id># follow 🎣 Hooks section to see available hooks IDsname:<name># any name you'd like to setentry:chatgpt-pre-commit-hooksargs:-"--hook"-"<id>"# follow 🎣 Hooks section to see available hooks IDs-"..."# rest of args what you'd like to set (optional)language:systemExample:default_install_hook_types:-pre-commit-prepare-commit-msgrepos:-repo:localhooks:-id:chatgpt-commit-messagename:ChatGPT commit messageentry:chatgpt-pre-commit-hooksargs:-"--hook"-"chatgpt-commit-message"-"--description"-"--emoji"language:system🛠️ Advanced configurationExtra environment variablesIn addition to the environment variables listed in the📥 Prerequisites setupsection, you can set several configurations using extra environment variables.NameTypeDefaultDescriptionOPENAI_MAX_TOKENSint1024What are tokens and how to count them?OPENAI_MODELstringgpt-3.5-turboModel endpoint compatibility- check/v1/chat/completionsendpointOPENAI_PROXYstringnot sethttp/https client proxyArgumentsAny environment variable can be overridden by hard-coded arguments inpre-commit-config.yaml, exceptOPENAI_API_KEY,OPENAI_ORGANIZATION.NameTypeDefaultDescription--env-prefixstringnot setSet prefix for environment variables allowing multiple configurations. Read more:--env-prefix--openai-max-tokensintnot setOverridesOPENAI_MAX_TOKENS--openai-proxystringnot setOverridesOPENAI_PROXY--openai-modelstringnot setOverridesOPENAI_MODEL--openai-api-basestringnot setOverridesOPENAI_API_BASE--openai-api-typestringnot setOverridesOPENAI_API_TYPEExample:default_install_hook_types:-pre-commit-prepare-commit-msgrepos:-repo:https://github.com/DariuszPorowski/chatgpt-pre-commit-hooksrev:vX.Y.Zhooks:-id:...# follow 🎣 Hooks section to see available hooks IDsargs:-"--env-prefix"-"personal"-"--openai-max-tokens"-"512"-...--env-prefixIt's a special argument where you can mark prefixes for your environment variables. This allows you to set many configurations depending on the project, account, profile, etc., for example,personal,work. Fallback is a global environment variable if prefixed isn't found.For instance, if your prefix ispersonal, then the environment variable must be setPERSONAL__OPENAI_MAX_TOKENS, meaning the structure is<prefix>__<base_env_name>- two underscores__betweenprefixandbase_env_name.Example:exportPERSONAL__OPENAI_API_KEY="sk-xxxxxx"exportWORK__OPENAI_API_KEY="sk-xxxxxx"Variables precedencehard-coded arguments, for example--openai-max-tokensprefixed environment variable, for examplePERSONAL__OPENAI_MAX_TOKENSglobal environment variable, for exampleOPENAI_MAX_TOKENS💸 PaymentsProject by default usesgpt-3.5-turbomodel because ofits lower cost. You have to pay for your own OpenAI API requests.👥 ContributingContributions to the project are welcome! Please followContributing Guide.📄 LicenseThis project is distributed under the terms of theMITlicense.