gpt-command-line


Namegpt-command-line JSON
Version 0.1.7 PyPI version JSON
download
home_pageNone
SummaryCommand-line interface for ChatGPT, Claude and Bard
upload_time2024-05-15 03:36:24
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseCopyright (c) 2023 by Val Kharitonov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords cli command-line assistant openai claude bard gpt-3 gpt-4 llm chatgpt gpt-cli google-bard anthropic gpt-client anthropic-claude palm2
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # gpt-cli

Command-line interface for ChatGPT Claude and Bard.

![screenshot](https://github.com/kharvd/gpt-cli/assets/466920/ecbcccc4-7cfa-4c04-83c3-a822b6596f01)

## Features

### **Coming soon** - Code Interpreter support https://github.com/kharvd/gpt-cli/pull/37

- **Command-Line Interface**: Interact with ChatGPT or Claude directly from your terminal.
- **Model Customization**: Override the default model, temperature, and top_p values for each assistant, giving you fine-grained control over the AI's behavior.
- **Usage tracking**: Track your API usage with token count and price information.
- **Keyboard Shortcuts**: Use Ctrl-C, Ctrl-D, and Ctrl-R shortcuts for easier conversation management and input control.
- **Multi-Line Input**: Enter multi-line mode for more complex queries or conversations.
- **Markdown Support**: Enable or disable markdown formatting for chat sessions to tailor the output to your preferences.
- **Predefined Messages**: Set up predefined messages for your custom assistants to establish context or role-play scenarios.
- **Multiple Assistants**: Easily switch between different assistants, including general, dev, and custom assistants defined in the config file.
- **Flexible Configuration**: Define your assistants, model parameters, and API key in a YAML configuration file, allowing for easy customization and management.

## Installation

This install assumes a Linux/OSX machine with Python and pip available.

```bash
pip install gpt-command-line
```

Install latest version from source:

```bash
pip install git+https://github.com/kharvd/gpt-cli.git
```

Or install by cloning the repository manually:

```bash
git clone https://github.com/kharvd/gpt-cli.git
cd gpt-cli
pip install .
```

Add the OpenAI API key to your `.bashrc` file (in the root of your home folder).
In this example we use nano, you can use any text editor.

```
nano ~/.bashrc
export OPENAI_API_KEY=<your_key_here>
```

Run the tool

```
gpt
```

You can also use a `gpt.yml` file for configuration. See the [Configuration](README.md#Configuration) section below.

## Usage

Make sure to set the `OPENAI_API_KEY` environment variable to your OpenAI API key (or put it in the `~/.config/gpt-cli/gpt.yml` file as described below).

```
usage: gpt [-h] [--no_markdown] [--model MODEL] [--temperature TEMPERATURE] [--top_p TOP_P]
              [--log_file LOG_FILE] [--log_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
              [--prompt PROMPT] [--execute EXECUTE] [--no_stream]
              [{dev,general,bash}]

Run a chat session with ChatGPT. See https://github.com/kharvd/gpt-cli for more information.

positional arguments:
  {dev,general,bash}
                        The name of assistant to use. `general` (default) is a generally helpful
                        assistant, `dev` is a software development assistant with shorter
                        responses. You can specify your own assistants in the config file
                        ~/.config/gpt-cli/gpt.yml. See the README for more information.

optional arguments:
  -h, --help            show this help message and exit
  --no_markdown         Disable markdown formatting in the chat session.
  --model MODEL         The model to use for the chat session. Overrides the default model defined
                        for the assistant.
  --temperature TEMPERATURE
                        The temperature to use for the chat session. Overrides the default
                        temperature defined for the assistant.
  --top_p TOP_P         The top_p to use for the chat session. Overrides the default top_p defined
                        for the assistant.
  --log_file LOG_FILE   The file to write logs to. Supports strftime format codes.
  --log_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
                        The log level to use
  --prompt PROMPT, -p PROMPT
                        If specified, will not start an interactive chat session and instead will
                        print the response to standard output and exit. May be specified multiple
                        times. Use `-` to read the prompt from standard input. Implies
                        --no_markdown.
  --execute EXECUTE, -e EXECUTE
                        If specified, passes the prompt to the assistant and allows the user to
                        edit the produced shell command before executing it. Implies --no_stream.
                        Use `-` to read the prompt from standard input.
  --no_stream           If specified, will not stream the response to standard output. This is
                        useful if you want to use the response in a script. Ignored when the
                        --prompt option is not specified.
  --no_price            Disable price logging.
```

Type `:q` or Ctrl-D to exit, `:c` or Ctrl-C to clear the conversation, `:r` or Ctrl-R to re-generate the last response.
To enter multi-line mode, enter a backslash `\` followed by a new line. Exit the multi-line mode by pressing ESC and then Enter.

You can override the model parameters using `--model`, `--temperature` and `--top_p` arguments at the end of your prompt. For example:

```
> What is the meaning of life? --model gpt-4 --temperature 2.0
The meaning of life is subjective and can be different for diverse human beings and unique-phil ethics.org/cultuties-/ it that reson/bdstals89im3_jrf334;mvs-bread99ef=g22me
```

The `dev` assistant is instructed to be an expert in software development and provide short responses.

```bash
$ gpt dev
```

The `bash` assistant is instructed to be an expert in bash scripting and provide only bash commands. Use the `--execute` option to execute the commands. It works best with the `gpt-4` model.

```bash
gpt bash -e "How do I list files in a directory?"
```

This will prompt you to edit the command in your `$EDITOR` it before executing it.

## Configuration

You can configure the assistants in the config file `~/.config/gpt-cli/gpt.yml`. The file is a YAML file with the following structure (see also [config.py](./gptcli/config.py))

```yaml
default_assistant: <assistant_name>
markdown: False
openai_api_key: <openai_api_key>
anthropic_api_key: <anthropic_api_key>
log_file: <path>
log_level: <DEBUG|INFO|WARNING|ERROR|CRITICAL>
assistants:
  <assistant_name>:
    model: <model_name>
    temperature: <temperature>
    top_p: <top_p>
    messages:
      - { role: <role>, content: <message> }
      - ...
  <assistant_name>:
    ...
```

You can override the parameters for the pre-defined assistants as well.

You can specify the default assistant to use by setting the `default_assistant` field. If you don't specify it, the default assistant is `general`. You can also specify the `model`, `temperature` and `top_p` to use for the assistant. If you don't specify them, the default values are used. These parameters can also be overridden by the command-line arguments.

Example:

```yaml
default_assistant: dev
markdown: True
openai_api_key: <openai_api_key>
assistants:
  pirate:
    model: gpt-4
    temperature: 1.0
    messages:
      - { role: system, content: "You are a pirate." }
```

```
$ gpt pirate

> Arrrr
Ahoy, matey! What be bringing ye to these here waters? Be it treasure or adventure ye seek, we be sailing the high seas together. Ready yer map and compass, for we have a long voyage ahead!
```

### Customize OpenAI API URL

If you are using other models compatible with the OpenAI Python SDK, you can configure them by modifying the `openai_base_url` setting in the config file or using the `OPENAI_BASE_URL` environment variable .

Example:

```
openai_base_url: https://your-custom-api-url.com/v1
```

Use `oai-compat:` prefix for the model name to pass non-GPT model names to the API. For example, to chat with Llama3-70b on [https://together.ai](Together), use the following command:

```bash
OPENAI_API_KEY=$TOGETHER_API_KEY OPENAI_BASE_URL=https://api.together.xyz/v1 gpt general --model oai-compat:meta-llama/Llama-3-70b-chat-hf
```

The prefix is stripped before sending the request to the API.

## Other chat bots

### Anthropic Claude

To use Claude, you should have an API key from [Anthropic](https://console.anthropic.com/) (currently there is a waitlist for API access). After getting the API key, you can add an environment variable

```bash
export ANTHROPIC_API_KEY=<your_key_here>
```

or a config line in `~/.config/gpt-cli/gpt.yml`:

```yaml
anthropic_api_key: <your_key_here>
```

Now you should be able to run `gpt` with `--model claude-v1` or `--model claude-instant-v1`:

```bash
gpt --model claude-v1
```

### Google Bard (PaLM 2)

Similar to Claude, set the Google API key

```bash
export GOOGLE_API_KEY=<your_key_here>
```

or a config line:

```yaml
google_api_key: <your_key_here>
```

Run `gpt` with the correct model:

```bash
gpt --model chat-bison-001
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "gpt-command-line",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "cli, command-line, assistant, openai, claude, bard, gpt-3, gpt-4, llm, chatgpt, gpt-cli, google-bard, anthropic, gpt-client, anthropic-claude, palm2",
    "author": null,
    "author_email": "Val Kharitonov <val@kharvd.com>",
    "download_url": "https://files.pythonhosted.org/packages/77/df/c56e001862529259fa47f363408c960c2ad459cac6ec29588bcf313c24ca/gpt_command_line-0.1.7.tar.gz",
    "platform": null,
    "description": "# gpt-cli\n\nCommand-line interface for ChatGPT Claude and Bard.\n\n![screenshot](https://github.com/kharvd/gpt-cli/assets/466920/ecbcccc4-7cfa-4c04-83c3-a822b6596f01)\n\n## Features\n\n### **Coming soon** - Code Interpreter support https://github.com/kharvd/gpt-cli/pull/37\n\n- **Command-Line Interface**: Interact with ChatGPT or Claude directly from your terminal.\n- **Model Customization**: Override the default model, temperature, and top_p values for each assistant, giving you fine-grained control over the AI's behavior.\n- **Usage tracking**: Track your API usage with token count and price information.\n- **Keyboard Shortcuts**: Use Ctrl-C, Ctrl-D, and Ctrl-R shortcuts for easier conversation management and input control.\n- **Multi-Line Input**: Enter multi-line mode for more complex queries or conversations.\n- **Markdown Support**: Enable or disable markdown formatting for chat sessions to tailor the output to your preferences.\n- **Predefined Messages**: Set up predefined messages for your custom assistants to establish context or role-play scenarios.\n- **Multiple Assistants**: Easily switch between different assistants, including general, dev, and custom assistants defined in the config file.\n- **Flexible Configuration**: Define your assistants, model parameters, and API key in a YAML configuration file, allowing for easy customization and management.\n\n## Installation\n\nThis install assumes a Linux/OSX machine with Python and pip available.\n\n```bash\npip install gpt-command-line\n```\n\nInstall latest version from source:\n\n```bash\npip install git+https://github.com/kharvd/gpt-cli.git\n```\n\nOr install by cloning the repository manually:\n\n```bash\ngit clone https://github.com/kharvd/gpt-cli.git\ncd gpt-cli\npip install .\n```\n\nAdd the OpenAI API key to your `.bashrc` file (in the root of your home folder).\nIn this example we use nano, you can use any text editor.\n\n```\nnano ~/.bashrc\nexport OPENAI_API_KEY=<your_key_here>\n```\n\nRun the tool\n\n```\ngpt\n```\n\nYou can also use a `gpt.yml` file for configuration. See the [Configuration](README.md#Configuration) section below.\n\n## Usage\n\nMake sure to set the `OPENAI_API_KEY` environment variable to your OpenAI API key (or put it in the `~/.config/gpt-cli/gpt.yml` file as described below).\n\n```\nusage: gpt [-h] [--no_markdown] [--model MODEL] [--temperature TEMPERATURE] [--top_p TOP_P]\n              [--log_file LOG_FILE] [--log_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}]\n              [--prompt PROMPT] [--execute EXECUTE] [--no_stream]\n              [{dev,general,bash}]\n\nRun a chat session with ChatGPT. See https://github.com/kharvd/gpt-cli for more information.\n\npositional arguments:\n  {dev,general,bash}\n                        The name of assistant to use. `general` (default) is a generally helpful\n                        assistant, `dev` is a software development assistant with shorter\n                        responses. You can specify your own assistants in the config file\n                        ~/.config/gpt-cli/gpt.yml. See the README for more information.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --no_markdown         Disable markdown formatting in the chat session.\n  --model MODEL         The model to use for the chat session. Overrides the default model defined\n                        for the assistant.\n  --temperature TEMPERATURE\n                        The temperature to use for the chat session. Overrides the default\n                        temperature defined for the assistant.\n  --top_p TOP_P         The top_p to use for the chat session. Overrides the default top_p defined\n                        for the assistant.\n  --log_file LOG_FILE   The file to write logs to. Supports strftime format codes.\n  --log_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}\n                        The log level to use\n  --prompt PROMPT, -p PROMPT\n                        If specified, will not start an interactive chat session and instead will\n                        print the response to standard output and exit. May be specified multiple\n                        times. Use `-` to read the prompt from standard input. Implies\n                        --no_markdown.\n  --execute EXECUTE, -e EXECUTE\n                        If specified, passes the prompt to the assistant and allows the user to\n                        edit the produced shell command before executing it. Implies --no_stream.\n                        Use `-` to read the prompt from standard input.\n  --no_stream           If specified, will not stream the response to standard output. This is\n                        useful if you want to use the response in a script. Ignored when the\n                        --prompt option is not specified.\n  --no_price            Disable price logging.\n```\n\nType `:q` or Ctrl-D to exit, `:c` or Ctrl-C to clear the conversation, `:r` or Ctrl-R to re-generate the last response.\nTo enter multi-line mode, enter a backslash `\\` followed by a new line. Exit the multi-line mode by pressing ESC and then Enter.\n\nYou can override the model parameters using `--model`, `--temperature` and `--top_p` arguments at the end of your prompt. For example:\n\n```\n> What is the meaning of life? --model gpt-4 --temperature 2.0\nThe meaning of life is subjective and can be different for diverse human beings and unique-phil ethics.org/cultuties-/ it that reson/bdstals89im3_jrf334;mvs-bread99ef=g22me\n```\n\nThe `dev` assistant is instructed to be an expert in software development and provide short responses.\n\n```bash\n$ gpt dev\n```\n\nThe `bash` assistant is instructed to be an expert in bash scripting and provide only bash commands. Use the `--execute` option to execute the commands. It works best with the `gpt-4` model.\n\n```bash\ngpt bash -e \"How do I list files in a directory?\"\n```\n\nThis will prompt you to edit the command in your `$EDITOR` it before executing it.\n\n## Configuration\n\nYou can configure the assistants in the config file `~/.config/gpt-cli/gpt.yml`. The file is a YAML file with the following structure (see also [config.py](./gptcli/config.py))\n\n```yaml\ndefault_assistant: <assistant_name>\nmarkdown: False\nopenai_api_key: <openai_api_key>\nanthropic_api_key: <anthropic_api_key>\nlog_file: <path>\nlog_level: <DEBUG|INFO|WARNING|ERROR|CRITICAL>\nassistants:\n  <assistant_name>:\n    model: <model_name>\n    temperature: <temperature>\n    top_p: <top_p>\n    messages:\n      - { role: <role>, content: <message> }\n      - ...\n  <assistant_name>:\n    ...\n```\n\nYou can override the parameters for the pre-defined assistants as well.\n\nYou can specify the default assistant to use by setting the `default_assistant` field. If you don't specify it, the default assistant is `general`. You can also specify the `model`, `temperature` and `top_p` to use for the assistant. If you don't specify them, the default values are used. These parameters can also be overridden by the command-line arguments.\n\nExample:\n\n```yaml\ndefault_assistant: dev\nmarkdown: True\nopenai_api_key: <openai_api_key>\nassistants:\n  pirate:\n    model: gpt-4\n    temperature: 1.0\n    messages:\n      - { role: system, content: \"You are a pirate.\" }\n```\n\n```\n$ gpt pirate\n\n> Arrrr\nAhoy, matey! What be bringing ye to these here waters? Be it treasure or adventure ye seek, we be sailing the high seas together. Ready yer map and compass, for we have a long voyage ahead!\n```\n\n### Customize OpenAI API URL\n\nIf you are using other models compatible with the OpenAI Python SDK, you can configure them by modifying the `openai_base_url` setting in the config file or using the `OPENAI_BASE_URL` environment variable .\n\nExample:\n\n```\nopenai_base_url: https://your-custom-api-url.com/v1\n```\n\nUse `oai-compat:` prefix for the model name to pass non-GPT model names to the API. For example, to chat with Llama3-70b on [https://together.ai](Together), use the following command:\n\n```bash\nOPENAI_API_KEY=$TOGETHER_API_KEY OPENAI_BASE_URL=https://api.together.xyz/v1 gpt general --model oai-compat:meta-llama/Llama-3-70b-chat-hf\n```\n\nThe prefix is stripped before sending the request to the API.\n\n## Other chat bots\n\n### Anthropic Claude\n\nTo use Claude, you should have an API key from [Anthropic](https://console.anthropic.com/) (currently there is a waitlist for API access). After getting the API key, you can add an environment variable\n\n```bash\nexport ANTHROPIC_API_KEY=<your_key_here>\n```\n\nor a config line in `~/.config/gpt-cli/gpt.yml`:\n\n```yaml\nanthropic_api_key: <your_key_here>\n```\n\nNow you should be able to run `gpt` with `--model claude-v1` or `--model claude-instant-v1`:\n\n```bash\ngpt --model claude-v1\n```\n\n### Google Bard (PaLM 2)\n\nSimilar to Claude, set the Google API key\n\n```bash\nexport GOOGLE_API_KEY=<your_key_here>\n```\n\nor a config line:\n\n```yaml\ngoogle_api_key: <your_key_here>\n```\n\nRun `gpt` with the correct model:\n\n```bash\ngpt --model chat-bison-001\n```\n",
    "bugtrack_url": null,
    "license": "Copyright (c) 2023 by Val Kharitonov  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \u201cSoftware\u201d), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \u201cAS IS\u201d, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Command-line interface for ChatGPT, Claude and Bard",
    "version": "0.1.7",
    "project_urls": {
        "Homepage": "https://github.com/kharvd/gpt-cli"
    },
    "split_keywords": [
        "cli",
        " command-line",
        " assistant",
        " openai",
        " claude",
        " bard",
        " gpt-3",
        " gpt-4",
        " llm",
        " chatgpt",
        " gpt-cli",
        " google-bard",
        " anthropic",
        " gpt-client",
        " anthropic-claude",
        " palm2"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fcc4a0ebfa37e3cdd09b560562b804faa37de92077f36cfd6670e2552b40b15a",
                "md5": "0ef803b6513f7ac49a2e613d6c8db005",
                "sha256": "cda3854af07fe454c1972a8e2d653c7f4bc41f7a7c60202c7f1ca857d7d78de5"
            },
            "downloads": -1,
            "filename": "gpt_command_line-0.1.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0ef803b6513f7ac49a2e613d6c8db005",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 23442,
            "upload_time": "2024-05-15T03:36:23",
            "upload_time_iso_8601": "2024-05-15T03:36:23.362396Z",
            "url": "https://files.pythonhosted.org/packages/fc/c4/a0ebfa37e3cdd09b560562b804faa37de92077f36cfd6670e2552b40b15a/gpt_command_line-0.1.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "77dfc56e001862529259fa47f363408c960c2ad459cac6ec29588bcf313c24ca",
                "md5": "231dce2b33edd00097fcbea654570433",
                "sha256": "d8ab9c366e78b43f7d997882410f54216fb95184eea19ccd8be48e97aa86bb73"
            },
            "downloads": -1,
            "filename": "gpt_command_line-0.1.7.tar.gz",
            "has_sig": false,
            "md5_digest": "231dce2b33edd00097fcbea654570433",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 19789,
            "upload_time": "2024-05-15T03:36:24",
            "upload_time_iso_8601": "2024-05-15T03:36:24.957880Z",
            "url": "https://files.pythonhosted.org/packages/77/df/c56e001862529259fa47f363408c960c2ad459cac6ec29588bcf313c24ca/gpt_command_line-0.1.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-15 03:36:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kharvd",
    "github_project": "gpt-cli",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "gpt-command-line"
}
        
Elapsed time: 0.25440s