Using ChatGPT/GPT-3.5/GPT-4 in the terminal.

Overview

AIChat

CI Crates

Using ChatGPT/GPT-3.5/GPT-4 in the terminal.

AIChat in chat mode:

chat mode

AIChat in command mode:

command mode

Install

With cargo

cargo install --force aichat

Binaries on macOS, Linux, Windows

Download it from Github Releases, unzip and add aichat to your $PATH.

Features

  • Support chat and command modes
  • Predefine AI roles
  • Use GPT prompt easily
  • Powerful Chat REPL
  • Context-ware conversation
  • syntax highlighting markdown and other 200 languages
  • Stream output with hand typing effect
  • Support multiple models
  • Support proxy
  • Support dark/light theme
  • Save chat messages

Config

On first launch, aichat will guide you through configuration.

> No config file, create a new one? Yes
> Openai API Key: sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Use proxy? Yes
> Set proxy: socks5://127.0.0.1:1080
> Save chat messages Yes

After setting, it will automatically create the configuration file. Of course, you can also manually set the configuration file.

api_key: "<YOUR SECRET API KEY>"  # Request via https://platform.openai.com/account/api-keys
organization_id: "org-xxx"        # optional, set organization id
model: "gpt-3.5-turbo"            # optional, choose a model
temperature: 1.0                  # optional, see https://platform.openai.com/docs/api-reference/chat/create#chat/create-temperature
save: true                        # optional, If set true, aichat will save chat messages to message.md
highlight: true                   # optional, Set false to turn highlight
proxy: "socks5://127.0.0.1:1080"  # optional, set proxy server. e.g. http://127.0.0.1:8080 or socks5://127.0.0.1:1080
conversation_first: false         # optional, If set true, start a conversation immediately upon repl
light_theme: false                # optional, If set true, use light theme
connect_timeout: 10               # optional, Set a timeout in seconds for connect to gpt.

You can use .info to view the current configuration file path and roles file path.

You can use Enviroment Variables to customize certain configuration items.

Roles

We can let ChatGPT play a certain role through prompt to make it better generate what we want.

We can predefine a batch of roles in roles.yaml.

We can get the location of roles.yaml through the repl's .info command or cli's --info option.

For example, we define a role

- name: shell
  prompt: >
    I want you to act as a linux shell expert.
    I want you to answer only with bash code.
    Do not provide explanations.

Let ChatGPT answer questions in the role of a linux shell expert.

〉.role shell

shell〉 extract encrypted zipfile app.zip to /tmp/app
mkdir /tmp/app
unzip -P PASSWORD app.zip -d /tmp/app

We have provided many awesome Role Examples.

Chat REPL

aichat has a powerful Chat REPL.

The Chat REPL supports:

  • Emacs keybinding
  • Command autocompletion
  • History search
  • Fish-style history autosuggestion hints
  • Edit/past multiline input
  • Undo support
  • Clipboard integration

multi-line editing

Type { or ( at the beginning of the line to enter the multi-line editing mode. In this mode you can type or paste multiple lines of text. Type the corresponding } or ) at the end of the line to exit the mode and submit the content.

〉{ convert json below to toml
{
  "an": [
    "arbitrarily",
    "nested"
  ],
  "data": "structure"
}}

.help - Print help message

〉.help
.info                    Print the information
.set                     Modify the configuration temporarily
.model                   Choose a model
.prompt                  Add a GPT prompt
.role                    Select a role
.clear role              Clear the currently selected role
.conversation            Start a conversation.
.clear conversation      End current conversation.
.history                 Print the history
.clear history           Clear the history
.help                    Print this help message
.exit                    Exit the REPL

Type `{` to enter the multi-line editing mode, type '}' to exit the mode.
Press Ctrl+C to abort readline, Ctrl+D to exit the REPL

.info - view current configuration information.

〉.info
config_file         /home/alice/.config/aichat/config.yaml
roles_file          /home/alice/.config/aichat/roles.yaml
messages_file       /home/alice/.config/aichat/messages.md
api_key             sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
organization_id     -
model               gpt-3.5-turbo
temperature         -
save                true
highlight           true
proxy               -
conversation_first  false
light_theme         false
connect_timeout     10
dry_run             false

