clichatgpt


Nameclichatgpt JSON
Version 0.1.3 PyPI version JSON
download
home_pagehttps://github.com/pchchv/clichat
SummaryCLI access to ChatGPT
upload_time2023-04-05 07:38:43
maintainer
docs_urlNone
author
requires_python
license
keywords clichat chatgpt cli python
VCS
bugtrack_url
requirements openai platformdirs pyyaml rich tiktoken
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # clichat[![GitHub license](https://img.shields.io/github/license/pchchv/clichat.svg)](https://github.com/pchchv/clichat/blob/master/LICENSE) [![PyPi](https://img.shields.io/pypi/v/clichatgpt?style=flat-square)](https://pypi.org/project/clichatgpt/)
## CLI access to ChatGPT

CliChat is a command line interface (CLI) tool designed to interact with OpenAI's [ChatGPT](https://chat.openai.com/).
It accepts pipeline input, arguments, or both, and allows you to save common cue preambles for quick use, also provides methods for extracting JSON or Markdown from ChatGPT responses.

**Important:** To use CliChat, you will need to configure the OpenAI API key.

You can do this by passing `--openai-api-key KEY` or by setting the env variable `OPENAI_API_KEY` (recommended).

## Install

### PyPi

```bash
pip install clichatgpt
```

### Brew (slow...)

```bash
brew tap pchchv/clichatgpt
brew install clichatgpt
```

## Documentation

### Making queries

#### A new conversation

```bash
сliсhat how can I extract a still frame from a video at 22:01 with ffmpeg
```

#### recall the last conversation

if you would like to recall the last conversation just call it back with `-l`

```bash
сliсhat -l
```

#### Continue the last conversation

To continue the conversation and ask for a change within the context, you can again use `-l` but with a query.

```bash
сliсhat -l can we make a gif instead from 00:22:01 to 00:22:04
```

