Package: chap
chap - A Python interface to chatgpt and other LLMs, including a terminal user interface (tui)System requirementsChap is primarily developed on Linux with Python 3.11. Moderate effort will be made to support versions back to Python 3.9 (Debian oldstable).InstallationIf you wantchapavailable as a command, just install withpipx install chaporpip install chap.Use a virtual environment unless you want it installed globally.Installation for developmentUse one of the following two methods to runchapas a command, with the ability to edit the source files. You are welcome to submit valuable changes asa pull request.Viapip install --editable .This is an "editable install", asrecommended by the Python Packaging Authority.Change directory to the root of thechapproject.Activate your virtual environment, then installchapin development mode:pipinstall--editable.In this mode, you get thechapcommand-line program installed, but you are able to edit the source files in thesrcdirectory in place.Viachap-dev.pyA simple shim script calledchap-dev.pyis included to demonstrate how to load and run thechaplibrary without installingchapin development mode. This method may be more familiar to some developers.Change directory to the root of thechapproject.Activate your virtual environment, then install requirements:pipinstall-rrequirements.txtRun the shim script (with optional command flags as appropriate):./chap-dev.pyIn this mode, you can edit the source files in thesrcdirectory in place, and the shim script will pick up the changes via theimportdirective.ContributingSeeCONTRIBUTING.md.Code of ConductSeeCODE_OF_CONDUCT.md.ConfigurationPut your OpenAI API key in the platform configuration directory for chap, e.g., on linux/unix systems at~/.config/chap/openai_api_keyCommand-line usagechap ask "What advice would you give a 20th century human visiting the 21st century for the first time?"chap render --last/chap cat --lastchap import chatgpt-style-chatlog.json(for files from pionxzh/chatgpt-exporter)chap grep needleInteractive terminal usageThe interactive terminal mode is accessed viachap tui.There are a variety of keyboard shortcuts to be aware of:tab/shift-tab to move between the entry field and the conversation, or between conversation itemsWhile in the text box, F9 or (if supported by your terminal) alt+enter to submit multiline textwhile on a conversation item:ctrl+x to re-draft the message. Thissaves a copy of the session in an auto-named file in the conversations folderremoves the conversation from this message to the endputs the user's message in the text box to editctrl+x to re-submit the message. Thissaves a copy of the session in an auto-named file in the conversations folderremoves the conversation from this message to the endputs the user's message in the text boxand submits it immediatelyctrl+y to yank the message. This places the response part of the current
interaction in the operating system clipboard to be pasted (e..g, with
ctrl+v or command+v in other software)ctrl+q to toggle whether this message may be included in the contextual history for a future query.
The exact way history is submitted is determined by the back-end, often by
counting messages or tokens, but the ctrl+q toggle ensures this message (both the user
and assistant message parts) are not considered.Sessions & Command-line ParametersDetails of session handling & command-line arguments are in flux.By default, a new session is created. It is saved to the user's state directory
(e.g.,~/.local/state/chapon linux/unix systems).You can specify the session filename for a new session with-nor to re-open
an existing session with-s. Or, you can continue the last session with--last.You can set the "system message" with the-Sflag.You can select the text generating backend with the-bflag:openai-chatgpt: the default, paid API, best quality resultsllama-cpp: Works withllama.cpp's http serverand can run locally with various models,
though it isoptimized for models that use the llama2-style prompting.
Set the server URL with-B url:....textgen: Works withhttps://github.com/oobabooga/text-generation-webuiand can run locally with various models.
Needs the server URL in$configuration_directory/textgen_url.lorem: local non-AI lorem generator for testingEnvironment variablesThe backend can be set with theCHAP_BACKENDenvironment variable.Backend settings can be set withCHAP_<backend_name>_<parameter_name>, withbackend_nameandparameter_nameall in caps.For instance,CHAP_LLAMA_CPP_URL=http://server.local:8080/completionchanges the default server URL for the llama-cpp back-end.Importing from ChatGPTThe userscripthttps://github.com/pionxzh/chatgpt-exportercan export chat logs from chat.openai.com in a JSON format.This format is different than chap's, especially sincechapcurrently only represents a single branch of conversation in one log.You can use thechap importcommand to import all the branches of a chatgpt-style chatlog in JSON format into a series ofchap-style chat logs.Plug-insChap supports back-end and command plug-ins."Back-ends" add additional text generators."Commands" add new ways to interact with text generators, session data, and so forth.Install a plugin withpip installorpipx inject(depending how you installed chap) and then use it as normal.chap-backend-replayis an example back-end plug-in. It replays answers from a previous session.chap-command-explainis an example command plug-in. It is similar tochap ask.At this time, there is no stability guarantee for the API of commands or backends.