.set - modify the configuration temporarily

〉.set dry_run true
〉.set highlight false
〉.set save false
〉.set temperature 1.2

.model - choose a model

> .model gpt-4
> .model gpt-4-32k
> .model gpt-3.5-turbo

.prompt - use GPT prompt

When you set up a prompt, every message sent later will carry the prompt.

〉{ .prompt
I want you to translate the sentences I wrote into emojis.
I will write the sentence, and you will express it with emojis.
I just want you to express it with emojis.
I want you to reply only with emojis.
}
Done

P〉You are a genius
👉🧠💡👨‍🎓

P〉I'm embarrassed
🙈😳

.prompt actually creates a temporary role internally, so run .clear role to clear the prompt.

When you are satisfied with the prompt, add it to roles.yaml for later use.

.role - let the ai play a role

Select a role.

〉.role emoji
name: emoji
prompt: I want you to translate the sentences I wrote into emojis. I will write the sentence, and you will express it with emojis. I just want you to express it with emojis. I don't want you to reply with anything but emoji. When I need to tell you something in English, I will do it by wrapping it in curly brackets like {like this}.
temperature: null

AI play the role we specified

emoji〉hello
👋

Clear current selected role

emoji〉.clear role

〉hello 
Hello there! How can I assist you today?

.conversation - start a context-aware conversation

By default, aichat behaves in a one-off request/response manner.

You can run .conversation to enter context-aware mode, or set config.conversation_first true to start a conversation immediately upon repl.

〉.conversation

$list 1 to 5, one per line                                                              4089
1
2
3
4
5

$reverse the list                                                                       4065
5
4
3
2
1

When enter conversation mode, prompt will change to , A number will appear on the right, which means how many tokens left to use. Once the number becomes zero, you need to start a new conversation.

Exit conversation mode

$.clear conversation                                                                    4043

〉

License

Copyright (c) 2023 aichat-developers.

aichat is made available under the terms of either the MIT License or the Apache License 2.0, at your option.

See the LICENSE-APACHE and LICENSE-MIT files for license details.

