{"id":13471437,"url":"https://github.com/appleboy/CodeGPT","last_synced_at":"2025-03-26T13:31:05.643Z","repository":{"id":112744245,"uuid":"609542180","full_name":"appleboy/CodeGPT","owner":"appleboy","description":"A CLI written in Go language that writes git commit messages or do a code review brief for you using ChatGPT AI (gpt-4o, gpt-4-turbo, gpt-3.5-turbo model) and automatically installs a git prepare-commit-msg hook.","archived":false,"fork":false,"pushed_at":"2025-03-19T13:53:20.000Z","size":1289,"stargazers_count":1369,"open_issues_count":11,"forks_count":124,"subscribers_count":17,"default_branch":"main","last_synced_at":"2025-03-21T17:06:53.523Z","etag":null,"topics":["chatgpt","chatgpt-api","git","git-hook","golang","openai","openai-api"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/appleboy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":["https://www.paypal.me/appleboy46"]}},"created_at":"2023-03-04T13:49:29.000Z","updated_at":"2025-03-21T04:44:00.000Z","dependencies_parsed_at":"2023-12-26T09:05:01.517Z","dependency_job_id":"913d5224-68ed-4d04-8ae9-23a589ba1788","html_url":"https://github.com/appleboy/CodeGPT","commit_stats":{"total_commits":347,"total_committers":22,"mean_commits":"15.772727272727273","dds":0.06916426512968299,"last_synced_commit":"9218f84bd1d7a4c657c04b568574315db9db6d44"},"previous_names":[],"tags_count":59,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appleboy%2FCodeGPT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appleboy%2FCodeGPT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appleboy%2FCodeGPT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appleboy%2FCodeGPT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/appleboy","download_url":"https://codeload.github.com/appleboy/CodeGPT/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245662798,"owners_count":20652085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatgpt","chatgpt-api","git","git-hook","golang","openai","openai-api"],"created_at":"2024-07-31T16:00:44.859Z","updated_at":"2025-03-26T13:31:05.636Z","avatar_url":"https://github.com/appleboy.png","language":"Go","readme":"# CodeGPT\n\n[![Lint and Testing](https://github.com/appleboy/CodeGPT/actions/workflows/testing.yml/badge.svg?branch=main)](https://github.com/appleboy/CodeGPT/actions/workflows/testing.yml)\n[![codecov](https://codecov.io/gh/appleboy/CodeGPT/branch/main/graph/badge.svg)](https://codecov.io/gh/appleboy/CodeGPT)\n[![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/CodeGPT)](https://goreportcard.com/report/github.com/appleboy/CodeGPT)\n\n![cover](./images/cover.png)\n\nEnglish | [繁體中文](./README.zh-tw.md) | [简体中文](./README.zh-cn.md)\n\nA CLI tool written in [Go](https://go.dev) that generates git commit messages or provides code review summaries using ChatGPT AI (gpt-4o, gpt-4 model). It also automatically installs a [git prepare-commit-msg hook](https://git-scm.com/docs/githooks).\n\n- [繁體中文介紹][1]\n- [繁體中文影片][2]\n\n[1]: https://blog.wu-boy.com/2023/03/writes-git-commit-messages-using-chatgpt/\n[2]: https://www.youtube.com/watch?v=4Yei_t6eMZU\n\n![flow](./images/flow.svg)\n\n## Features\n\n- Supports [Azure OpenAI Service](https://azure.microsoft.com/en-us/products/cognitive-services/openai-service), [OpenAI API](https://platform.openai.com/docs/api-reference), [Gemini][60], [Anthropic][100], [Ollama][41], [Groq][30], and [OpenRouter][50].\n- Adheres to the [conventional commits specification](https://www.conventionalcommits.org/en/v1.0.0/).\n- Integrates with Git prepare-commit-msg Hook, see the [Git Hooks documentation](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks).\n- Allows customization of generated diffs with a specified number of context lines (default is three).\n- Enables exclusion of files from the git diff command.\n- Translates commit messages into other languages (supports `en`, `zh-tw`, or `zh-cn`).\n- Supports SOCKS proxy or custom network HTTP proxy.\n- Provides a [model list](https://github.com/appleboy/CodeGPT/blob/bf28f000463cfc6dfa2572df61e1b160c5c680f7/openai/openai.go#L18-L38) including `gpt-4`, `gpt-4o`, etc.\n- Generates brief code reviews.\n- Allows customization of prompt templates and variables.\n\n![code review](./images/code_review.png)\n\n## Installation\n\n### macOS\n\nInstall via [Homebrew](http://brew.sh/):\n\n```sh\nbrew tap appleboy/tap\nbrew install codegpt\n```\n\n### Windows\n\nInstall via [Chocolatey](https://chocolatey.org/install):\n\n```sh\nchoco install codegpt\n```\n\n### Pre-compiled Binaries\n\nDownload the pre-compiled binaries from the [release page](https://github.com/appleboy/CodeGPT/releases). Change the binary permissions to `755` and copy the binary to the system bin directory. Use the `codegpt` command as shown below:\n\n```sh\n$ codegpt version\nversion: v0.4.3 commit: xxxxxxx\n```\n\n### From Source\n\nInstall from source code:\n\n```sh\ngo install github.com/appleboy/CodeGPT/cmd/codegpt@latest\n```\n\n## Setup\n\nFirst, create your OpenAI API Key. The [OpenAI Platform](https://platform.openai.com/account/api-keys) allows you to generate a new API Key.\n\n![register](./images/register.png)\n\nSet the environment variable `OPENAI_API_KEY`:\n\n```sh\nexport OPENAI_API_KEY=sk-xxxxxxx\n```\n\nAlternatively, store your API key in a custom config file:\n\n```sh\ncodegpt config set openai.api_key sk-xxxxxxx\n```\n\nThis will create a `.codegpt.yaml` file in your home directory ($HOME/.config/codegpt/.codegpt.yaml). The following options are available:\n\n| Option                       | Description                                                                                                                                                                    |\n| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| **openai.base_url**          | Replace the default base URL (`https://api.openai.com/v1`).                                                                                                                    |\n| **openai.api_key**           | Generate API key from [openai platform page](https://platform.openai.com/account/api-keys).                                                                                    |\n| **openai.org_id**            | Identifier for this organization sometimes used in API requests. See [organization settings](https://platform.openai.com/account/org-settings). Only for `openai` service.     |\n| **openai.model**             | Default model is `gpt-4o`, you can change to other custom model (Groq or OpenRouter provider).                                                                                 |\n| **openai.proxy**             | HTTP/HTTPS client proxy.                                                                                                                                                       |\n| **openai.socks**             | SOCKS client proxy.                                                                                                                                                            |\n| **openai.timeout**           | Default HTTP timeout is `10s` (ten seconds).                                                                                                                                   |\n| **openai.skip_verify**       | Default skip_verify is `false`, You can change it to `true` to ignore SSL verification.                                                                                        |\n| **openai.max_tokens**        | Default max tokens is `300`. See reference [max_tokens](https://platform.openai.com/docs/api-reference/completions/create#completions/create-max_tokens).                      |\n| **openai.temperature**       | Default temperature is `1`. See reference [temperature](https://platform.openai.com/docs/api-reference/completions/create#completions/create-temperature).                     |\n| **git.diff_unified**         | Generate diffs with `\u003cn\u003e` lines of context, default is `3`.                                                                                                                    |\n| **git.exclude_list**         | Exclude file from `git diff` command.                                                                                                                                          |\n| **openai.provider**          | Default service provider is `openai`, you can change to `azure`.                                                                                                               |\n| **output.lang**              | Default language is `en` and available languages `zh-tw`, `zh-cn`, `ja`.                                                                                                       |\n| **openai.top_p**             | Default top_p is `1.0`. See reference [top_p](https://platform.openai.com/docs/api-reference/completions/create#completions/create-top_p).                                     |\n| **openai.frequency_penalty** | Default frequency_penalty is `0.0`. See reference [frequency_penalty](https://platform.openai.com/docs/api-reference/completions/create#completions/create-frequency_penalty). |\n| **openai.presence_penalty**  | Default presence_penalty is `0.0`. See reference [presence_penalty](https://platform.openai.com/docs/api-reference/completions/create#completions/create-presence_penalty).    |\n| **prompt.folder**            | Default prompt folder is `$HOME/.config/codegpt/prompt`.                                                                                                                       |\n\n### How to Customize the Default Prompt Folder\n\nThe default prompt folder is located at `$HOME/.config/codegpt/prompt`. You can change this to another directory by executing:\n\n```sh\ncodegpt config set prompt.folder /path/to/your/prompt\n```\n\nTo load the prompt files from the custom folder, run:\n\n```sh\ncodegpt prompt --load\n```\n\nUpon execution, you will see messages similar to the following:\n\n```sh\nsave code_review_file_diff.tmpl to /Users/xxxxx/.config/codegpt/prompt/code_review_file_diff.tmpl\nsave summarize_file_diff.tmpl to /Users/xxxxx/.config/codegpt/prompt/summarize_file_diff.tmpl\nsave summarize_title.tmpl to /Users/xxxxx/.config/codegpt/prompt/summarize_title.tmpl\nsave conventional_commit.tmpl to /Users/xxxxx/.config/codegpt/prompt/conventional_commit.tmpl\n```\n\n- [code_review_file_diff.tmpl](./prompt/templates/code_review_file_diff.tmpl)\n- [summarize_file_diff.tmpl](./prompt/templates/summarize_file_diff.tmpl)\n- [summarize_title.tmpl](./prompt/templates/summarize_title.tmpl)\n- [conventional_commit.tmpl](./prompt/templates/conventional_commit.tmpl)\n\n### How to Change to Azure OpenAI Service\n\nGet the `API key`, `Endpoint`, and `Model deployments` list from the Azure Resource Management Portal on the left menu.\n\n![azure01](./images/azure_01.png)\n\n![azure02](./images/azure_02.png)\n\nUpdate your config file:\n\n```sh\ncodegpt config set openai.provider azure\ncodegpt config set openai.base_url https://xxxxxxxxx.openai.azure.com/\ncodegpt config set openai.api_key xxxxxxxxxxxxxxxx\ncodegpt config set openai.model xxxxx-gpt-4o\n```\n\n### Support for [Gemini][60] API Service\n\nBuild with the Gemini API, you can see the [Gemini API documentation][61]. Update the `provider` and `api_key` in your config file. Please create an API key from the [Gemini API][62] page.\n\n```sh\ncodegpt config set openai.provider gemini\ncodegpt config set openai.api_key xxxxxxx\ncodegpt config set openai.model gemini-1.5-flash-latest\n```\n\n[60]: https://ai.google.dev/gemini-api\n[61]: https://ai.google.dev/gemini-api/docs\n[62]: https://aistudio.google.com/app/apikey\n\n### Support for [Anthropic][100] API Service\n\nBuild with the Anthropic API, you can see the [Anthropic API documentation][101]. Update the `provider` and `api_key` in your config file. Please create an API key from the [Anthropic API][102] page.\n\n```sh\ncodegpt config set openai.provider anthropic\ncodegpt config set openai.api_key xxxxxxx\ncodegpt config set openai.model claude-3-5-sonnet-20241022\n```\n\nSee the model list from the [Anthropic API documentation][103].\n\n[100]: https://anthropic.com/\n[101]: https://docs.anthropic.com/en/home\n[102]: https://anthropic.com/\n[103]: https://docs.anthropic.com/en/docs/about-claude/models\n\n### How to Change to [Groq][30] API Service\n\nGet the `API key` from the Groq API Service, please visit [here][31]. Update the `base_url` and `api_key` in your config file.\n\n```sh\ncodegpt config set openai.provider openai\ncodegpt config set openai.base_url https://api.groq.com/openai/v1\ncodegpt config set openai.api_key gsk_xxxxxxxxxxxxxx\ncodegpt config set openai.model llama3-8b-8192\n```\n\nGroqCloud currently supports the [following models][32]:\n\n1. [Production Models](https://console.groq.com/docs/models#production-models)\n2. [Preview Models](https://console.groq.com/docs/models#preview-models)\n\n[30]: https://groq.com/\n[31]: https://console.groq.com/keys\n[32]: https://console.groq.com/docs/models\n\n### How to Change to Ollama API Service\n\nWe can use the Llama3 model from the [Ollama][41] API Service, please visit [here][40]. Update the `base_url` in your config file.\n\n[40]: https://github.com/ollama/ollama/blob/main/docs/openai.md#models\n[41]: https://github.com/ollama/ollama\n\n```sh\n# pull llama3 8b model\nollama pull llama3\nollama cp llama3 gpt-4o\n```\n\nTry to use the `Ollama` API Service:\n\n```sh\ncurl http://localhost:11434/v1/chat/completions \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"model\": \"gpt-4o\",\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"content\": \"Hello!\"\n      }\n    ]\n  }'\n```\n\nUpdate the `base_url` in your config file. You don't need to set the `api_key` in the config file.\n\n```sh\ncodegpt config set openai.base_url http://localhost:11434/v1\n```\n\n### How to Change to [OpenRouter][50] API Service\n\nYou can see the [supported models list][51], model usage can be paid by users, developers, or both, and may shift in [availability][52]. You can also fetch models, prices, and limits [via API][53].\n\nThe following example uses the free model name: `meta-llama/llama-3-8b-instruct:free`\n\n```sh\ncodegpt config set openai.provider openai\ncodegpt config set openai.base_url https://openrouter.ai/api/v1\ncodegpt config set openai.api_key sk-or-v1-xxxxxxxxxxxxxxxx\ncodegpt config set openai.model google/learnlm-1.5-pro-experimental:free\n```\n\n[50]: https://openrouter.ai/\n[51]: https://openrouter.ai/docs#models\n[52]: https://openrouter.ai/terms#services\n[53]: https://openrouter.ai/api/v1/models\n\nTo include your app in openrouter.ai rankings and show it in rankings on openrouter.ai, you can set the `openai.headers` in your config file:\n\n```sh\ncodegpt config set openai.headers \"HTTP-Referer=https://github.com/appleboy/CodeGPT X-Title=CodeGPT\"\n```\n\n- **HTTP-Referer**: Optional, for including your app in openrouter.ai rankings.\n- **X-Title**: Optional, for showing in rankings on openrouter.ai.\n\n## Usage\n\nThere are two methods for generating a commit message using the `codegpt` command: CLI mode and Git Hook.\n\n### CLI Mode\n\nYou can call `codegpt` directly to generate a commit message for your staged changes:\n\n```sh\ngit add \u003cfiles...\u003e\ncodegpt commit --preview\n```\n\nThe commit message is shown below:\n\n```sh\nSummarize the commit message using the gpt-4o model\nWe are trying to summarize a git diff\nWe are trying to summarize a title for the pull request\n================Commit Summary====================\n\nfeat: Add preview flag and remove disableCommit flag in commit command and template file.\n\n- Add a `preview` flag to the `commit` command\n- Remove the `disableCommit` flag from the `prepare-commit-msg` template file\n\n==================================================\nWrite the commit message to .git/COMMIT_EDITMSG file\n```\n\nOr translate all git commit messages into a different language (`Traditional Chinese`, `Simplified Chinese`, or `Japanese`):\n\n```sh\ncodegpt commit --lang zh-tw --preview\n```\n\nConsider the following outcome:\n\n```sh\nSummarize the commit message using the gpt-4o model\nWe are trying to summarize a git diff\nWe are trying to summarize a title for the pull request\nWe are trying to translate a git commit message to Traditional Chinese language\n================Commit Summary====================\n\n功能：重構 codegpt commit 命令標記\n\n- 將「codegpt commit」命令新增「預覽」標記\n- 從「codegpt commit」命令中移除「--disableCommit」標記\n\n==================================================\nWrite the commit message to .git/COMMIT_EDITMSG file\n```\n\nYou can replace the tip of the current branch by creating a new commit. Just use the `--amend` flag:\n\n```sh\ncodegpt commit --amend\n```\n\n## Change Commit Message Template\n\nThe default commit message template is as follows:\n\n```tmpl\n{{ .summarize_prefix }}: {{ .summarize_title }}\n\n{{ .summarize_message }}\n```\n\nChange the format with a template string using the `--template_string` parameter:\n\n```sh\ncodegpt commit --preview --template_string \\\n  \"[{{ .summarize_prefix }}]: {{ .summarize_title }}\"\n```\n\nChange the format with a template file using the `--template_file` parameter:\n\n```sh\ncodegpt commit --preview --template_file your_file_path\n```\n\nAdd a custom variable to the git commit message template:\n\n```sh\n{{ .summarize_prefix }}: {{ .summarize_title }}\n\n{{ .summarize_message }}\n\n{{ if .JIRA_URL }}{{ .JIRA_URL }}{{ end }}\n```\n\nAdd a custom variable to the git commit message template using the `--template_vars` parameter:\n\n```sh\ncodegpt commit --preview --template_file your_file_path --template_vars \\\n  JIRA_URL=https://jira.example.com/ABC-123\n```\n\nLoad a custom variable from a file using the `--template_vars_file` parameter:\n\n```sh\ncodegpt commit --preview --template_file your_file_path --template_vars_file your_file_path\n```\n\nSee the `template_vars_file` format as follows:\n\n```env\nJIRA_URL=https://jira.example.com/ABC-123\n```\n\n### Git Hook\n\nYou can also use the prepare-commit-msg hook to integrate `codegpt` with Git. This allows you to use Git normally and edit the commit message before committing.\n\n#### Install\n\nTo install the hook in the Git repository:\n\n```sh\ncodegpt hook install\n```\n\n#### Uninstall\n\nTo remove the hook from the Git repository:\n\n```sh\ncodegpt hook uninstall\n```\n\nStage your files and commit after installation:\n\n```sh\ngit add \u003cfiles...\u003e\ngit commit\n```\n\n`codegpt` will generate the commit message for you and pass it back to Git. Git will open it with the configured editor for you to review/edit it. Then, to commit, save and close the editor!\n\n```sh\n$ git commit\nSummarize the commit message using the gpt-4o model\nWe are trying to summarize a git diff\nWe are trying to summarize a title for the pull request\n================Commit Summary====================\n\nImprove user experience and documentation for OpenAI tools\n\n- Add download links for pre-compiled binaries\n- Include instructions for setting up OpenAI API key\n- Add a CLI mode for generating commit messages\n- Provide references for OpenAI Chat completions and ChatGPT/Whisper APIs\n\n==================================================\nWrite the commit message to .git/COMMIT_EDITMSG file\n[main 6a9e879] Improve user experience and documentation for OpenAI tools\n 1 file changed, 56 insertions(+)\n```\n\n### Code Review\n\nYou can use `codegpt` to generate a code review message for your staged changes:\n\n```sh\ncodegpt review\n```\n\nOr translate all code review messages into a different language (`Traditional Chinese`, `Simplified Chinese`, or `Japanese`):\n\n```sh\ncodegpt review --lang zh-tw\n```\n\nSee the following result:\n\n```sh\nCode review your changes using gpt-4o model\nWe are trying to review code changes\nPromptTokens: 1021, CompletionTokens: 200, TotalTokens: 1221\nWe are trying to translate core review to Traditional Chinese language\nPromptTokens: 287, CompletionTokens: 199, TotalTokens: 486\n================Review Summary====================\n\n總體而言，此程式碼修補似乎在增加 Review 指令的功能，允許指定輸出語言並在必要時進行翻譯。以下是需要考慮的潛在問題：\n\n- 輸出語言沒有進行輸入驗證。如果指定了無效的語言代碼，程式可能會崩潰或產生意外結果。\n- 此使用的翻譯 API 未指定，因此不清楚是否存在任何安全漏洞。\n- 無法處理翻譯 API 調用的錯誤。如果翻譯服\n\n==================================================\n```\n\nanother php example code:\n\n```php\n\u003c?php\nif( isset( $_POST[ 'Submit' ]  ) ) {\n  // Get input\n  $target = $_REQUEST[ 'ip' ];\n  // Determine OS and execute the ping command.\n  if( stristr( php_uname( 's' ), 'Windows NT' ) ) {\n    // Windows\n    $cmd = shell_exec( 'ping  ' . $target );\n  }\n  else {\n    // *nix\n    $cmd = shell_exec( 'ping  -c 4 ' . $target );\n  }\n  // Feedback for the end user\n  $html .= \"\u003cpre\u003e{$cmd}\u003c/pre\u003e\";\n}\n?\u003e\n```\n\ncode review result:\n\n```sh\n================Review Summary====================\n\nCode review:\n\n1. Security: The code is vulnerable to command injection attacks as the user input is directly used in the shell_exec() function. An attacker can potentially execute malicious commands on the server by injecting them into the 'ip' parameter.\n2. Error handling: There is no error handling in the code. If the ping command fails, the error message is not displayed to the user.\n3. Input validation: There is no input validation for the 'ip' parameter. It should be validated to ensure that it is a valid IP address or domain name.\n4. Cross-platform issues: The code assumes that the server is either running Windows or *nix operating systems. It may not work correctly on other platforms.\n\nSuggestions for improvement:\n\n1. Use escapeshellarg() function to sanitize the user input before passing it to shell_exec() function to prevent command injection.\n2. Implement error handling to display error messages to the user if the ping command fails.\n3. Use a regular expression to validate the 'ip' parameter to ensure that it is a valid IP address or domain name.\n4. Use a more robust method to determine the operating system, such as the PHP_OS constant, which can detect a wider range of operating systems.\n\n==================================================\n```\n\n## Testing\n\nRun the following command to test the code:\n\n```sh\nmake test\n```\n\n## Star History\n\n[![Star History Chart](https://api.star-history.com/svg?repos=appleboy/codegpt\u0026type=Date)](https://star-history.com/#appleboy/codegpt\u0026Date)\n\n## Reference\n\n- [OpenAI Chat completions documentation](https://platform.openai.com/docs/guides/chat).\n- [Introducing ChatGPT and Whisper APIs](https://openai.com/blog/introducing-chatgpt-and-whisper-apis)\n","funding_links":["https://www.paypal.me/appleboy46"],"categories":["Go","UIs","AI Coding Assistants"],"sub_categories":["Command-line(shell) interface","CLI Tools"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappleboy%2FCodeGPT","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fappleboy%2FCodeGPT","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappleboy%2FCodeGPT/lists"}