Skip to content

fzdp/richat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Richat

Gem Version GitHub license

A powerful command-line ChatGPT tool.

Richat is a command-line ChatGPT tool implemented in Ruby that supports highly customizable configuration. It can save chat contents, performs fuzzy searches on historical inputs, allows for prompt switching at any time and can even run Linux commands.

2023-03-30.16.58.51.mov

Features

  • Save chat contents in markdown files
  • Switch and set prompt easily
  • Auto complete, traverse and search input history
  • Can even be used as a real Linux terminal
  • Fully configurable

Installation

gem install richat

Usage

There are two ways to configure OpenAI API key

  1. set OPENAI_API_KEY env variable
  2. edit ~/.richat/config.json file and set API key, for example
{
  "chatgpt": {
    "api_key": "YOUR OPENAI API KEY"
  }
}

Then run richat command to talk with ChatGPT.

Configuration

Use /config command to show current configuration.

>> /config
Configuration file path is /Users/fzdp/.richat/config.json
{
  "chatgpt": {
    "api_key": "YOUR_OPENAI_API_KEY",
    "model": "gpt-3.5-turbo",
    "temperature": 0.7
  },
  "log": {
    "enable": true,
    "log_dir": "~/.richat/logs",
    "log_file": null,
    "user_role": "USR",
    "ai_role": "GPT",
    "system_role": "SYS"
  },
  "shell": {
    "save_shell_history": true,
    "enable_chat_context": true,
    "show_welcome_info": true,
    "shell_history_file": "~/.richat/history.txt",
    "exit_keywords": [
      "/exit",
      "q",
      "quit",
      "exit"
    ],
    "chat_context_indicator": "💡"
  },
  "sys_cmd": {
    "activate_keywords": [
      ">",
      "!"
    ],
    "deactivate_keywords": [
      "q",
      "quit",
      "exit"
    ]
  },
  "prompt": {
    "prompt_dir": "~/.richat/prompts",
    "default": ""
  }
}

Edit ~/.richat/config.json if you need customize configuration.

Chat log

By default, Richat will log your chat history and log names are in date format.

Set log.enable to false if you don't need log feature.

log directory path

Default logs directory is ~/.richat/logs, you can set another directory if needed.

log file path

If you need save chat logs in a single file, for example in ~/chatgpt_logs.md, there are two ways to do this:

  • edit ~/.richat/config.json
{
  "log": {
    "log_file": "~/chatgpt_logs.md"
}
  • through command line richat --logfile ~/chatgpt_logs.md

If log file is not an absolute path then its parent directory is log_dir.

Prompt

You can place prompt files in ~/.richat/prompts or other directory defined in configure file.

For example, if you place emoji, linux, wikipedia in the directory, then in Richat shell /prompt command will show these prompt files.

Change prompt

You can use /prompt command to switch prompt, the argument is prompt file name or prompt file index.

Set default prompt

For example if you want to use linux as default prompt, just edit config file

{
  "prompt": {
    "default": "linux"
  }
}

Then Richat shell will use linux prompt when it's run

Input history

By default your input history will be saved in ~/.richat/shell_history_file.

In Richat shell mode, there are three ways to enhance chat experience.

  1. press TAB to auto complete input
  2. press Arrow keys to traverse history
  3. press Control + R to fuzzy search input

Stream mode

ChatGPT stream mode is auto enabled in Richat shell mode

2023-03-30.16.04.38.mov

Cli

You can run richat with additional chat content directly

~ richat hello world
Hello! How can I assist you today?

Chat context

Chat context is enabled by default, because ChatGPT have no memory of past requests, all relevant information must be supplied via the conversation.

You can toggle chat context mode using /context command.

Linux terminal

Press > or any other keys defined in config file, then you will enter linux shell mode where you can run any commands.

press q or other keys you defined to exit linux shell mode.

linux_terminal_example

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/fzdp/richat.

License

The gem is available as open source under the terms of the MIT License.