Comments
  • [Feature Request] use `bat::PrettyPrinter` for better highlighting

    [Feature Request] use `bat::PrettyPrinter` for better highlighting

    instead of calling syntect directly in our code.

    Looks bat produces better result overall (it uses syntect too under the hood). This hopefully could also simplify the render code a bit.

    https://docs.rs/bat/latest/bat/ https://docs.rs/bat/latest/bat/struct.PrettyPrinter.html

    opened by int 10
  • chatgpt output word limit

    chatgpt output word limit

    pipe input/output, but output word too much, once can not be output completed, how to continue to output the previous content? Or in Chat mode (set config.conversation_first true), the ability to pipe the input file so that we can type 'continue' to let chatgpt continue typing before ?

    opened by vernon2gh 9
  • args in roles.yaml

    args in roles.yaml

    ✨amazing project btw!✨

    I was trying to use the translator: role example, but I'm not quite understanding the ARGn substitutions and how they relate to the role name definition in roles.yaml.

    Example roles.yaml:

    - name: translator:french
      prompt: >
        You will act as a translator between English and __ARG1__.
        Whenever you receive a prompt in either language, you will translate the text into the opposite language and provide the translated output as your response.
        Please ensure that your response contains only the translated text.
        No additional descriptions or explanations, No tags or comments to indicate language direction.
    
    

    Must I define the name as translator:french or can I make it generic and use translator:lang? Or does it not matter? Is french just a placeholder? Or is it a default? If it's a default, I would expect to be able to write:

    aichat -r translator Good afternoon
    

    ...without specifying a language parameter. But that doesn't work. You must type the full role spec. Am I using this incorrectly?

    opened by luckman212 7
  • [Request] Automatically enter editor mode when pasting multiline text

    [Request] Automatically enter editor mode when pasting multiline text

    Right now when you paste a text (e.g. code snippet), every line is submitted individually as a separate request. It would be more helpful if the text was pasted in editor mode so that the whole thing would be submitted at once.

    opened by olalonde 7
  • No output

    No output

    I built version 0.5.0 from source on a mac. Using a free-tier API key but not getting any output. messages.md file shows no results when saving is on. Shouldn't it work with a free tier key? Or if not, shouldn't there be some error message?

    opened by teddyknox 6
  • [Feature Request] chat/session mode (i.e. back and forth conversation)

    [Feature Request] chat/session mode (i.e. back and forth conversation)

    Currently, aichat behaves in a one-off request/response manner -- it has no "context" info.

    e.g.

    > show me some haskell code to print fibonacci numbers
    Here is the Haskell code to print the first n Fibonacci numbers:
    
    ────────────────────
    fib :: Int -> [Int]
    fib n = take n fibList
      where fibList = 0 : 1 : zipWith (+) fibList (tail fibList)
    
    main :: IO ()
    main = do
        putStrLn "Enter the number of Fibonacci numbers to print:"
        n <- readLn
        putStrLn $ "The first " ++ show n ++ " Fibonacci numbers are: "
        print $ fib n
    ────────────────────
    
    > now convert it to python
    Sorry, I'm an AI language model and I would need to see the original code to convert it to Python. 
    Can you please provide more context or the original code you would like to convert?
    

    We have chat in our name, so it'd be nice if it can mimic a real chatting bot (a la ChatGPT) who can have a conversation. Implementation-wise (from a high level view), we can just extend the messages sent to the OpenAI API with every input & output we've got so far.

    As for the UI, we probably can make it default in interactive mode, while adding some extra commands like .clear session, .mode chat, etc.

    opened by int 5
  • Process closed upon starting

    Process closed upon starting

    I open aichat in terminal and upon opening I get this message `zsh: no such file or directory: $PATH/aichat

    Saving session...completed.

    [Process completed] ` Everything was working correctly, until I forced stopped aichat process which was generating text I wanted it to stop.

    I deleted config folder and aichat binary and downloaded new version, but that didn't resolve the issue.

    Could you please help me repair? Thank you.

    opened by StaniKub 4
  • Error while generating list of emojis

    Error while generating list of emojis

    I encountered some errors while trying to generate emojis. I have tried to replicate the issue, but unfortunately, the response is no longer the same.

    I'm not entirely sure whether this issue is related to the emoji output, as I've checked and found that other emoji responses are displayed correctly.

    Welcome to aichat 0.5.0
    Type ".help" for more information.
    〉suggest emojis: sad
    1. 😞
    2. 😔
    3. 😢
    4. 😥
    5. 😿
    6. 💔 ()
    7. 💧
    8. 🩸    (hem-faceemoetry/star_fp on github was out that one can use *thon_mas_star  and terminate with + ; function=top_record_attributes?))
    9 .👊😓(normal confidence : boosted bravery w/grendalvis_ref_boot.exe>>pone?)
    10. 😫(IB\_head)/:sha/sexinoeljumoottomwaveflowermuetcode): bep375 support to denote eager optimism mixing B2 feels backwards-tonelif+t H/F faces making grnf among employees joining waysstar_up105(unittest.cursors().npgsqlCommandsNamesExcept(ib_file_string(web_inst.fb(down_loaded_attach))) win less amongst bunch-less votes era happiness>())))[7])).lowest(value_counts(kind))?dna_kw.dpi:return{return zip_group_str(sum(audio_opcode_one_nested[s_sequence(full(str(isolate_ref_mobile(manager_bridge_files(graphFLESSES_argsigingng.py+.times-cy/file, dis+
    establish_COI_* path+='/rf/times/values.html/files/API_AUDIO_HTTP/tests/material/location/db/method/event/posts/stat.ptgdvz>>+_frame for decrypt(origin.path, save_F47(ldie56/RON_add(d_message(email, Audio403MSG(apls.title(TAG_DENLError(message=jgroups(pyTennis + hexload_helper(Crypto_.K_OS_all_the_end(beta_ASSError(theme_pol_writevalide(info_support___MEDIA_FUNCTIONS)), ios&assist_color>>weightless-token+klist,s_value(mock_local=n.local_h(app.gpickle(epoch_to_IS(version>v_10_SUB!=rhovoiler.token_confirm_detail(page=str_current_dtype + email(byteout(Ciphertext_dict(fieldface.sigfgwith_ghost(filename)), iso_CRC326_FUNCTION_CMD_DIR_AGENT000,(ping_textlib(ans.OS_background_runner[NN.index_null => 'FAILED it.success_var(file_header(exception.expected(big_noise_policy,list(last_read(pair_hist.ml(g_full(first_digit).__lte__).split(('err [283708769 n res...NUMBER_QCP== True and application_app_is_address_tcp_wr)))>(['_63BC8271 B reuil1 blue_host exampleAError J.MOH.SH_dheegcgl.
    93PGqa7'
    
    um.c.l(context_life_hex(PC=SIGH_I = shrospayload_filename_token_validation_controller_timer_file(tk.StringIOCheat(validater.decode_hex)),falen_Sigh.context(user_PC_reactive.dis,h.as(v / sql_setattr_with_empresning<disabled.startswith_*)(__decipher_service(PKI.prot(segment_encode(PC=\telepython.() amba_crypto>>quantunnugmaticals(FRWAT/snapwin/crypto/libs.mid)))
    ^C%
    
    opened by XOKP 4
  • [Feature request] File mode (e.g. aichat -r comment -f somefile.ts)

    [Feature request] File mode (e.g. aichat -r comment -f somefile.ts)

    It would be nice to have an inline file mode that allows using the content of a file as the aichat input and writing back the output to the file.

    It would allow this kind of use case for adding code comments to a file.

    aichat -r comment -f somefile.ts 
    

    Or fixing grammar:

    aichat -r grammar -f README.md
    

    etc.

    If you approve, I can try writing a PR.

    Temporary bash workaround (generated by ChatGPT :P):

    #!/bin/bash
    
    # Check if there are enough arguments
    if [ "$#" -lt 2 ]; then
        echo "Usage: $0 <aichat_options> <filename>"
        exit 1
    fi
    
    # Store the last argument (filename) and remove it from the argument list
    FILENAME="${!#}"
    shopt -u nocasematch
    set -- "${@:1:$#-1}"
    
    # Check if the file exists
    if [ ! -f "$FILENAME" ]; then
        echo "Error: File '$FILENAME' not found"
        exit 1
    fi
    
    # Create a temporary file in the OS temporary directory
    TMPFILE=$(mktemp)
    
    echo "$FILENAME"
    echo "${@}"
    
    # Pass all the arguments except the last one to the aichat command
    aichat "${@}" < "$FILENAME" > "$TMPFILE"
    
    # Move the temporary file to the original file
    mv "$TMPFILE" "$FILENAME"
    
    opened by olalonde 3
  • Modify role just for one command

    Modify role just for one command

    (thanks for the apps !)

    Sometime I need to adapt the profile for a specific request for instance: aichat -r shell install htop packet but this time, I use alpine linux, so I would need this time something like: aichat -r shell --extra-role "I want you to use alpine linux" install htop packet

    Thanks

    opened by vlp-git 3
  • .copy command not working in WSL2 terminal

    .copy command not working in WSL2 terminal

    Running aichat in Ubuntu 22.04 on Windows WSL2, the .copy command doesn't work. I suppose copypasta thinks it's running a standard Linux machine, but is there some kind of workaround? In order to write to the Windows clipboard from WSL, you can pipe the contents to clip.exe which is in PATH.

    opened by mortenscheel 3
  • feature request: YAML anchors and aliases for simplifying roles.yaml

    feature request: YAML anchors and aliases for simplifying roles.yaml

    Sorry if this is naive (it probably is, I'm less than a week into using aichat), but I think it would be useful to be able to use YAML anchors and aliases. This is the usecase I had in mind:

    - name: &code_generator
      prompt: code_generator
        Your answer must only executable code.
        Do not answer with fenced code block.
        The first line of your answer must contain a she-bang.
        Provide explanations in comments.
    
    - name: bash
      prompt: bash generator                                                                                            <<: *code_generator
        Your answer must only be executable Bash code
    
    - name: python
      prompt: python generator                                                                                          <<: *code_generator
        Your answer must only be executable Python code
    

    Basically I have a set of requirements that I ask aichat when generating code in any programming language. I'd like to be able to have these requirements be inherited by specific language roles, which would allow me to tweak the wording of only the code_generator if I want to change how all of the languages are generated.

    I can just keep copy/pasting the common requirements though. What do you think?

    opened by sudomain 0
  • undo and clipboard integration  features in the README?

    undo and clipboard integration features in the README?

    Hi I just want to check to see that I'm not missing something obvious here. It appears the README mentions:

    Undo support
    Clipboard integration
    

    I can't find anything in the help or github search. Are these yet to be implemented or am I bad at searching?

    opened by sudomain 0
  • n00b question: config file

    n00b question: config file

    How do I edit my config file?

    On first launch, aichat will guide you through configuration.... Of course, you can also manually set the configuration file.

    Where is the config file located and how do I edit it?

    opened by alexWhitworth 0
  • Replace custom OpenAI SDK implementation with async-openai.

    Replace custom OpenAI SDK implementation with async-openai.

    Hey! Thanks for making aichat.

    I refactored this for my own benefit, but if you are interested, I can make whatever adjustments you think might be necessary to merge this PR.

    Or close it, up to you!

    opened by TrevorS 0
  • Add support for Azure OpenAI

    Add support for Azure OpenAI

    This PR adds support for the Azure OpenAI service, which is an alternate API for accessing the OpenAI models. In the initial-config wizard it adds a question Use OpenAI via Azure? (default no), and if the answer is yes it asks for the endpoint and deployment name. It stores these in the config file under new keys. It also adds support for max_tokens (on both APIs), since the Azure max_tokens default is very low.

    Details:

    If aoai_endpoint is set, then use Azure OpenAI endpoint rather than the direct OpenAI endpoint. Requires aoai_deployment to be specified as well. You should set the model too, so that aichat knows the correct number of remaining tokens.

    Also adds support for max_tokens since the AOAI default is very low.

    The Azure OpenAI API currently requires chats to be encoded as completions, so logic to do this is added as well.

    Tested with gpt-35-turbo (version 0301).

    opened by kw217 0
  • Lines show in duplicate/triplicate on narrower terminals

    Lines show in duplicate/triplicate on narrower terminals

    I'm using aichat in Arch Linux with Kitty terminal. Using i3 as a display manager.

    It works great, until I set the terminal to half-screen size, when lines appear several times over. This does not seem to occur on wider terminals.

    2023-04-05-17:18:11-screenshot

    opened by benoliver999 3
Releases(v0.8.0)
Owner
null
ChatGPT-Code-Review is a Rust application that uses the OpenAI GPT-3.5 language model to review code

ChatGPT-Code-Review is a Rust application that uses the OpenAI GPT-3.5 language model to review code. It accepts a local path to a folder containing code, and generates a review for each file in the folder and its subdirectories.

Greg P. 15 Apr 22, 2023
Provide free GPT-3.5 API service by reverse engineering the login-free ChatGPT website.

ChatGPT Free API Provide free GPT-3.5 API service by reverse engineering the login-free ChatGPT website. Note: This service requires the IP to be able

null 21 May 5, 2024
All in One AI Chat Tool( GPT-4 / GPT-3.5 /OpenAI API/Azure OpenAI)

WeChatAI Create All in One personal AI chat assistant English | 中文介绍 This project is not for reward and profit, only used for personal Screenshot Supp

null 38 Apr 25, 2023
ChatGPT CLI - A minimal assistant in the terminal

ChatGPT CLI A lightweight ChatGPT CLI - Chat completion. Interact with ChatGPT from your terminal and save the conversation in a text file. Get starte

Imad E. 5 Mar 14, 2023
Ask ChatGPT for a shell script, code, or anything, directly from your terminal 🤖🧠👨‍💻

ShellGPT Ask ChatGPT for a shell script, code, or anything, directly from your terminal ?? ?? ??‍?? Demo Install The binary is named gpt when installe

null 4 May 15, 2023
A CLI tool connected to GPT-3 to help find the right terminal command

Command Recall A CLI tool connected to GPT-3 to help find the right terminal command Install to install the cli: cargo install --git https://github.co

Camille Moatti 102 Feb 18, 2023
A tool for chatting using the ChatGPT API, written in Rust CLI.

ChatGPT CLI A tool for chatting using the ChatGPT API, written in Rust CLI. You can use this tool to chat, just by setting your API Key. You can modif

null 6 Apr 5, 2023
Rust-based CLI library for OpenAI ChatGPT API

This is a Rust library that provides a CLI (command-line interface) for easy and convenient access to the OpenAI ChatGPT API. The library offers a simple and straightforward way to integrate the ChatGPT API into your Rust-based applications.

bigduu 10 Mar 9, 2023
chatgpt from the command line 🤖💬

Talk to ChatGPT from your terminal. Quickstart First you'll need to install the CLI: cargo install chatgpt-cli Then, you'll need to make sure your ca

Juan Gonzalez 9 Mar 23, 2023
This is a simple command-line interface tool that allows you to interact with ChatGPT from OpenAI or Azure.

HeyGPT This is a simple command-line interface tool that allows you to interact with ChatGPT from OpenAI or Azure. You can use it to: Chat with ChatGP

Philip 5 Mar 28, 2023
Koi is a simple tool built to let you use ChatGPT through the command line

Koi is a simple tool built to let you use ChatGPT through the command line. It adds the ability to let ChatGPT run commands on your computer in order to help you out, or to help you out with complicated tasks.

Shivam Sharma 9 Mar 28, 2023
A command-line interface for interacting with the ChatGPT API from OpenAI

cligpt cligpt is a command-line interface for interacting with the ChatGPT API from OpenAI. With cligpt, you can quickly and easily generate text by s

Felipe S. S. Schneider 6 Apr 4, 2023
A simple common-line interface for ChatGPT API.

heygpt A simple common-line interface for ChatGPT API. ?? Streaming output! ?? One-shot mode to get a quick answer ?? Interactive mode to have a conve

Eric Fu 88 Apr 17, 2023
ChatGPT powered Rust proc macro that generates code at compile-time.

gpt-macro ChatGPT powered Rust proc macro that generates code at compile-time. Implemented Macros auto_impl!{} #[auto_test(...)] Usage Get ChatGPT API

Akira Moroo 429 Apr 15, 2023
Striving to create a great Application with full functions of learning languages by ChatGPT, TTS, STT and other awesome AI models

Striving to create a great Application with full functions of learning languages by ChatGPT, TTS, STT and other awesome AI models, supports talking, speaking assessment, memorizing words with contexts, Listening test, so on.

null 155 Apr 20, 2023
a command-line tool that transforms a Git repository into a minimal format for ChatGPT queries

gprepo /dʒiːpiːˈɹi:pi:oʊ/ a command-line tool that transforms a Git repository into a minimal format for ChatGPT queries. Features Excludes LICENSE an

null 6 Apr 20, 2023
A programming and system administration assistant, powered by chatGPT

TermGPT Interact with ChatGPT from your terminal! ?? ?? Install Cargo cargo install termgpt termgpt --help From source git clone [email protected]:bahdot

Gokul 5 May 11, 2023
A simple command-line tool for conversing with ChatGPT

daberu A simple command-line tool for conversing with ChatGPT. "daberu" is a Japanese translation of "chatting". $ daberu -h ChatGPT client tool that

Takeru Ohta 4 Jun 4, 2023
A localized open-source AI server that is better than ChatGPT.

??AI00 RWKV Server English | 中文 | 日本語 AI00 RWKV Server is an inference API server based on the RWKV model. It supports VULKAN inference acceleration a

顾真牛 142 Aug 23, 2023