{"id":13643864,"url":"https://github.com/appleboy/codegpt","last_synced_at":"2026-01-20T10:07:07.766Z","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-05-10T07:06:04.000Z","size":1329,"stargazers_count":1403,"open_issues_count":11,"forks_count":126,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-05-11T05:26:52.702Z","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,"zenodo":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-05-11T04:11:02.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":60,"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":254160016,"owners_count":22024567,"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-08-02T01:01:53.980Z","updated_at":"2026-01-20T10:07:07.759Z","avatar_url":"https://github.com/appleboy.png","language":"Go","funding_links":["https://www.paypal.me/appleboy46"],"categories":["CLIs"],"sub_categories":[],"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[![Security Scanning](https://github.com/appleboy/CodeGPT/actions/workflows/security.yml/badge.svg?branch=main)](https://github.com/appleboy/CodeGPT/actions/workflows/security.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\nA CLI tool written in [Go](https://go.dev) that generates git commit messages or provides code review summaries using ChatGPT AI (gpt-5, 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**English** | [繁體中文](./README.zh-tw.md) | [简体中文](./README.zh-cn.md)\n\n![cover](./images/cover.png)\n\n## Table of Contents\n\n- [CodeGPT](#codegpt)\n  - [Table of Contents](#table-of-contents)\n  - [Features](#features)\n  - [Installation](#installation)\n    - [macOS](#macos)\n    - [Windows](#windows)\n    - [Install via Script or Binary](#install-via-script-or-binary)\n      - [**A. Automated Install (Recommended)**](#a-automated-install-recommended)\n      - [**B. Manual Install (Advanced)**](#b-manual-install-advanced)\n      - [Configurable Environment Variables](#configurable-environment-variables)\n    - [From Source](#from-source)\n    - [Using VSCode Devcontainer](#using-vscode-devcontainer)\n  - [Configuration](#configuration)\n    - [Using API Key Helper for Dynamic Credentials](#using-api-key-helper-for-dynamic-credentials)\n      - [Setup API Key Helper](#setup-api-key-helper)\n      - [Configure Refresh Interval](#configure-refresh-interval)\n      - [Gemini-Specific API Key Helper](#gemini-specific-api-key-helper)\n      - [How It Works](#how-it-works)\n      - [Priority Order](#priority-order)\n    - [How to Customize the Default Prompt Folder](#how-to-customize-the-default-prompt-folder)\n    - [How to Change to Azure OpenAI Service](#how-to-change-to-azure-openai-service)\n    - [Support for Gemini API Service](#support-for-gemini-api-service)\n      - [Configuration Options](#configuration-options)\n      - [Example: Gemini API (default backend)](#example-gemini-api-default-backend)\n      - [Example: VertexAI Gemini](#example-vertexai-gemini)\n    - [Support for Anthropic API Service](#support-for-anthropic-api-service)\n    - [How to Change to Groq API Service](#how-to-change-to-groq-api-service)\n    - [How to Change to Ollama API Service](#how-to-change-to-ollama-api-service)\n    - [How to Change to OpenRouter API Service](#how-to-change-to-openrouter-api-service)\n  - [Usage](#usage)\n    - [CLI Mode](#cli-mode)\n  - [Change Commit Message Template](#change-commit-message-template)\n    - [Git Hook](#git-hook)\n      - [Install](#install)\n      - [Uninstall](#uninstall)\n    - [Code Review](#code-review)\n  - [Testing](#testing)\n  - [Star History](#star-history)\n  - [Reference](#reference)\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 by specifying the number of context lines (default: 3).\n- Enables file exclusion patterns for git diff operations.\n- Translates commit messages into other languages (supports `en`, `zh-tw`, or `zh-cn`).\n- Supports SOCKS proxy or custom network HTTP proxy.\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### Install via Script or Binary\n\nFor most systems, you can use an install script **or** manually download a pre-compiled binary.\n\n#### **A. Automated Install (Recommended)**\n\nRun the install script to automatically download and set up the latest release:\n\n```sh\nbash \u003c \u003c(curl -sSL https://raw.githubusercontent.com/appleboy/CodeGPT/main/install.sh)\n```\n\nOr download and run manually:\n\n```sh\ncurl -LO https://raw.githubusercontent.com/appleboy/CodeGPT/main/install.sh\nchmod +x install.sh\n./install.sh\n```\n\n#### **B. Manual Install (Advanced)**\n\n1. Download the latest pre-compiled binary from the [release page](https://github.com/appleboy/CodeGPT/releases).\n2. Change permissions:\n\n   ```sh\n   chmod 755 codegpt\n   ```\n\n3. Move the binary to your system bin directory:\n\n   ```sh\n   mv codegpt /usr/local/bin/\n   ```\n\n4. Confirm installation:\n\n   ```sh\n   codegpt version\n   ```\n\n#### Configurable Environment Variables\n\n| Variable Name | Default Value      | Description                                                                   |\n| ------------- | ------------------ | ----------------------------------------------------------------------------- |\n| VERSION       | latest             | The CodeGPT version to install (defaults to latest release)                   |\n| INSTALL_DIR   | $HOME/.codegpt/bin | Installation directory                                                        |\n| INSECURE      | unset (disabled)   | If set to any value, skips SSL verification. Enabled when variable is present |\n\nExample usage:\n\n```sh\n# Install with insecure mode enabled (ignoring curl SSL verification):\nINSECURE=1 ./install.sh\n\n# Install a specific version to a custom directory:\nVERSION=1.1.0 INSTALL_DIR=/opt/codegpt ./install.sh\n```\n\nThe script will:\n\n1. Detect your OS and architecture\n2. Download the latest binary\n3. Add the binary to your PATH\n\n### From Source\n\nInstall from source code:\n\n```sh\ngo install github.com/appleboy/CodeGPT/cmd/codegpt@latest\n```\n\n### Using VSCode Devcontainer\n\nAdd the [feature](https://github.com/kvokka/features/tree/main/src/codegpt) to your `devcontainer.json`:\n\n```json\n\"features\": {\n    \"ghcr.io/kvokka/features/codegpt:1\": {}\n}\n```\n\n## Configuration\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.api_key_helper**                  | Shell command to dynamically generate API key (e.g., from password manager or secret service).                                                                                 |\n| **openai.api_key_helper_refresh_interval** | Interval in seconds to refresh credentials from `api_key_helper` (default: `900` seconds / 15 minutes). Set to `0` to disable caching.                                         |\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### Using API Key Helper for Dynamic Credentials\n\nInstead of storing your API key directly in the config file, you can use a shell command to dynamically retrieve it from a password manager or secret service. This is especially useful for:\n\n- Fetching keys from password managers (1Password, Bitwarden, etc.)\n- Using cloud secret services (AWS Secrets Manager, Google Secret Manager, etc.)\n- Implementing token rotation and short-lived credentials\n- Enhancing security by not storing keys in plain text\n\n#### Setup API Key Helper\n\nConfigure a shell command to retrieve your API key:\n\n```sh\n# Using 1Password CLI\ncodegpt config set openai.api_key_helper \"op read op://vault/openai/api_key\"\n\n# Using AWS Secrets Manager\ncodegpt config set openai.api_key_helper \"aws secretsmanager get-secret-value --secret-id openai-key --query SecretString --output text\"\n\n# Using Google Cloud Secret Manager\ncodegpt config set openai.api_key_helper \"gcloud secrets versions access latest --secret=openai-api-key\"\n\n# Using environment variable\ncodegpt config set openai.api_key_helper \"echo \\$MY_OPENAI_KEY\"\n\n# Custom script\ncodegpt config set openai.api_key_helper \"/path/to/get-api-key.sh\"\n```\n\n#### Configure Refresh Interval\n\nBy default, the API key is cached for 15 minutes (900 seconds) to avoid excessive calls to your secret service:\n\n```sh\n# Set refresh interval to 5 minutes\ncodegpt config set openai.api_key_helper_refresh_interval 300\n\n# Set refresh interval to 30 minutes\ncodegpt config set openai.api_key_helper_refresh_interval 1800\n\n# Disable caching (fetch key every time)\ncodegpt config set openai.api_key_helper_refresh_interval 0\n```\n\n#### Gemini-Specific API Key Helper\n\nFor Gemini provider, you can set a separate helper:\n\n```sh\ncodegpt config set gemini.api_key_helper \"gcloud secrets versions access latest --secret=gemini-key\"\ncodegpt config set gemini.api_key_helper_refresh_interval 600\n```\n\n#### How It Works\n\n1. **First execution**: CodeGPT runs your helper command and caches the API key in `~/.config/codegpt/.cache/` with restrictive permissions (0600)\n2. **Subsequent executions**: Within the refresh interval, CodeGPT uses the cached key\n3. **After expiration**: CodeGPT automatically re-runs the helper command and updates the cache\n4. **Security**: Cache files are stored with owner-only read/write permissions\n\n#### Priority Order\n\nWhen multiple API key sources are configured, CodeGPT uses this priority:\n\n1. `openai.api_key_helper` (if configured)\n2. `openai.api_key` (static config)\n3. `OPENAI_API_KEY` environment variable\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\nYou can use the Gemini API or VertexAI Gemini service. See the [Gemini API documentation][61] and [VertexAI documentation][63].  \nUpdate the following parameters in your config file.\n\n- Please create an API key from the [Gemini API][62] page (for BackendGeminiAPI) or from [VertexAI API Key][64] (for BackendVertexAI).\n\n#### Configuration Options\n\n| Option                | Description                                                                                      | Example Value      | Required | Default            |\n| --------------------- | ------------------------------------------------------------------------------------------------ | ------------------ | -------- | ------------------ |\n| **openai.provider**   | Set to `gemini` to use Gemini provider                                                           | `gemini`           | Yes      |                    |\n| **gemini.api_key**    | API key for Gemini or VertexAI                                                                   | `xxxxxxx`          | Yes      |                    |\n| **gemini.model**      | Model name (see [Gemini models][61])                                                             | `gemini-2.0-flash` | Yes      |                    |\n| **gemini.backend**    | Gemini backend: `BackendGeminiAPI` (default, for Gemini API) or `BackendVertexAI` (for VertexAI) | `BackendGeminiAPI` | No       | `BackendGeminiAPI` |\n| **gemini.project_id** | VertexAI project ID (required if using `BackendVertexAI`)                                        | `my-gcp-project`   | Cond.    |                    |\n| **gemini.location**   | VertexAI location (required if using `BackendVertexAI`)                                          | `us-central1`      | Cond.    |                    |\n\n#### Example: Gemini API (default backend)\n\n```sh\ncodegpt config set openai.provider gemini\ncodegpt config set openai.model gemini-2.0-flash\ncodegpt config set gemini.api_key xxxxxxx\n# gemini.backend defaults to BackendGeminiAPI, so you can omit it\n```\n\n#### Example: VertexAI Gemini\n\n```sh\ncodegpt config set openai.provider gemini\ncodegpt config set openai.model gemini-2.0-flash\ncodegpt config set gemini.backend BackendVertexAI\ncodegpt config set gemini.project_id my-gcp-project\ncodegpt config set gemini.location us-central1\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[63]: https://cloud.google.com/vertex-ai/docs/generative-ai/learn/overview\n[64]: https://console.cloud.google.com/apis/credentials\n\n```mermaid\nflowchart TD\n    User([User])\n    subgraph CodeGPT\n      GeminiClient([Gemini Provider])\n    end\n    subgraph Google\n      GeminiAPI([Gemini API])\n      VertexAI([VertexAI Gemini])\n    end\n\n    User --\u003e|Completion / GetSummaryPrefix| GeminiClient\n\n    GeminiClient -- BackendGeminiAPI --\u003e GeminiAPI\n    GeminiAPI -- Response (text, usage) --\u003e GeminiClient\n\n    GeminiClient -- BackendVertexAI --\u003e VertexAI\n    VertexAI -- Response (text, usage) --\u003e GeminiClient\n\n    GeminiClient --\u003e User\n```\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 by visiting the [Groq API Service][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 the [Ollama API Models documentation][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/gemini-3-flash-preview\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\nExample php code review:\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","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"}