ChatMastermind
ChatMastermind is a Python application that automates conversation with AI, stores question-answer pairs with tags, and composes relevant chat history for the next question.
The project uses the OpenAI API to generate responses and stores the data in YAML files. It also allows you to filter chat history based on tags and supports autocompletion for tags.
Official repository URL: https://kaizenkodo.no/gitea/kaizenkodo/ChatMastermind.git
Requirements
- Python 3.9 or higher
- openai
- PyYAML
- argcomplete
You can install these requirements using pip:
pip install -r requirements.txt
Installation
You can install the package with the requirements using pip:
pip install .
Usage
The cmm script has global options, a list of commands, and options per command:
cmm [global options] command [command options]
Global Options
-c,--config: Config file name (defaults to.config.yaml).
Commands
ask: Ask a question.hist: Print chat history.tag: Manage tags.config: Manage configuration.print: Print files.
Command Options
ask Command Options
-q,--question: Question to ask (required).-m,--max-tokens: Max tokens to use.-T,--temperature: Temperature to use.-M,--model: Model to use.-n,--number: Number of answers to produce (default is 3).-s,--source: Add content of a file to the query.-S,--only-source-code: Add pure source code to the chat history.-t,--tags: List of tag names.-e,--extags: List of tag names to exclude.-o,--output-tags: List of output tag names (default is the input tags).-a,--match-all-tags: All given tags must match when selecting chat history entries.
hist Command Options
-d,--dump: Print chat history as Python structure.-w,--with-tags: Print chat history with tags.-W,--with-files: Print chat history with filenames.-S,--only-source-code: Print only source code.-t,--tags: List of tag names.-e,--extags: List of tag names to exclude.-a,--match-all-tags: All given tags must match when selecting chat history entries.
tag Command Options
-l,--list: List all tags and their frequency.
config Command Options
-l,--list-models: List all available models.-m,--print-model: Print the currently configured model.-M,--model: Set model in the config file.
print Command Options
-f,--file: File to print (required).-S,--only-source-code: Print only source code.
Examples
- Ask a question:
cmm ask -q "What is the meaning of life?" -t philosophy -e religion
- Display the chat history:
cmm hist
- Filter chat history by tags:
cmm hist -t tag1 tag2
- Exclude chat history by tags:
cmm hist -e tag3 tag4
- List all tags and their frequency:
cmm tag -l
- Print the contents of a file:
cmm print -f example.yaml
Configuration
The configuration file (.config.yaml) should contain the following fields:
openai:api_key: Your OpenAI API key.model: The name of the OpenAI model to use (e.g. "text-davinci-002").temperature: The temperature value for the model.max_tokens: The maximum number of tokens for the model.top_p: The top P value for the model.frequency_penalty: The frequency penalty value.presence_penalty: The presence penalty value.
system: The system message used to set the behavior of the AI.db: The directory where the question-answer pairs are stored in YAML files.
Autocompletion
To activate autocompletion for tags, add the following line to your shell's configuration file (e.g., .bashrc, .zshrc, or .profile):
eval "$(register-python-argcomplete cmm)"
After adding this line, restart your shell or run source <your-shell-config-file> to enable autocompletion for the cmm script.
Contributing
Enable commit hooks
pip install pre-commit
pre-commit install
Execute tests before opening a PR
pytest
Consider using pyenv / pyenv-virtualenv
Short installation instructions:
- install
pyenv:
cd ~
git clone https://github.com/pyenv/pyenv .pyenv
cd ~/.pyenv && src/configure && make -C src
- make sure that
~/.pyenv/shimsand~/.pyenv/binare the first entries in yourPATH, e. g. by setting it in~/.bashrc - add the following to your
~/.bashrc(after settingPATH):eval "$(pyenv init -)" - create a new terminal or source the changes (e. g.
source ~/.bashrc) - install
virtualenv
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
- add the following to your
~/.bashrc(after the commands above):eval "$(pyenv virtualenv-init -) - create a new terminal or source the changes (e. g.
source ~/.bashrc) - go back to the
ChatMasterMindrepo and create a virtual environment with the latestPython, e. g.3.11.4:
cd <CMM_REPO_PATH>
pyenv install 3.11.4
pyenv virtualenv 3.11.4 py311
pyenv activate py311
- see also the official pyenv documentation
License
This project is licensed under the terms of the WTFPL License.