`-l` is the shortcut for `-S last` or last session. It is possible to track and continue various individual conversations using the [session options](#session-options) options.


#### Switching between gpt-3.5 and 4

The default is gpt-3.5, to switch to 4, use `clichat -c 4`

#### Chatting interactively

If you want to chat interactively, just use `clichat -i`.

#### Show streaming text (experimental)

You can also stream responses as in webui. At the end of the stream, the result will be formatted and can be merged into an interactive session.

```CliChat -s -i```

### Formatting the results

Responses are parsed and if CliChat thinks its markdown, it will be presented as such to get the syntax highlighted. But sometimes this may not work, because it removes new lines, or because you are only interested in extracting part of the result to pass to another command.

It is possible to use:
- `-r` just prints the text as returned by ChatGPT and does not pass it through markdown.
- `-e` tries to determine what was returned (either a block of code or a json) and extract only that part. If neither is found, it does the same as `-r`.

Both options can be used either with a new query, e.g.

```bash
clichat -e write me a python boilerplate script that starts a server and prints hello world > main.py
```

### Passing content to CliChat

If there are long requests that we don't want to type every time, or just want to provide context for our request, we can pass content to CliChat.

e.g.

```bash
curl https://news.ycombinator.com/rss | clichat given the above rss can you show me the top 3 articles about AI and their links -c 4
```

or

```bash
clichat what does this script do < script.sh
```

What gets sent to ChatGPT over the wire is:

```
piped input
-------
query
```

#### Session Options

Sessions are named conversations.

If you start CliChat with a session name SESS of your choice:

```bash
clichat -S SESS can we make a gif instead from 00:22:01 to 00:22:04
```

CliChat will create a session named SESS if it does not exist, and save the current exchange (request-response pair) for SESS.

If such a session already exists, the saved conversation will be loaded and a new exchange will be added.

Without the session argument the exchange is also stored in a session named `last`, but subsequent calls without a session will overwrite the contents of `last`. You can continue a conversation that was started as a sessionless exchange by passing `-S last`, but `last` will not be a safe place to store the conversation, since it will be cleared again on the next sessionless call. The `-l` option is provided as an abbreviation for `-S last`.

If you specify a session without a query:

```bash
clichat -S SESS
```

CliChat will recall a conversation without changing the session.

CliChat supports various operations on sessions. It provides `--session-OP` options, where `OP` can be `list`, `path`, `dump`, `delete`, `rename`.

### Checking token count and estimated costs

If you want to check the approximate cost and use of tokens of the previous request, you can use the `-t` flag for "tokens".

This can be done when passing a large amount of context, as in the example above.

```bash
curl https://news.ycombinator.com/rss | clichat given the above rss can you show me the top 3 articles about AI and their links -t
```

This will not perform any action on the wire, but will just calculate the tokens locally.

### Use custom prompts (the system msg)

The system message is used to instruct the model how to behave, see [OpenAI - Instructing Chat Models]. [OpenAI - Instructing Chat Models](https://platform.openai.com/docs/guides/chat/instructing-chat-models).

They can be loaded using the `-p` command. For convenience, any file that we put in ~/.config/clichat/ will be picked up by this command.

So, for example, with the following file `~/.config/clichat/etymology`, which contains:

```
I want you to act as a professional Etymologist and Quiz Generator. You have a deep knowledge of etymology and will be provided with a word.
The goal is to create cards that quiz on both the etymology and finding the word by its definition.

The following is what a perfect answer would look like for the word "disparage":

[{
  "question": "A verb used to indicate the act of speaking about someone or something in a negative or belittling way.<br/> <i>E.g He would often _______ his coworkers behind their backs.</i>",
  "answer": "disparage"
},
{
  "question": "What is the etymological root of the word disparage?",
  "answer": "From the Old French word <i>'desparagier'</i>, meaning 'marry someone of unequal rank', which comes from <i>'des-'</i> (dis-) and <i>'parage'</i> (equal rank)"
}]

You will return answers in JSON only. Answer truthfully and if you don't know then say so. Keep questions as close as possible to the
provided examples. Make sure to include an example in the definition question. Use HTML within the strings to nicely format your answers.

If multiple words are provided, create questions and answers for each of them in one list.

Only answer in JSON, don't provide any more text. Valid JSON uses "" quotes to wrap its items.
```

We can now run a command and refer to this prompt with `-p etymology`:

```bash
clichat -p etymology gregarious
```

You can specify `-p` directly to the file path in order to load a system message from any arbitrary location

And since we asked for JSON, we can pipe our result to something else, e.g.:

```bash
clichat -l -e > toanki
```

### Configuring for Azure OpenAI

CliChat can be used with the Azure OpenAI endpoint, in which case you will need to set the following environment variables in addition to `OPENAI_API_KEY`:

- `OPENAI_API_TYPE` :: Set to `azure`. As required by [openai-python](https://github.com/openai/openai-python).
- `OPENAI_API_BASE` :: The URL of the endpoint of your cognitive services, for example `https://eastus.api.cognitive.microsoft.com/`.
- `OPENAI_API_AZURE_ENGINE` :: the name of your Azure deployment, for example `my-gpt-35-turbo` (tied to a specific model)

### Help

```
usage: clichat [-h] [--openai-api-key key] [--temperature t] [-c {3.5,4}] [-i] [-s] [-t] [-p name] [-e] [-r] [-n] [-o] [-l] [-S sess] [--session-list] [--session-path]
                 [--session-dump] [--session-delete] [--session-rename newsess]
                 [query ...]

a CLI access to ChatGPT

positional arguments:
  query                           Query to send to chat GPT

options:
  -h, --help                      show this help message and exit
  --openai-api-key key            the OpenAI API key can also be set as env variable OPENAI_API_KEY
  --temperature t                 temperature (openai setting)
  -c {3.5,4}, --chat-gpt {3.5,4}  chat GPT model
  -i, --interactive               start an interactive chat session. This will implicitly continue the conversation
  -s, --stream                    Stream the incoming text to the terminal
  -t, --tokens                    display what *would* be sent, how many tokens, and estimated costs
  -p name, --prompt-file name     prompt name - will load the prompt at ~/.config/clichat/name as system msg

result formatting options:
  -e, --extract                   extract content from response if possible (either json or code block)
  -r, --raw                       print session as pure text, don't pretty print or format
  -n, --no-format                 do not add pretty print formatting to output
  -o, --only                      Only display the response, omit query

session options:
  -l, --last                      alias for '-S last', the default session if none is specified
  -S sess, --session sess         initiate or continue named session
  --session-list                  list sessions
  --session-path                  show path to session file
  --session-dump                  dump session to stdout
  --session-delete                delete session
  --session-rename newsess        rename session
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pchchv/clichat",
    "name": "clichatgpt",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "clichat chatgpt cli python",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/51/6b/8599521b637f43c39b2ff86d69783b4b3df025aee77c726f564eb9c27f41/clichatgpt-0.1.3.tar.gz",
    "platform": null,
    "description": "# clichat[![GitHub license](https://img.shields.io/github/license/pchchv/clichat.svg)](https://github.com/pchchv/clichat/blob/master/LICENSE) [![PyPi](https://img.shields.io/pypi/v/clichatgpt?style=flat-square)](https://pypi.org/project/clichatgpt/)\n## CLI access to ChatGPT\n\nCliChat is a command line interface (CLI) tool designed to interact with OpenAI's [ChatGPT](https://chat.openai.com/).\nIt accepts pipeline input, arguments, or both, and allows you to save common cue preambles for quick use, also provides methods for extracting JSON or Markdown from ChatGPT responses.\n\n**Important:** To use CliChat, you will need to configure the OpenAI API key.\n\nYou can do this by passing `--openai-api-key KEY` or by setting the env variable `OPENAI_API_KEY` (recommended).\n\n## Install\n\n### PyPi\n\n```bash\npip install clichatgpt\n```\n\n### Brew (slow...)\n\n```bash\nbrew tap pchchv/clichatgpt\nbrew install clichatgpt\n```\n\n## Documentation\n\n### Making queries\n\n#### A new conversation\n\n```bash\n\u0441li\u0441hat how can I extract a still frame from a video at 22:01 with ffmpeg\n```\n\n#### recall the last conversation\n\nif you would like to recall the last conversation just call it back with `-l`\n\n```bash\n\u0441li\u0441hat -l\n```\n\n#### Continue the last conversation\n\nTo continue the conversation and ask for a change within the context, you can again use `-l` but with a query.\n\n```bash\n\u0441li\u0441hat -l can we make a gif instead from 00:22:01 to 00:22:04\n```\n\n`-l` is the shortcut for `-S last` or last session. It is possible to track and continue various individual conversations using the [session options](#session-options) options.\n\n\n#### Switching between gpt-3.5 and 4\n\nThe default is gpt-3.5, to switch to 4, use `clichat -c 4`\n\n#### Chatting interactively\n\nIf you want to chat interactively, just use `clichat -i`.\n\n#### Show streaming text (experimental)\n\nYou can also stream responses as in webui. At the end of the stream, the result will be formatted and can be merged into an interactive session.\n\n```CliChat -s -i```\n\n### Formatting the results\n\nResponses are parsed and if CliChat thinks its markdown, it will be presented as such to get the syntax highlighted. But sometimes this may not work, because it removes new lines, or because you are only interested in extracting part of the result to pass to another command.\n\nIt is possible to use:\n- `-r` just prints the text as returned by ChatGPT and does not pass it through markdown.\n- `-e` tries to determine what was returned (either a block of code or a json) and extract only that part. If neither is found, it does the same as `-r`.\n\nBoth options can be used either with a new query, e.g.\n\n```bash\nclichat -e write me a python boilerplate script that starts a server and prints hello world > main.py\n```\n\n### Passing content to CliChat\n\nIf there are long requests that we don't want to type every time, or just want to provide context for our request, we can pass content to CliChat.\n\ne.g.\n\n```bash\ncurl https://news.ycombinator.com/rss | clichat given the above rss can you show me the top 3 articles about AI and their links -c 4\n```\n\nor\n\n```bash\nclichat what does this script do < script.sh\n```\n\nWhat gets sent to ChatGPT over the wire is:\n\n```\npiped input\n-------\nquery\n```\n\n#### Session Options\n\nSessions are named conversations.\n\nIf you start CliChat with a session name SESS of your choice:\n\n```bash\nclichat -S SESS can we make a gif instead from 00:22:01 to 00:22:04\n```\n\nCliChat will create a session named SESS if it does not exist, and save the current exchange (request-response pair) for SESS.\n\nIf such a session already exists, the saved conversation will be loaded and a new exchange will be added.\n\nWithout the session argument the exchange is also stored in a session named `last`, but subsequent calls without a session will overwrite the contents of `last`. You can continue a conversation that was started as a sessionless exchange by passing `-S last`, but `last` will not be a safe place to store the conversation, since it will be cleared again on the next sessionless call. The `-l` option is provided as an abbreviation for `-S last`.\n\nIf you specify a session without a query:\n\n```bash\nclichat -S SESS\n```\n\nCliChat will recall a conversation without changing the session.\n\nCliChat supports various operations on sessions. It provides `--session-OP` options, where `OP` can be `list`, `path`, `dump`, `delete`, `rename`.\n\n### Checking token count and estimated costs\n\nIf you want to check the approximate cost and use of tokens of the previous request, you can use the `-t` flag for \"tokens\".\n\nThis can be done when passing a large amount of context, as in the example above.\n\n```bash\ncurl https://news.ycombinator.com/rss | clichat given the above rss can you show me the top 3 articles about AI and their links -t\n```\n\nThis will not perform any action on the wire, but will just calculate the tokens locally.\n\n### Use custom prompts (the system msg)\n\nThe system message is used to instruct the model how to behave, see [OpenAI - Instructing Chat Models]. [OpenAI - Instructing Chat Models](https://platform.openai.com/docs/guides/chat/instructing-chat-models).\n\nThey can be loaded using the `-p` command. For convenience, any file that we put in ~/.config/clichat/ will be picked up by this command.\n\nSo, for example, with the following file `~/.config/clichat/etymology`, which contains:\n\n```\nI want you to act as a professional Etymologist and Quiz Generator. You have a deep knowledge of etymology and will be provided with a word.\nThe goal is to create cards that quiz on both the etymology and finding the word by its definition.\n\nThe following is what a perfect answer would look like for the word \"disparage\":\n\n[{\n  \"question\": \"A verb used to indicate the act of speaking about someone or something in a negative or belittling way.<br/> <i>E.g He would often _______ his coworkers behind their backs.</i>\",\n  \"answer\": \"disparage\"\n},\n{\n  \"question\": \"What is the etymological root of the word disparage?\",\n  \"answer\": \"From the Old French word <i>'desparagier'</i>, meaning 'marry someone of unequal rank', which comes from <i>'des-'</i> (dis-) and <i>'parage'</i> (equal rank)\"\n}]\n\nYou will return answers in JSON only. Answer truthfully and if you don't know then say so. Keep questions as close as possible to the\nprovided examples. Make sure to include an example in the definition question. Use HTML within the strings to nicely format your answers.\n\nIf multiple words are provided, create questions and answers for each of them in one list.\n\nOnly answer in JSON, don't provide any more text. Valid JSON uses \"\" quotes to wrap its items.\n```\n\nWe can now run a command and refer to this prompt with `-p etymology`:\n\n```bash\nclichat -p etymology gregarious\n```\n\nYou can specify `-p` directly to the file path in order to load a system message from any arbitrary location\n\nAnd since we asked for JSON, we can pipe our result to something else, e.g.:\n\n```bash\nclichat -l -e > toanki\n```\n\n### Configuring for Azure OpenAI\n\nCliChat can be used with the Azure OpenAI endpoint, in which case you will need to set the following environment variables in addition to `OPENAI_API_KEY`:\n\n- `OPENAI_API_TYPE` :: Set to `azure`. As required by [openai-python](https://github.com/openai/openai-python).\n- `OPENAI_API_BASE` :: The URL of the endpoint of your cognitive services, for example `https://eastus.api.cognitive.microsoft.com/`.\n- `OPENAI_API_AZURE_ENGINE` :: the name of your Azure deployment, for example `my-gpt-35-turbo` (tied to a specific model)\n\n### Help\n\n```\nusage: clichat [-h] [--openai-api-key key] [--temperature t] [-c {3.5,4}] [-i] [-s] [-t] [-p name] [-e] [-r] [-n] [-o] [-l] [-S sess] [--session-list] [--session-path]\n                 [--session-dump] [--session-delete] [--session-rename newsess]\n                 [query ...]\n\na CLI access to ChatGPT\n\npositional arguments:\n  query                           Query to send to chat GPT\n\noptions:\n  -h, --help                      show this help message and exit\n  --openai-api-key key            the OpenAI API key can also be set as env variable OPENAI_API_KEY\n  --temperature t                 temperature (openai setting)\n  -c {3.5,4}, --chat-gpt {3.5,4}  chat GPT model\n  -i, --interactive               start an interactive chat session. This will implicitly continue the conversation\n  -s, --stream                    Stream the incoming text to the terminal\n  -t, --tokens                    display what *would* be sent, how many tokens, and estimated costs\n  -p name, --prompt-file name     prompt name - will load the prompt at ~/.config/clichat/name as system msg\n\nresult formatting options:\n  -e, --extract                   extract content from response if possible (either json or code block)\n  -r, --raw                       print session as pure text, don't pretty print or format\n  -n, --no-format                 do not add pretty print formatting to output\n  -o, --only                      Only display the response, omit query\n\nsession options:\n  -l, --last                      alias for '-S last', the default session if none is specified\n  -S sess, --session sess         initiate or continue named session\n  --session-list                  list sessions\n  --session-path                  show path to session file\n  --session-dump                  dump session to stdout\n  --session-delete                delete session\n  --session-rename newsess        rename session\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "CLI access to ChatGPT",
    "version": "0.1.3",
    "split_keywords": [
        "clichat",
        "chatgpt",
        "cli",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "516b8599521b637f43c39b2ff86d69783b4b3df025aee77c726f564eb9c27f41",
                "md5": "9f76cee490e41e655f9b0c225ecf3bd6",
                "sha256": "9f423cd1bbec7d01f572f2011b32410af4feee51667db96f13da67b1d7e56c36"
            },
            "downloads": -1,
            "filename": "clichatgpt-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "9f76cee490e41e655f9b0c225ecf3bd6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 20264,
            "upload_time": "2023-04-05T07:38:43",
            "upload_time_iso_8601": "2023-04-05T07:38:43.995229Z",
            "url": "https://files.pythonhosted.org/packages/51/6b/8599521b637f43c39b2ff86d69783b4b3df025aee77c726f564eb9c27f41/clichatgpt-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-05 07:38:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "pchchv",
    "github_project": "clichat",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "openai",
            "specs": [
                [
                    ">=",
                    "0.27.2"
                ]
            ]
        },
        {
            "name": "platformdirs",
            "specs": [
                [
                    "==",
                    "3.2.0"
                ]
            ]
        },
        {
            "name": "pyyaml",
            "specs": [
                [
                    "==",
                    "6.0"
                ]
            ]
        },
        {
            "name": "rich",
            "specs": [
                [
                    "==",
                    "13.3.2"
                ]
            ]
        },
        {
            "name": "tiktoken",
            "specs": [
                [
                    "==",
                    "0.3.3"
                ]
            ]
        }
    ],
    "lcname": "clichatgpt"
}
        
Elapsed time: 0.18637s