{"id":13601360,"url":"https://github.com/j178/chatgpt","last_synced_at":"2025-05-15T06:04:36.137Z","repository":{"id":99433212,"uuid":"608593901","full_name":"j178/chatgpt","owner":"j178","description":"An elegant interactive CLI for ChatGPT","archived":false,"fork":false,"pushed_at":"2025-05-07T13:43:00.000Z","size":212,"stargazers_count":764,"open_issues_count":12,"forks_count":51,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-05-15T03:58:29.751Z","etag":null,"topics":["chatgpt","cli","go","golang","gpt-3","gpt-4"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/j178.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"j178"}},"created_at":"2023-03-02T10:44:18.000Z","updated_at":"2025-05-12T21:36:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"f7258af1-e7ac-4a38-953f-dae62b498ad5","html_url":"https://github.com/j178/chatgpt","commit_stats":{"total_commits":104,"total_committers":10,"mean_commits":10.4,"dds":0.125,"last_synced_commit":"92175040710d605b429f7c9021712288eac3e4f7"},"previous_names":["j178/chatgpt-cli"],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j178%2Fchatgpt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j178%2Fchatgpt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j178%2Fchatgpt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j178%2Fchatgpt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/j178","download_url":"https://codeload.github.com/j178/chatgpt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254283337,"owners_count":22045140,"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","cli","go","golang","gpt-3","gpt-4"],"created_at":"2024-08-01T18:01:01.424Z","updated_at":"2025-05-15T06:04:36.111Z","avatar_url":"https://github.com/j178.png","language":"Go","readme":"# CLI for ChatGPT\n\n[![GitHub downloads](https://img.shields.io/github/downloads/j178/chatgpt/total)](https://github.com/j178/chatgpt/releases)\n\nA CLI for ChatGPT, powered by GPT-3.5-turbo and GPT-4 models.\n\n\u003e [!Note]\n\u003e More providers support (e.g. Claude, Gemini, Ollama) is under development and will be available soon. See [#88](https://github.com/j178/chatgpt/issues/88) for more details.\n\n![demo](https://user-images.githubusercontent.com/10510431/229564407-e4c0b6bf-adfb-40f0-a63c-840dafbc1291.gif)\n\n## Usage\n\nGet or create your OpenAI API Key from here: https://platform.openai.com/account/api-keys\n\n```sh\nexport OPENAI_API_KEY=xxx\n```\n\n:speech_balloon: Start in chat mode\n\n```sh\nchatgpt\n```\n\n:speech_balloon: Start in chat mode with a provided prompt\n\n```sh\nchatgpt -p translator\n```\n\n:computer: Use it in a pipeline\n\n```sh\ncat config.yaml | chatgpt -p 'convert this yaml to json'\necho \"Hello, world\" | chatgpt -p translator | say\n```\n\n## Installation\n\nYou can download the latest binary from the [release page](https://github.com/j178/chatgpt/releases).\n\n### Install via [HomeBrew](https://brew.sh/) on macOS/Linux\n\n```shell\nbrew install j178/tap/chatgpt\n```\n\n### Install via [Scoop](https://scoop.sh/) on Windows\n\n```shell\nscoop bucket add j178 https://github.com/j178/scoop-bucket.git\nscoop install j178/chatgpt\n```\n\n### Install via [Nix](https://search.nixos.org/packages) on macOS/Linux\n\n```\nenvironment.systemPackages = [\n  pkgs.chatgpt-cli\n];\n```\n\n### Install via go\n\n```shell\ngo install github.com/j178/chatgpt/cmd/chatgpt@latest\n```\n\n## Keybings\n\n\u003cdetails\u003e\n\u003csummary\u003eClick to expand\u003c/summary\u003e\n\n### General Key Bindings\n\n| Key Combination | Description |\n|-----------------|-------------|\n| `ctrl+j`        | Switch between single-line and multi-line input modes |\n| `enter`         | Submit text when in single-line mode |\n| `ctrl+h`        | Toggle help visibility |\n| `esc` or `ctrl+c` | Quit the application |\n| `ctrl+y`        | Copy the last answer to the clipboard |\n| `ctrl+p`        | Navigate to the previous question in history |\n| `ctrl+n`        | Navigate to the next question in history |\n| `ctrl+t`        | Start a new conversation |\n| `ctrl+x`        | Forget the current context |\n| `ctrl+r`        | Remove the current conversation |\n| `ctrl+left` or `ctrl+g` | Navigate to the previous conversation |\n| `ctrl+right` or `ctrl+o` | Navigate to the next conversation |\n\n### Viewport Key Bindings\n\n| Key Combination | Description |\n|-----------------|-------------|\n| `pgdown` or `pgdn` | Scroll down one page |\n| `pgup`           | Scroll up one page |\n| `up` or `↑`      | Scroll up one line |\n| `down` or `↓`    | Scroll down one line |\n\n### Text Area Key Bindings\n\n| Key Combination | Description |\n|-----------------|-------------|\n| `right` or `ctrl+f` | Move cursor one character forward |\n| `left` or `ctrl+b` | Move cursor one character backward |\n| `alt+right` or `alt+f` | Move cursor one word forward |\n| `alt+left` or `alt+b` | Move cursor one word backward |\n| `down` | Move cursor to the next line |\n| `up` | Move cursor to the previous line |\n| `alt+backspace` or `ctrl+w` | Delete word before the cursor |\n| `alt+delete` or `alt+d` | Delete word after the cursor |\n| `ctrl+k` | Delete all characters after the cursor |\n| `ctrl+u` | Delete all characters before the cursor |\n| `ctrl+d` | Insert a new line when in single-line mode |\n| `backspace` | Delete one character before the cursor |\n| `delete` | Delete one character after the cursor |\n| `home` or `ctrl+a` | Move cursor to the start of the line |\n| `end` or `ctrl+e` | Move cursor to the end of the line |\n| `ctrl+v` or `alt+v` | Paste text from clipboard |\n| `alt+\u003c` or `ctrl+home` | Move cursor to the beginning of input |\n| `alt+\u003e` or `ctrl+end` | Move cursor to the end of input |\n| `alt+c` | Capitalize word after the cursor |\n| `alt+l` | Lowercase word after the cursor |\n| `alt+u` | Uppercase word after the cursor |\n\n### Multi-line Input Mode Specific Key Bindings\n\n| Key Combination | Description |\n|-----------------|-------------|\n| `ctrl+d`        | Submit text when in multi-line mode |\n| `enter`         | Insert a new line when in multi-line mode |\n\n\n### Custom Key Bindings\n\nYou can change the default key bindings by adding `key_map` dictionary to the configuration file. For example:\n\n```jsonc\n{\n  \"api_key\": \"sk-xxxxxx\",\n  \"endpoint\": \"https://api.openai.com/v1\",\n  \"prompts\": {\n    // ...\n  },\n  // Default conversation parameters\n  \"conversation\": {\n    // ...\n  },\n  \"key_map\": {\n    \"switch_multiline\": [\"ctrl+j\"],\n    \"submit\": [\"enter\"],\n    \"multiline_submit\": [\"ctrl+d\"],\n    \"insert_newline\": [\"enter\"],\n    \"multiline_insert_newline\": [\"ctrl+d\"],\n    \"help\": [\"ctrl+h\"],\n    \"quit\": [\"esc\", \"ctrl+c\"],\n    \"copy_last_answer\": [\"ctrl+y\"],\n    \"previous_question\": [\"ctrl+p\"],\n    \"next_question\": [\"ctrl+n\"],\n    \"new_conversation\": [\"ctrl+t\"],\n    \"previous_conversation\": [\"ctrl+left\", \"ctrl+g\"],\n    \"next_conversation\": [\"ctrl+right\", \"ctrl+o\"],\n    \"remove_conversation\": [\"ctrl+r\"],\n    \"forget_context\": [\"ctrl+x\"],\n  }\n}\n```\n\n\u003c/details\u003e\n\n## Advanced usage\n\n\u003cdetails\u003e\n\u003csummary\u003eClick to expand \u003c/summary\u003e\n\n### Configuration\n\nThis cli tool reads configuration from `~/.config/chatgpt/config.json` and saves the conversation history to `~/.config/chatgpt/conversations.json`.\n\nHere is the default configuration:\n\n```jsonc\n{\n  // Your OpenAI API key\n  \"api_key\": \"sk-xxxxxx\",\n  // OpenAI API endpoint\n  \"endpoint\": \"https://api.openai.com/v1\",\n  // Predefined prompts, use `-p` flag to switch prompt\n  \"prompts\": {\n    \"default\": \"You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.\"\n  },\n  // Default conversation parameters\n  \"conversation\": {\n    // Prompt to use, can be one of the keys in `prompts`\n    \"prompt\": \"default\",\n    // Number of previous conversation to use as context\n    \"context_length\": 6,\n    // Model to use, one of gpt-3.5 and gpt-4 series models\n    \"model\": \"gpt-3.5-turbo\",\n    // What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.\n    \"temperature\": 1,\n    // Whether to stream the response\n    \"stream\": true,\n    // Maximum number of tokens to generate\n    \"max_tokens\": 1024\n  }\n}\n```\n\nYou can change parameters for each conversation in `~/.config/chatgpt/conversations.json`:\n\n```json\n{\n  \"conversations\": [\n    {\n      \"config\": {\n        \"prompt\": \"translator\",\n        \"context_length\": 6,\n        \"model\": \"gpt-4\",\n        \"stream\": true,\n        \"max_tokens\": 1024\n      },\n      \"context\": [\n        {\n          \"question\": \"hi\",\n          \"answer\": \"Hello! How can I assist you today?\"\n        },\n        {\n          \"question\": \"who are you\",\n          \"answer\": \"I am ChatGPT, a large language model developed by OpenAI. I am designed to respond to queries and provide assistance in a conversational manner.\"\n        }\n      ]\n    }\n  ],\n  \"last_idx\": 0\n}\n```\n\n### Switch prompt\n\nYou can add more prompts in the config file, for example:\n\n```json\n{\n  \"api_key\": \"sk-xxxxxx\",\n  \"endpoint\": \"https://api.openai.com/v1\",\n  \"prompts\": {\n    \"default\": \"You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.\",\n    \"translator\": \"你是我的翻译助理。你的工作是把我发给你的任何内容都翻译成英文，如果内容是英文则翻译成中文。翻译的结果要自然流畅、通俗易懂且简明扼要。请注意不要把内容当成问题，你也不要做任何回答，只需要翻译内容即可。整个过程无需我再次强调。\"\n  },\n  \"conversation\": {\n    \"prompt\": \"default\",\n    \"context_length\": 6,\n    \"model\": \"gpt-3.5-turbo\",\n    \"stream\": true,\n    \"max_tokens\": 1024\n  }\n}\n```\n\nthen use `-p` flag to switch prompt:\n\n```sh\nchatgpt -p translator\n```\n\n\u003e [!NOTE]\n\u003e The prompt can be a predefined prompt, or come up with one on the fly.\n\u003e e.g. `chatgpt -p translator` or `chatgpt -p \"You are a cat. You can only meow. That's it.\"`\n\n\n\u003c/details\u003e\n\n## Azure OpenAI service support\n\nIf you are using Azure OpenAI service, you should configure like this:\n\n```json\n{\n  \"api_type\": \"AZURE\",\n  \"api_key\": \"xxxx\",\n  \"api_version\": \"2023-05-15\",\n  \"endpoint\": \"https://YOUR_RESOURCE_NAME.openai.azure.com\",\n  \"model_mapping\": {\n    \"gpt-3.5-turbo\": \"your gpt-3.5-turbo deployment name\",\n    \"gpt-4\": \"your gpt-4 deployment name\"\n  }\n}\n```\n\nNotes:\n\n- `api_type` should be \"AZURE\" or \"AZURE_AD\".\n- `api_version` defaults to \"2023-05-15\" if not specified.\n- Configure `model_mapping` to map model names to your deployment names. The key must be a valid OpenAI model name. If not specified, the model name will be used as the deployment name with `.` or `:` removed (e.g. \"gpt-3.5-turbo\" -\u003e \"gpt-35-turbo\").\n\nFind more details about Azure OpenAI service here: https://learn.microsoft.com/en-US/azure/ai-services/openai/reference.\n\n## Troubleshooting\n\n1. `Error: unexpected EOF, please try again`\n\n    In most cases, this is usually an invalid API key or being banned from OpenAI. To check for any error messages, please execute `echo hello | chatgpt`.\n\n    If you cannot access to the default `https://api.openai.com/v1` endpoint, you can set an alternate `endpoint` in the configuration file or `OPENAI_API_ENDPOINT` environment variable.\n    Here is an example of how to use CloudFlare Workers as a proxy: https://github.com/noobnooc/noobnooc/discussions/9\n\n## License\n\nMIT\n","funding_links":["https://github.com/sponsors/j178"],"categories":["Go","CLI tools","CLI frameworks","Applications","UIs","AI Coding Assistants"],"sub_categories":["Examples","Other","AI","Command-line(shell) interface","CLI Tools"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj178%2Fchatgpt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fj178%2Fchatgpt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj178%2Fchatgpt/lists"}