### Install CodeGPT with Custom Version and Directory (Shell) Source: https://github.com/appleboy/codegpt/blob/main/README.md Demonstrates how to install a specific version of CodeGPT into a custom directory using environment variables before executing the installation script. ```sh # Install a specific version to a custom directory: VERSION=1.1.0 INSTALL_DIR=/opt/codegpt ./install.sh ``` -------------------------------- ### Manual Installation Steps for CodeGPT Binary Source: https://github.com/appleboy/codegpt/blob/main/README.md These snippets outline the advanced manual installation process for CodeGPT. They cover changing permissions of the downloaded binary, moving it to a system-wide executable path, and finally verifying the installation by checking the tool's version. ```Shell chmod 755 codegpt ``` ```Shell mv codegpt /usr/local/bin/ ``` ```Shell codegpt version ``` -------------------------------- ### Automated Installation of CodeGPT via Script Source: https://github.com/appleboy/codegpt/blob/main/README.md This snippet demonstrates the recommended automated installation method for CodeGPT. It uses a curl command to download and execute an install script directly, or alternatively, shows how to download the script first and then run it manually. ```Shell bash < <(curl -sSL https://raw.githubusercontent.com/appleboy/CodeGPT/main/install.sh) ``` ```Shell curl -LO https://raw.githubusercontent.com/appleboy/CodeGPT/main/install.sh chmod +x install.sh ./install.sh ``` -------------------------------- ### CodeGPT Gemini API and VertexAI Configuration Options (APIDOC) Source: https://github.com/appleboy/codegpt/blob/main/README.md This API documentation outlines the configurable parameters for integrating CodeGPT with Gemini API or VertexAI Gemini. It details each option, including its purpose, example values, and whether it is required, providing a comprehensive guide for setting up Gemini-based AI services. ```APIDOC Configuration Options: - openai.provider: Description: Set to `gemini` to use Gemini provider Example Value: `gemini` Required: Yes Default: (empty) - gemini.api_key: Description: API key for Gemini or VertexAI Example Value: `xxxxxxx` Required: Yes Default: (empty) - gemini.model: Description: Model name (see Gemini models) Example Value: `gemini-2.0-flash` Required: Yes Default: (empty) - gemini.backend: Description: Gemini backend: `BackendGeminiAPI` (default, for Gemini API) or `BackendVertexAI` (for VertexAI) Example Value: `BackendGeminiAPI` Required: No Default: `BackendGeminiAPI` - gemini.project_id: Description: VertexAI project ID (required if using `BackendVertexAI`) Example Value: `my-gcp-project` Required: Cond. Default: (empty) - gemini.location: Description: VertexAI location (required if using `BackendVertexAI`) Example Value: `us-central1` Required: Cond. Default: (empty) ``` -------------------------------- ### Install CodeGPT from Source (Go) Source: https://github.com/appleboy/codegpt/blob/main/README.md Provides the Go command to install the latest version of CodeGPT directly from its source code repository. This method requires a Go development environment. ```go go install github.com/appleboy/CodeGPT/cmd/codegpt@latest ``` -------------------------------- ### Install CodeGPT on Windows using Chocolatey Source: https://github.com/appleboy/codegpt/blob/main/README.md This snippet provides the command to install CodeGPT on Windows systems using the Chocolatey package manager. It uses the `choco install` command to set up the `codegpt` package. ```Shell choco install codegpt ``` -------------------------------- ### Install codegpt Git Hook Source: https://github.com/appleboy/codegpt/blob/main/README.md Provides the command to install the `codegpt` prepare-commit-msg Git hook, allowing automatic commit message generation. ```sh codegpt hook install ``` -------------------------------- ### Install CodeGPT on macOS using Homebrew Source: https://github.com/appleboy/codegpt/blob/main/README.md This snippet provides the commands to install CodeGPT on macOS systems using the Homebrew package manager. It involves tapping the official repository and then installing the `codegpt` package. ```Shell brew tap appleboy/tap brew install codegpt ``` -------------------------------- ### Example CodeGPT Review Output (Traditional Chinese) Source: https://github.com/appleboy/codegpt/blob/main/README.md This snippet shows an example output from `codegpt` when performing a code review and translating it into Traditional Chinese. It includes token usage information and a summary of potential issues and suggestions. ```sh Code review your changes using gpt-4o model We are trying to review code changes PromptTokens: 1021, CompletionTokens: 200, TotalTokens: 1221 We are trying to translate core review to Traditional Chinese language PromptTokens: 287, CompletionTokens: 199, TotalTokens: 486 ================Review Summary==================== 總體而言,此程式碼修補似乎在增加 Review 指令的功能,允許指定輸出語言並在必要時進行翻譯。以下是需要考慮的潛在問題: - 輸出語言沒有進行輸入驗證。如果指定了無效的語言代碼,程式可能會崩潰或產生意外結果。 - 此使用的翻譯 API 未指定,因此不清楚是否存在任何安全漏洞。 - 無法處理翻譯 API 調用的錯誤。如果翻譯服 ================================================== ``` -------------------------------- ### Commit with Git Hook and Review Source: https://github.com/appleboy/codegpt/blob/main/README.md Illustrates the standard Git commit workflow when the `codegpt` hook is installed. `codegpt` generates the message, which is then opened in the editor for review before final commit. ```sh git add git commit ``` ```sh $ git commit Summarize the commit message using the gpt-4o model We are trying to summarize a git diff We are trying to summarize a title for the pull request ================Commit Summary==================== Improve user experience and documentation for OpenAI tools - Add download links for pre-compiled binaries - Include instructions for setting up OpenAI API key - Add a CLI mode for generating commit messages - Provide references for OpenAI Chat completions and ChatGPT/Whisper APIs ================================================== Write the commit message to .git/COMMIT_EDITMSG file [main 6a9e879] Improve user experience and documentation for OpenAI tools 1 file changed, 56 insertions(+) ``` -------------------------------- ### Test Ollama Local API with Curl Source: https://github.com/appleboy/codegpt/blob/main/README.md This snippet provides a curl command example to interact with a locally running Ollama API service. It demonstrates how to send a chat completion request to a model named 'gpt-4o' on the default Ollama local endpoint. ```sh curl http://localhost:11434/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4o", "messages": [ { "role": "user", "content": "Hello!" } ] }' ``` -------------------------------- ### codegpt Configuration Options Reference Source: https://github.com/appleboy/codegpt/blob/main/README.md Comprehensive list of available configuration options for `codegpt`, including OpenAI API settings, Git integration, and output language preferences. These options can be set in the `.codegpt.yaml` file to customize `codegpt`'s behavior. ```APIDOC openai.base_url: Replace the default base URL (`https://api.openai.com/v1`). openai.api_key: Generate API key from [openai platform page](https://platform.openai.com/account/api-keys). openai.org_id: Identifier for this organization sometimes used in API requests. Only for `openai` service. openai.model: Default model is `gpt-4o`, you can change to other custom model (Groq or OpenRouter provider). openai.proxy: HTTP/HTTPS client proxy. openai.socks: SOCKS client proxy. openai.timeout: Default HTTP timeout is `10s` (ten seconds). openai.skip_verify: Default skip_verify is `false`, You can change it to `true` to ignore SSL verification. 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). openai.temperature: Default temperature is `1`. See reference [temperature](https://platform.openai.com/docs/api-reference/completions/create#completions/create-temperature). git.diff_unified: Generate diffs with `` lines of context, default is `3`. git.exclude_list: Exclude file from `git diff` command. openai.provider: Default service provider is `openai`, you can change to `azure`. output.lang: Default language is `en` and available languages `zh-tw`, `zh-cn`, `ja`. 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). 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). 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). prompt.folder: Default prompt folder is `$HOME/.config/codegpt/prompt`. ``` -------------------------------- ### Configure CodeGPT for VertexAI Gemini Backend (Shell) Source: https://github.com/appleboy/codegpt/blob/main/README.md This snippet illustrates the shell commands required to configure CodeGPT for the VertexAI Gemini backend. It includes setting the provider, model, explicitly defining the backend as `BackendVertexAI`, and providing the necessary VertexAI project ID and location. ```sh codegpt config set openai.provider gemini codegpt config set openai.model gemini-2.0-flash codegpt config set gemini.backend BackendVertexAI codegpt config set gemini.project_id my-gcp-project codegpt config set gemini.location us-central1 ``` -------------------------------- ### Configure CodeGPT for Gemini API Default Backend (Shell) Source: https://github.com/appleboy/codegpt/blob/main/README.md This snippet provides shell commands to configure CodeGPT for the Gemini API using its default backend. It demonstrates setting the provider, model, and API key, highlighting that the `gemini.backend` parameter can be omitted as it defaults to `BackendGeminiAPI`. ```sh codegpt config set openai.provider gemini codegpt config set openai.model gemini-2.0-flash codegpt config set gemini.api_key xxxxxxx # gemini.backend defaults to BackendGeminiAPI, so you can omit it ``` -------------------------------- ### Configure CodeGPT for Groq API Source: https://github.com/appleboy/codegpt/blob/main/README.md This snippet shows how to configure CodeGPT to connect to the Groq API service. It requires setting the provider to 'openai' (as Groq uses an OpenAI-compatible endpoint), updating the base URL to Groq's endpoint, providing your Groq API key, and specifying a Groq model. ```sh codegpt config set openai.provider openai codegpt config set openai.base_url https://api.groq.com/openai/v1 codegpt config set openai.api_key gsk_xxxxxxxxxxxxxx codegpt config set openai.model llama3-8b-8192 ``` -------------------------------- ### Run Project Tests Source: https://github.com/appleboy/codegpt/blob/main/README.md This command executes the test suite for the project. It is typically used during development to ensure that all components are functioning correctly and that recent changes have not introduced regressions. ```sh make test ``` -------------------------------- ### Set OpenAI API Key as Environment Variable Source: https://github.com/appleboy/codegpt/blob/main/README.md Demonstrates how to set the OpenAI API key as an environment variable, making it accessible to the `codegpt` application. This method is common for temporary or system-wide configurations. ```sh export OPENAI_API_KEY=sk-xxxxxxx ``` -------------------------------- ### Pull Ollama Models Locally Source: https://github.com/appleboy/codegpt/blob/main/README.md This snippet demonstrates how to pull and copy models using the Ollama command-line tool. It shows how to download the Llama3 8b model and then create a copy named 'gpt-4o' for local use. ```sh ollama pull llama3 ollama cp llama3 gpt-4o ``` -------------------------------- ### Configure CodeGPT for Azure OpenAI Service (Shell) Source: https://github.com/appleboy/codegpt/blob/main/README.md This snippet provides shell commands to integrate CodeGPT with Azure OpenAI. It covers setting the provider to 'azure', defining the base URL, providing the API key, and specifying the deployed model name, all essential for connecting to Azure's AI services. ```sh codegpt config set openai.provider azure codegpt config set openai.base_url https://xxxxxxxxx.openai.azure.com/ codegpt config set openai.api_key xxxxxxxxxxxxxxxx codegpt config set openai.model xxxxx-gpt-4o ``` -------------------------------- ### Generate and Preview Git Commit Message Source: https://github.com/appleboy/codegpt/blob/main/README.md Demonstrates how to use `codegpt` to generate a commit message for staged changes and preview it before committing. The output shows the summary generated by the AI model. ```sh git add codegpt commit --preview ``` ```sh Summarize the commit message using the gpt-4o model We are trying to summarize a git diff We are trying to summarize a title for the pull request ================Commit Summary==================== feat: Add preview flag and remove disableCommit flag in commit command and template file. - Add a `preview` flag to the `commit` command - Remove the `disableCommit` flag from the `prepare-commit-msg` template file ================================================== Write the commit message to .git/COMMIT_EDITMSG file ``` -------------------------------- ### Default codegpt Commit Message Template Source: https://github.com/appleboy/codegpt/blob/main/README.md Displays the default Go template used by `codegpt` for generating commit messages, showing available variables like `summarize_prefix`, `summarize_title`, and `summarize_message`. ```tmpl {{ .summarize_prefix }}: {{ .summarize_title }} {{ .summarize_message }} ``` -------------------------------- ### Add CodeGPT Feature to VSCode Devcontainer (JSON) Source: https://github.com/appleboy/codegpt/blob/main/README.md Shows how to integrate CodeGPT into a VSCode Devcontainer configuration by adding a specific feature reference to the 'devcontainer.json' file. ```json "features": { "ghcr.io/kvokka/features/codegpt:1": {} } ``` -------------------------------- ### Store OpenAI API Key in codegpt Configuration File Source: https://github.com/appleboy/codegpt/blob/main/README.md Shows how to store the OpenAI API key directly in the `codegpt` configuration file using the `codegpt config set` command. This creates or updates the `$HOME/.config/codegpt/.codegpt.yaml` file for persistent settings. ```sh codegpt config set openai.api_key sk-xxxxxxx ``` -------------------------------- ### Format for Template Variables File Source: https://github.com/appleboy/codegpt/blob/main/README.md Defines the expected format for the file containing custom template variables, which is a simple key-value pair format similar to environment variables. ```env JIRA_URL=https://jira.example.com/ABC-123 ``` -------------------------------- ### Configure CodeGPT for Ollama Local API Source: https://github.com/appleboy/codegpt/blob/main/README.md This snippet shows how to configure CodeGPT to use a locally running Ollama API service. It involves setting the openai.base_url to the local Ollama endpoint. An API key is not required for local Ollama instances. ```sh codegpt config set openai.base_url http://localhost:11434/v1 ``` -------------------------------- ### Configure CodeGPT for OpenRouter API Source: https://github.com/appleboy/codegpt/blob/main/README.md This snippet demonstrates how to configure CodeGPT to use the OpenRouter API service. It involves setting the provider to 'openai', updating the base URL to OpenRouter's endpoint, providing your OpenRouter API key, and specifying a free OpenRouter model. ```sh codegpt config set openai.provider openai codegpt config set openai.base_url https://openrouter.ai/api/v1 codegpt config set openai.api_key sk-or-v1-xxxxxxxxxxxxxxxx codegpt config set openai.model google/learnlm-1.5-pro-experimental:free ``` -------------------------------- ### Load Custom Template Variables from File Source: https://github.com/appleboy/codegpt/blob/main/README.md Shows how to load custom variables for the commit message template from an external file using the `--template_vars_file` parameter. ```sh codegpt commit --preview --template_file your_file_path --template_vars_file your_file_path ``` -------------------------------- ### Configure CodeGPT for Anthropic API Source: https://github.com/appleboy/codegpt/blob/main/README.md This snippet demonstrates how to configure CodeGPT to use the Anthropic API service. It involves setting the provider to 'anthropic', providing your API key, and specifying the desired Anthropic model. ```sh codegpt config set openai.provider anthropic codegpt config set openai.api_key xxxxxxx codegpt config set openai.model claude-3-5-sonnet-20241022 ``` -------------------------------- ### CodeGPT Review of Vulnerable PHP Code Source: https://github.com/appleboy/codegpt/blob/main/README.md This is the detailed code review generated by `codegpt` for the provided PHP snippet. It identifies critical security vulnerabilities like command injection, lack of error handling, and insufficient input validation, offering specific suggestions for improvement. ```sh ================Review Summary==================== Code review: 1. 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. 2. Error handling: There is no error handling in the code. If the ping command fails, the error message is not displayed to the user. 3. 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. 4. 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. Suggestions for improvement: 1. Use escapeshellarg() function to sanitize the user input before passing it to shell_exec() function to prevent command injection. 2. Implement error handling to display error messages to the user if the ping command fails. 3. Use a regular expression to validate the 'ip' parameter to ensure that it is a valid IP address or domain name. 4. 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. ================================================== ``` -------------------------------- ### Translate and Preview Git Commit Message Source: https://github.com/appleboy/codegpt/blob/main/README.md Shows how to translate the generated commit message into a different language (Traditional Chinese) using the `--lang` flag with a preview. The output displays the translated summary. ```sh codegpt commit --lang zh-tw --preview ``` ```sh Summarize the commit message using the gpt-4o model We are trying to summarize a git diff We are trying to summarize a title for the pull request We are trying to translate a git commit message to Traditional Chinese language ================Commit Summary==================== 功能:重構 codegpt commit 命令標記 - 將「codegpt commit」命令新增「預覽」標記 - 從「codegpt commit」命令中移除「--disableCommit」標記 ================================================== Write the commit message to .git/COMMIT_EDITMSG file ``` -------------------------------- ### Configure CodeGPT Default Prompt Folder Location (Shell) Source: https://github.com/appleboy/codegpt/blob/main/README.md This snippet demonstrates how to change the default directory for CodeGPT's prompt templates. It includes commands to set a new folder path and then load the prompt files from that custom location. The output shows the successful saving of template files to the specified directory. ```sh codegpt config set prompt.folder /path/to/your/prompt ``` ```sh codegpt prompt --load ``` ```sh save code_review_file_diff.tmpl to /Users/xxxxx/.config/codegpt/prompt/code_review_file_diff.tmpl save summarize_file_diff.tmpl to /Users/xxxxx/.config/codegpt/prompt/summarize_file_diff.tmpl save summarize_title.tmpl to /Users/xxxxx/.config/codegpt/prompt/summarize_title.tmpl save conventional_commit.tmpl to /Users/xxxxx/.config/codegpt/prompt/conventional_commit.tmpl ``` -------------------------------- ### Generate Code Review for Staged Changes Source: https://github.com/appleboy/codegpt/blob/main/README.md This command uses `codegpt` to generate a code review message for the currently staged changes in your version control system. It leverages an AI model to analyze the code and provide feedback. ```sh codegpt review ``` -------------------------------- ### Customize Commit Message Template via File Source: https://github.com/appleboy/codegpt/blob/main/README.md Shows how to specify a custom template file for commit messages using the `--template_file` parameter. ```sh codegpt commit --preview --template_file your_file_path ``` -------------------------------- ### Set OpenRouter Headers in CodeGPT Config Source: https://github.com/appleboy/codegpt/blob/main/README.md This snippet shows how to set optional HTTP headers in CodeGPT's configuration for OpenRouter. These headers, HTTP-Referer and X-Title, can be used to include your application in OpenRouter's rankings and display its title. ```sh codegpt config set openai.headers "HTTP-Referer=https://github.com/appleboy/CodeGPT X-Title=CodeGPT" ``` -------------------------------- ### Uninstall codegpt Git Hook Source: https://github.com/appleboy/codegpt/blob/main/README.md Provides the command to remove the `codegpt` prepare-commit-msg Git hook from the repository. ```sh codegpt hook uninstall ``` -------------------------------- ### Pass Custom Template Variables via CLI Source: https://github.com/appleboy/codegpt/blob/main/README.md Explains how to pass custom variables to the commit message template directly from the command line using the `--template_vars` parameter. ```sh codegpt commit --preview --template_file your_file_path --template_vars \ JIRA_URL=https://jira.example.com/ABC-123 ``` -------------------------------- ### Vulnerable PHP Ping Command Execution Source: https://github.com/appleboy/codegpt/blob/main/README.md This PHP code snippet demonstrates a simple web application that executes a `ping` command based on user input. It is highly vulnerable to command injection due to direct use of `$_REQUEST['ip']` in `shell_exec()`. ```php {$cmd}"; } ?> ``` -------------------------------- ### Customize Commit Message Template via String Source: https://github.com/appleboy/codegpt/blob/main/README.md Demonstrates how to change the commit message format using an inline template string with the `--template_string` parameter. ```sh codegpt commit --preview --template_string \ "[{{ .summarize_prefix }}]: {{ .summarize_title }}" ``` -------------------------------- ### Add Custom Variable to Commit Message Template Source: https://github.com/appleboy/codegpt/blob/main/README.md Illustrates how to include a custom variable, such as `JIRA_URL`, within the commit message template using Go template syntax for conditional rendering. ```tmpl {{ .summarize_prefix }}: {{ .summarize_title }} {{ .summarize_message }} {{ if .JIRA_URL }}{{ .JIRA_URL }}{{ end }} ``` -------------------------------- ### Amend Last Git Commit Message Source: https://github.com/appleboy/codegpt/blob/main/README.md Explains how to replace the tip of the current branch by creating a new commit using the `--amend` flag with `codegpt`. ```sh codegpt commit --amend ``` -------------------------------- ### Translate Code Review Messages Source: https://github.com/appleboy/codegpt/blob/main/README.md This command translates the generated code review messages into a specified language. It supports languages like Traditional Chinese, Simplified Chinese, or Japanese, allowing users to receive reviews in their preferred language. ```sh codegpt review --lang zh-tw ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.