Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding A2rchi CLI #159

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Adding A2rchi CLI #159

wants to merge 2 commits into from

Conversation

mdr223
Copy link
Collaborator

@mdr223 mdr223 commented Jan 5, 2024

First, my apologies for not wrapping this up before the holidays, but this work adds an initial CLI which can be used to create, update, and delete instances of an a2rchi deployment. Note that before you begin you must also have docker and docker compose installed on the machine you're using in order for the CLI to work (it acts as a wrapper around docker compose commands).

To install the CLI, activate a virtual/conda environment and from the root of the repository (i.e. where the pyproject.toml file is) run:

$ pip install .

This will install A2rchi's dependencies as well as a local CLI tool. You should be able to see that it is installed using the which command (your output will be slightly different):

$ which a2rchi
/Users/matthewrusso/A2rchi/venv/bin/a2rchi

The CLI has the following commands:

a2rchi create --name <name> --a2rchi-config <path-to-config> [--grafana True]
a2rchi delete --name <name>
a2rchi update --name <name> --a2rchi-config <path-to-config>

The --name represents the name of your a2rchi deployment and the files for your deployment will be stored under ~/.a2rchi/a2rchi-{name} on your local machine (you don't need to do anything with them, this is just an FYI). The --grafana flag can be included with the value True in order to include a Grafana dashboard with your deployment. The --a2rchi-config is a config provided by the user which can override any of the templatable fields in a2rchi/templates/base-config.yaml (in the future, we could make them all templatable). For example, I have been using the following config to experiment with using GPT-3.5 for both condensing and answering questions:

# stored in file example_conf.yaml
config_name: all_gpt35_config
trained_on_str: "your data"
web_input_lists:
  - config/submit.list
  - config/miscellanea.list
model_name: OpenAIGPT35
condense_model_name: OpenAIGPT35
summary_model_name: OpenAIGPT35
main_prompt: config/prompts/submit.prompt  # NOTE: these are local filepaths; they should be correct if you run the commands below from the root of the repository
condense_prompt: config/prompts/condense.prompt
summary_prompt: config/prompts/summary.prompt

Now, to create an instance of an A2rchi deployment called my-a2rchi (with a grafana dashboard), simply create a file called example_conf.yaml with the contents above and run:

$ a2rchi create --name my-a2rchi --a2rchi-config example_conf.yaml --grafana True

It will take up to (a few) minute(s) for the command to finish (and possibly longer the first time you run it b/c docker will have to fetch the container images from Docker Hub), but you should ultimately see output similar to:

[a2rchi]>> Creating docker volumes
[a2rchi]>> Creating docker volume: a2rchi-my-a2rchi
[a2rchi]>> Creating docker volume: a2rchi-pg-my-a2rchi
[a2rchi]>> Creating docker volume: a2rchi-grafana-my-a2rchi
[a2rchi]>> Preparing Grafana
[a2rchi]>> Preparing Postgres
[a2rchi]>> Preparing Compose
[a2rchi]>> Starting docker compose
...
... A lot of logs from pulling and extracting images ...
...
Network a2rchi-my-a2rchi_default  Creating
Network a2rchi-my-a2rchi_default  Created
Container postgres-my-a2rchi  Creating
Container chromadb-my-a2rchi  Creating
Container postgres-my-a2rchi  Created
Container chromadb-my-a2rchi  Created
Container grafana-my-a2rchi  Creating
Container chat-my-a2rchi  Creating
Container grafana-my-a2rchi  Created
Container chat-my-a2rchi  Created
Container postgres-my-a2rchi  Starting
Container chromadb-my-a2rchi  Starting
Container chromadb-my-a2rchi  Started
Container postgres-my-a2rchi  Started
Container chromadb-my-a2rchi  Waiting
Container postgres-my-a2rchi  Waiting
Container postgres-my-a2rchi  Waiting
Container postgres-my-a2rchi  Healthy
Container grafana-my-a2rchi  Starting
Container postgres-my-a2rchi  Healthy
Container grafana-my-a2rchi  Started
Container chromadb-my-a2rchi  Healthy
Container chat-my-a2rchi  Starting
Container chat-my-a2rchi  Started

You can verify that all your images are up and running properly by executing the following:

$ docker ps -a
CONTAINER ID   IMAGE                          COMMAND                  CREATED         STATUS                   PORTS                    NAMES
7fd9015bf5df   mdr223/a2rchi:chat-0.0.1       "python -u a2rchi/bi…"   3 minutes ago   Up 2 minutes             0.0.0.0:7861->7861/tcp   chat-my-a2rchi
d1f749f12416   mdr223/a2rchi:grafana-0.0.1    "/run.sh"                3 minutes ago   Up 2 minutes             0.0.0.0:3000->3000/tcp   grafana-my-a2rchi
f1298d6efefc   postgres:16                    "docker-entrypoint.s…"   3 minutes ago   Up 2 minutes (healthy)   5432/tcp                 postgres-my-a2rchi
efcb7be30a6e   mdr223/a2rchi:chromadb-0.0.1   "uvicorn chromadb.ap…"   3 minutes ago   Up 2 minutes (healthy)   0.0.0.0:8000->8000/tcp   chromadb-my-a2rchi

Now, suppose you wanted to re-configure your deployment to use GPT-4 instead, you could accomplish this by modifying example_conf.yaml to have the following:

# stored in file example_conf.yaml
config_name: all_gpt4_config
...
model_name: OpenAIGPT4
condense_model_name: OpenAIGPT4
summary_model_name: OpenAIGPT4
...

And then update the deployment in place as follows:

$ a2rchi update --name my-a2rchi
[a2rchi]>> Updating config
[a2rchi]>> config updated successfully w/config_id: 3

If you check the logs for chat-my-a2rchi (by using docker logs chat-my-a2rchi -f) you should see that it will restart with GPT-4 as its model instead.

Note that you could also update your deployments prompts in place by, e.g., creating a new main.prompt and providing the filepath to this new prompt in your example_conf.yaml (it would also work if you just updated the prompt(s) in-place and kept their filepath(s) as-is in the config file).

Finally, to tear down the deployment, simply run:

$ a2rchi delete --name my-a2rchi

Please feel free to ask follow up Q's or let me know if there's anything I can do to make the PR easier to digest!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant