diff --git a/.github/workflows/prod-801-ci-cd.yaml b/.github/workflows/prod-801-ci-cd.yaml new file mode 100644 index 00000000..9545044f --- /dev/null +++ b/.github/workflows/prod-801-ci-cd.yaml @@ -0,0 +1,70 @@ +name: Deploy A2rchi Prod for 8.01 +run-name: ${{ github.actor }} deploys A2rchi for 8.01 to prod +on: + push: + branches: + - release-8.01 +jobs: + deploy-prod-system: + runs-on: ubuntu-latest + env: + SSH_AUTH_SOCK: /tmp/ssh_agent.sock + steps: + # boilerplate message and pull repository to CI runner + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - uses: actions/checkout@v3 + - run: echo "The ${{ github.repository }} repository has been cloned to the runner." + + # setup SSH + - name: Setup SSH + run: | + mkdir -p /home/runner/.ssh/ + echo "${{ secrets.SSH_PRIVATE_KEY_MDRUSSO }}" > /home/runner/.ssh/id_rsa_submit + chmod 600 /home/runner/.ssh/id_rsa_submit + echo "${{ secrets.SSH_SUBMIT_KNOWN_HOSTS }}" > ~/.ssh/known_hosts + cp ${{ github.workspace }}/deploy/ssh_config /home/runner/.ssh/config + ssh-agent -a $SSH_AUTH_SOCK > /dev/null + ssh-add /home/runner/.ssh/id_rsa_submit + + # create secrets files for docker-compose + - name: Create Secrets Files + run: | + mkdir -p ${{ github.workspace }}/deploy/prod-801/secrets/ + touch ${{ github.workspace }}/deploy/prod-801/secrets/flask_uploader_app_secret_key.txt + echo "${{ secrets.PROD_FLASK_UPLOADER_APP_SECRET_KEY }}" >> ${{ github.workspace }}/deploy/prod-801/secrets/flask_uploader_app_secret_key.txt + chmod 400 ${{ github.workspace }}/deploy/prod-801/secrets/flask_uploader_app_secret_key.txt + touch ${{ github.workspace }}/deploy/prod-801/secrets/uploader_salt.txt + echo "${{ secrets.PROD_UPLOADER_SALT }}" >> ${{ github.workspace }}/deploy/prod-801/secrets/uploader_salt.txt + chmod 400 ${{ github.workspace }}/deploy/prod-801/secrets/uploader_salt.txt + touch ${{ github.workspace }}/deploy/prod-801/secrets/openai_api_key.txt + echo "${{ secrets.OPENAI_API_KEY }}" >> ${{ github.workspace }}/deploy/prod-801/secrets/openai_api_key.txt + chmod 400 ${{ github.workspace }}/deploy/prod-801/secrets/openai_api_key.txt + touch ${{ github.workspace }}/deploy/prod-801/secrets/hf_token.txt + echo "${{ secrets.HF_TOKEN }}" >> ${{ github.workspace }}/deploy/prod-801/secrets/hf_token.txt + chmod 400 ${{ github.workspace }}/deploy/prod-801/secrets/hf_token.txt + + # stop any existing docker compose that's running + - name: Stop Docker Compose + run: | + ssh submit-t3desk 'bash -s' < ${{ github.workspace }}/deploy/prod-801/prod-801-stop.sh + + # copy repository to machine + - name: Copy Repository + run: | + rsync -e ssh -r ${{ github.workspace}}/* --exclude .git/ --delete submit-t3desk:~/A2rchi-prod-801/ + + # run deploy script + - name: Run Deploy Script + run: | + ssh submit-t3desk 'bash -s' < ${{ github.workspace }}/deploy/prod-801/prod-801-install.sh + + # clean up secret files + - name: Remove Secrets from Runner + run: | + rm ${{ github.workspace }}/deploy/prod-801/secrets/flask_uploader_app_secret_key.txt + rm ${{ github.workspace }}/deploy/prod-801/secrets/uploader_salt.txt + rm ${{ github.workspace }}/deploy/prod-801/secrets/openai_api_key.txt + rm ${{ github.workspace }}/deploy/prod-801/secrets/hf_token.txt + + # print job status + - run: echo "🍏 This job's status is ${{ job.status }}." \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1c11446a..bdd9ff66 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ venv *.egg-info *sqlite_db .vscode +801-content/ diff --git a/A2rchi/bin/service_chat.py b/A2rchi/bin/service_chat.py index 4a74cd36..2b6f0120 100644 --- a/A2rchi/bin/service_chat.py +++ b/A2rchi/bin/service_chat.py @@ -11,6 +11,7 @@ os.environ['OPENAI_API_KEY'] = read_secret("OPENAI_API_KEY") os.environ['HUGGING_FACE_HUB_TOKEN'] = read_secret("HUGGING_FACE_HUB_TOKEN") config = Config_Loader().config["interfaces"]["chat_app"] +global_config = Config_Loader().config["global"] print(f"Starting Chat Service with (host, port): ({config['HOST']}, {config['PORT']})") def generate_script(config): @@ -22,6 +23,7 @@ def generate_script(config): template = f.read() filled_template = template.replace('XX-HTTP_PORT-XX', str(config["EXTERNAL_PORT"])) + filled_template = filled_template.replace('XX-TRAINED_ON-XX', str(global_config["TRAINED_ON"])) script_file = os.path.join(config["static_folder"], "script.js") with open(script_file, "w") as f: diff --git a/A2rchi/chains/prompts.py b/A2rchi/chains/prompts.py index e2c26c6a..cfc5ef93 100644 --- a/A2rchi/chains/prompts.py +++ b/A2rchi/chains/prompts.py @@ -1,27 +1,31 @@ # flake8: noqa from langchain.prompts.prompt import PromptTemplate +from A2rchi.utils.config_loader import Config_Loader -condense_history_template = """Given the following conversation between you (the AI named A2rchi), a human user who needs help, and an expert, and a follow up question, rephrase the follow up question to be a standalone question, in its original language. +config = Config_Loader().config["chains"]["prompts"] -Chat History: -{chat_history} -Follow Up Input: {question} -Standalone question:""" +def read_prompt(prompt_filepath, is_condense_prompt=False, is_main_prompt=False): + with open(prompt_filepath, "r") as f: + raw_prompt = f.read() -prompt_template = """You are a conversational chatbot named A2rchi who helps people navigate a computing resource named subMIT. You will be provided context to help you answer their questions. -Using your linux and computing knowledge, answer the question at the end. Unless otherwise indicated, assume the users are not well versed computing. - Please do not assume that subMIT machines have anything installed on top of native linux except if the context mentions it. -If you don't know, say "I don't know", if you need to ask a follow up question, please do. + prompt = "" + for line in raw_prompt.split("\n"): + if len(line.lstrip())>0 and line.lstrip()[0:1] != "#": + prompt += line + "\n" -Context: {context} Additionally, it is always preferred to use conda, if possible. + if is_condense_prompt and ("{chat_history}" not in prompt or "{question}" not in prompt): + raise ValueError("""Condensing prompt must contain \"{chat_history}\" and \"{question}\" tags. Instead, found prompt to be: + """ + prompt) + if is_main_prompt and ("{context}" not in prompt or "{question}" not in prompt): + raise ValueError("""Condensing prompt must contain \"{context}\" and \"{question}\" tags. Instead, found prompt to be: + """ + prompt) -Question: {question} -Helpful Answer:""" + return prompt QA_PROMPT = PromptTemplate( - template=prompt_template, input_variables=["context", "question"] + template=read_prompt(config["MAIN_PROMPT"], is_main_prompt=True), input_variables=["context", "question"] ) CONDENSE_QUESTION_PROMPT = PromptTemplate( - template=condense_history_template, input_variables=["chat_history", "question"] + template=read_prompt(config["CONDENSING_PROMPT"], is_condense_prompt=True), input_variables=["chat_history", "question"] ) diff --git a/A2rchi/interfaces/chat_app/app.py b/A2rchi/interfaces/chat_app/app.py index e4353ce9..20401bd5 100644 --- a/A2rchi/interfaces/chat_app/app.py +++ b/A2rchi/interfaces/chat_app/app.py @@ -153,8 +153,9 @@ def __init__(self, app, **configs): CORS(self.app) # add endpoints for flask app - self.add_endpoint('/get_chat_response', 'get_chat_response', self.get_chat_response, methods=["POST"]) + self.add_endpoint('/api/get_chat_response', 'get_chat_response', self.get_chat_response, methods=["POST"]) self.add_endpoint('/', '', self.index) + self.add_endpoint('/terms', 'terms', self.terms) def configs(self, **configs): for config, value in configs: @@ -193,3 +194,6 @@ def get_chat_response(self): def index(self): return render_template('index.html') + + def terms(self): + return render_template('terms.html') diff --git a/A2rchi/interfaces/chat_app/static/script.js b/A2rchi/interfaces/chat_app/static/script.js index 2b7ab165..ed0b5302 100644 --- a/A2rchi/interfaces/chat_app/static/script.js +++ b/A2rchi/interfaces/chat_app/static/script.js @@ -18,7 +18,9 @@ const loadDataFromLocalstorage = () => { const defaultText = `

A2rchi

-

Start a conversation and explore the power of A2rchi.
Your chat history will be displayed here.

+

Start a conversation and explore the power of A2rchi, specially trained on subMIT.
+ Your chat history will be displayed here.

+ By using this website, you agree to the terms and conditions.

` chatContainer.innerHTML = localStorage.getItem("all-chats") || defaultText; @@ -40,7 +42,7 @@ const refreshChat = async () => { } const getChatResponse = async (incomingChatDiv) => { - const API_URL = "http://0.0.0.0:7861/get_chat_response"; + const API_URL = "http://t3desk019.mit.edu:7861/api/get_chat_response"; const pElement = document.createElement("div"); // Define the properties and data for the API request diff --git a/A2rchi/interfaces/chat_app/static/script.js-template b/A2rchi/interfaces/chat_app/static/script.js-template index 75b994cc..5e407a14 100644 --- a/A2rchi/interfaces/chat_app/static/script.js-template +++ b/A2rchi/interfaces/chat_app/static/script.js-template @@ -18,7 +18,9 @@ const loadDataFromLocalstorage = () => { const defaultText = `

A2rchi

-

Start a conversation and explore the power of A2rchi.
Your chat history will be displayed here.

+

Start a conversation and explore the power of A2rchi, specially trained on XX-TRAINED_ON-XX.
+ Your chat history will be displayed here.

+ By using this website, you agree to the terms and conditions.

` chatContainer.innerHTML = localStorage.getItem("all-chats") || defaultText; @@ -40,7 +42,7 @@ const refreshChat = async () => { } const getChatResponse = async (incomingChatDiv) => { - const API_URL = "http://0.0.0.0:XX-HTTP_PORT-XX/get_chat_response"; + const API_URL = "http://t3desk019.mit.edu:XX-HTTP_PORT-XX/api/get_chat_response"; const pElement = document.createElement("div"); // Define the properties and data for the API request diff --git a/A2rchi/interfaces/chat_app/templates/terms.html b/A2rchi/interfaces/chat_app/templates/terms.html new file mode 100644 index 00000000..ce6a458e --- /dev/null +++ b/A2rchi/interfaces/chat_app/templates/terms.html @@ -0,0 +1,40 @@ + + + +Terms and Conditions + + +

Terms and Conditions

+ +

Welcome to A2rchi. By using this website, you agree to comply with and be bound by the following terms and conditions of use. Please review these terms carefully before using the website. If you do not agree to these terms, you should not use the website. +

+ +

1. Data Usage and Privacy:

+ +

1.1 We may collect and store the questions you ask the chat bot for research and improvement purposes. However, we do not collect any additional meta data, and we will never share this information with any third party.

+ +

2. Usage Restrictions:

+ +

2.1 You agree to use the chat bot provided on the website only for its intended purpose and not for any unauthorized or unlawful activities.

+ +

2.2 You agree not to use the chat bot to generate spam or any automated content that disrupts the service or violates the rights of others.

+ +

3. Termination of Use:

+ +

3.1 We reserve the right to terminate your access to the chat bot and the website at our discretion, without notice, if you violate these terms and conditions.

+ +

4. Changes to Terms and Conditions:

+ +

4.1 We may revise these terms and conditions at any time without notice. By continuing to use the website after such changes, you agree to be bound by the revised terms.

+ +

5. Disclaimer:

+ +

5.1 The chat bot provided on the website is for informational purposes only. We do not guarantee the accuracy, completeness, or reliability of the information provided by the chat bot.

+ +

6. Contact Us:

+ +

6.1 If you have any questions or concerns regarding these terms and conditions, please contact us at a2rchi@mit.edu.

+ +

By using the website, you acknowledge that you have read, understood, and agree to be bound by these terms and conditions. Your continued use of the website constitutes your acceptance of these terms.

+ + diff --git a/A2rchi/utils/config_loader.py b/A2rchi/utils/config_loader.py index 41a43b5d..eb4ec527 100644 --- a/A2rchi/utils/config_loader.py +++ b/A2rchi/utils/config_loader.py @@ -16,9 +16,9 @@ def load_config(self): """ Small function for loading the config.yaml file """ - prod_or_dev = os.getenv("PROD_OR_DEV") + env = os.getenv("RUNTIME_ENV") try: - with open(f"./config/{prod_or_dev}-config.yaml", "r") as f: + with open(f"./config/{env}-config.yaml", "r") as f: config = yaml.load(f, Loader=yaml.FullLoader) # change the model class parameter from a string to an actual class diff --git a/A2rchi/utils/scraper.py b/A2rchi/utils/scraper.py index 364023af..9a93caed 100644 --- a/A2rchi/utils/scraper.py +++ b/A2rchi/utils/scraper.py @@ -59,7 +59,7 @@ def collect_urls_from_lists(self): data = f.read() for line in data.split("\n"): - if len(line) > 0 and line[0] != '#': + if len(line.lstrip())>0 and line.lstrip()[0:1] != "#": urls.append(line) return urls diff --git a/config/dev-config.yaml b/config/dev-config.yaml index bb006dc5..b426fe53 100644 --- a/config/dev-config.yaml +++ b/config/dev-config.yaml @@ -1,4 +1,5 @@ global: + TRAINED_ON: "subMIT (development)" #used to create name of the specific version of a2rchi we're using DATA_PATH: "/root/data/" ACCOUNTS_PATH: "/root/.accounts/" LOCAL_VSTORE_PATH: "/root/data/vstore/" @@ -31,6 +32,11 @@ chains: - User - A2rchi - Expert + prompts: + # prompt that serves to condense a history and a question into a single question + CONDENSING_PROMPT: config/prompts/condense.prompt + # main prompt which takes in a single question and a context. + MAIN_PROMPT: config/prompts/submit.prompt chain: # pick one of the models listed in the model class map below MODEL_NAME: OpenAILLM # LlamaLLM diff --git a/config/prod-801-config.yaml b/config/prod-801-config.yaml new file mode 100644 index 00000000..08cea210 --- /dev/null +++ b/config/prod-801-config.yaml @@ -0,0 +1,110 @@ +global: + TRAINED_ON: "8.01" #used to create name of the specific version of a2rchi we're using + DATA_PATH: "/root/data/" + ACCOUNTS_PATH: "/root/.accounts/" + LOCAL_VSTORE_PATH: "/root/data/vstore/" + ACCEPTED_FILES: + -".txt" + -".html" + -".pdf" + +interfaces: + chat_app: + PORT: 7861 + EXTERNAL_PORT: 7683 + HOST: "0.0.0.0" # either "0.0.0.0" (for public) or "127.0.0.1" (for internal) + HOSTNAME: "ppc.mit.edu" # careful, this is used for the chat service + template_folder: "/root/A2rchi/A2rchi/interfaces/chat_app/templates" + static_folder: "/root/A2rchi/A2rchi/interfaces/chat_app/static" + uploader_app: + PORT: 5001 + HOST: "0.0.0.0" # either "0.0.0.0" (for public) or "127.0.0.1" (for internal) + template_folder: "/root/A2rchi/A2rchi/interfaces/uploader_app/templates" + +chains: + input_lists: + - empty.list + - miscellanea.list + base: + # roles that A2rchi knows about + ROLES: + - User + - A2rchi + - Expert + prompts: + # prompt that serves to condense a history and a question into a single question + CONDENSING_PROMPT: config/prompts/condense.prompt + # main prompt which takes in a single question and a context. + MAIN_PROMPT: config/prompts/801.prompt + chain: + # pick one of the models listed in the model class map below + MODEL_NAME: OpenAILLM + # map of all the class models and their keyword arguments + MODEL_CLASS_MAP: + OpenAILLM: + class: OpenAILLM + kwargs: + model_name: gpt-4 + temperature: 1 + DumbLLM: + class: DumbLLM + kwargs: + filler: null + LlamaLLM: + class: LlamaLLM + kwargs: + base_model: "meta-llama/Llama-2-7b-chat-hf" #the location of the model (ex. meta-llama/Llama-2-70b) + peft_model: null #the location of the finetuning of the model. Can be none + enable_salesforce_content_safety: True # Enable safety check with Salesforce safety flan t5 + quantization: True #enables 8-bit quantization + max_new_tokens: 4096 #The maximum numbers of tokens to generate + seed: null #seed value for reproducibility + do_sample: True #Whether or not to use sampling ; use greedy decoding otherwise. + min_length: null #The minimum length of the sequence to be generated, input prompt + min_new_tokens + use_cache: True #[optional] Whether or not the model should use the past last key/values attentions Whether or not the model should use the past last key/values attentions (if applicable to the model) to speed up decoding. + top_p: .9 # [optional] If set to float < 1, only the smallest set of most probable tokens with probabilities that add up to top_p or higher are kept for generation. + temperature: .6 # [optional] The value used to modulate the next token probabilities. + top_k: 50 # [optional] The number of highest probability vocabulary tokens to keep for top-k-filtering. + repetition_penalty: 1.0 #The parameter for repetition penalty. 1.0 means no penalty. + length_penalty: 1 #[optional] Exponential penalty to the length that is used with beam-based generation. + max_padding_length: null # the max padding length to be used with tokenizer padding the prompts. + chain_update_time: 10 # the amount of time (in seconds) which passes between when the chain updates to the newest version of the vectorstore +utils: + cleo: + cleo_update_time: 10 + mailbox: + IMAP4_PORT: 143 + mailbox_update_time: 10 + data_manager: + CHUNK_SIZE: 1000 + CHUNK_OVERLAP: 0 + use_HTTP_chromadb_client: True # recommended: True (use http client for the chromadb vectorstore?) + # use_HTTP_chromadb_client: False + vectordb_update_time: 10 + chromadb_host: chromadb-prod-801 + chromadb_port: 8000 + collection_name: "prod_801_collection" #unique in case vector stores are ever combined. + reset_collection: True # reset the entire collection each time it is accessed by a new data manager instance + embeddings: + # choose one embedding from list below + EMBEDDING_NAME: OpenAIEmbeddings + # list of possible embeddings to use in vectorstore + EMBEDDING_CLASS_MAP: + OpenAIEmbeddings: + class: OpenAIEmbeddings + kwargs: + model: text-embedding-ada-002 + similarity_score_reference: 0.4 + HuggingFaceEmbeddings: + class: HuggingFaceEmbeddings + kwargs: + model_name: "sentence-transformers/all-mpnet-base-v2" + model_kwargs: + device: 'cpu' + encode_kwargs: + normalize_embeddings: True + similarity_score_reference: 0.9 + scraper: + reset_data: True # delete websites and sources.yml in data folder + verify_urls: False # should be true when possible + enable_warnings: False # keeps output clean if verify == False diff --git a/config/prod-config.yaml b/config/prod-config.yaml index 4b0468da..5bd5f5bf 100644 --- a/config/prod-config.yaml +++ b/config/prod-config.yaml @@ -1,4 +1,5 @@ global: + TRAINED_ON: "subMIT" #used to create name of the specific version of a2rchi we're using DATA_PATH: "/root/data/" ACCOUNTS_PATH: "/root/.accounts/" LOCAL_VSTORE_PATH: "/root/data/vstore/" @@ -31,6 +32,11 @@ chains: - User - A2rchi - Expert + prompts: + # prompt that serves to condense a history and a question into a single question + CONDENSING_PROMPT: config/prompts/condense.prompt + # main prompt which takes in a single question and a context. + MAIN_PROMPT: config/prompts/submit.prompt chain: # pick one of the models listed in the model class map below MODEL_NAME: OpenAILLM diff --git a/config/prompts/801.prompt b/config/prompts/801.prompt new file mode 100644 index 00000000..f33be0de --- /dev/null +++ b/config/prompts/801.prompt @@ -0,0 +1,16 @@ +# Prompt used to qurery LLM with appropriate context and question. +# This prompt is specific to 8.01 taught at MIT and likely will not perform well for other applications, where it is recommeneded to write your own prompt and change it in the config +# +# All final promptsd must have the following tags in them, which will be filled with the appropriate information: +# {question} +# {context} +# +You are a conversational chatbot and teaching assisitant named A2rchi who helps students taking Classical Mechanics 1 at MIT (also called 8.01). You will be provided context to help you answer their questions. +Using your physics, math, and problem solving knowledge, answer the question at the end. Unless otherwise indicated, assume the users know high school level physics. +Since you are a teaching assisitant, please try to give throughou answers to questions with explanations, instead of just giving the answer. +If you don't know, say "I don't know". It is extremely important you only give correct answers. If you need to ask a follow up question, please do. + +Context: {context} + +Question: {question} +Helpful Answer: \ No newline at end of file diff --git a/config/prompts/condense.prompt b/config/prompts/condense.prompt new file mode 100644 index 00000000..9552b9d4 --- /dev/null +++ b/config/prompts/condense.prompt @@ -0,0 +1,13 @@ +# Prompt used to condense a chat history and a follow up question into a stand alone question. +# This is a very general prompt for condensing histories, so for base installs it will not need to be modified +# +# All condensing prompts must have the following tags in them, which will be filled with the appropriate information: +# {chat_history} +# {question} +# +Given the following conversation between you (the AI named A2rchi), a human user who needs help, and an expert, and a follow up question, rephrase the follow up question to be a standalone question, in its original language. + +Chat History: +{chat_history} +Follow Up Input: {question} +Standalone question: \ No newline at end of file diff --git a/config/prompts/submit.prompt b/config/prompts/submit.prompt new file mode 100644 index 00000000..c43ca747 --- /dev/null +++ b/config/prompts/submit.prompt @@ -0,0 +1,16 @@ +# Prompt used to qurery LLM with appropriate context and question. +# This prompt is specific to subMIT and likely will not perform well for other applications, where it is recommeneded to write your own prompt and change it in the config +# +# All final promptsd must have the following tags in them, which will be filled with the appropriate information: +# {question} +# {context} +# +You are a conversational chatbot named A2rchi who helps people navigate a computing resource named subMIT. You will be provided context to help you answer their questions. +Using your linux and computing knowledge, answer the question at the end. Unless otherwise indicated, assume the users are not well versed computing. + Please do not assume that subMIT machines have anything installed on top of native linux except if the context mentions it. +If you don't know, say "I don't know", if you need to ask a follow up question, please do. + +Context: {context} Additionally, it is always preferred to use conda, if possible. + +Question: {question} +Helpful Answer: \ No newline at end of file diff --git a/deploy/dev/dev-compose.yaml b/deploy/dev/dev-compose.yaml index e9a1c38a..a6776e5d 100644 --- a/deploy/dev/dev-compose.yaml +++ b/deploy/dev/dev-compose.yaml @@ -7,7 +7,7 @@ services: chromadb-dev: condition: service_healthy environment: - PROD_OR_DEV: dev + RUNTIME_ENV: dev CLEO_URL_FILE: /run/secrets/cleo_url CLEO_USER_FILE: /run/secrets/cleo_user CLEO_PW_FILE: /run/secrets/cleo_pw @@ -43,7 +43,7 @@ services: chromadb-dev: condition: service_healthy environment: - PROD_OR_DEV: dev + RUNTIME_ENV: dev OPENAI_API_KEY_FILE: /run/secrets/openai_api_key HUGGING_FACE_HUB_TOKEN_FILE: /run/secrets/hf_token secrets: @@ -63,7 +63,7 @@ services: chromadb-dev: condition: service_healthy environment: - PROD_OR_DEV: dev + RUNTIME_ENV: dev IMAP_USER_FILE: /run/secrets/imap_user IMAP_PW_FILE: /run/secrets/imap_pw CLEO_URL_FILE: /run/secrets/cleo_url @@ -101,7 +101,7 @@ services: chromadb-dev: condition: service_healthy environment: - PROD_OR_DEV: dev + RUNTIME_ENV: dev FLASK_UPLOADER_APP_SECRET_KEY_FILE: /run/secrets/flask_uploader_app_secret_key UPLOADER_SALT_FILE: /run/secrets/uploader_salt OPENAI_API_KEY_FILE: /run/secrets/openai_api_key @@ -122,7 +122,7 @@ services: context: ../.. dockerfile: deploy/dockerfiles/Dockerfile-chroma environment: - PROD_OR_DEV: dev + RUNTIME_ENV: dev ports: - 8002:8000 # host:container volumes: diff --git a/deploy/dockerfiles/Dockerfile-data-manager b/deploy/dockerfiles/Dockerfile-data-manager index 8f98e6cf..99481d61 100644 --- a/deploy/dockerfiles/Dockerfile-data-manager +++ b/deploy/dockerfiles/Dockerfile-data-manager @@ -9,4 +9,7 @@ COPY config config COPY A2rchi A2rchi RUN pip install --upgrade pip && pip install . +# ensure this directory is present for prod-801 deployment +RUN if [ "$BUILD_ENV" = "prod-801" ] ; then mkdir /root/data/801-content ; fi + CMD ["python", "-u", "A2rchi/bin/service_data_manager.py"] diff --git a/deploy/prod-801/prod-801-compose.yaml b/deploy/prod-801/prod-801-compose.yaml new file mode 100644 index 00000000..c6b41d62 --- /dev/null +++ b/deploy/prod-801/prod-801-compose.yaml @@ -0,0 +1,81 @@ +services: + chat-prod-801: + build: + context: ../.. + dockerfile: deploy/dockerfiles/Dockerfile-chat + depends_on: + chromadb-prod-801: + condition: service_healthy + environment: + RUNTIME_ENV: prod-801 + OPENAI_API_KEY_FILE: /run/secrets/openai_api_key + HUGGING_FACE_HUB_TOKEN_FILE: /run/secrets/hf_token + secrets: + - openai_api_key + - hf_token + volumes: + - a2rchi-prod-801-data:/root/data/ + ports: + - 7683:7861 # host:container + restart: always + + data-manager-prod-801: + build: + context: ../.. + dockerfile: deploy/dockerfiles/Dockerfile-data-manager + args: + BUILD_ENV: prod-801 + depends_on: + chromadb-prod-801: + condition: service_healthy + environment: + RUNTIME_ENV: prod-801 + FLASK_UPLOADER_APP_SECRET_KEY_FILE: /run/secrets/flask_uploader_app_secret_key + UPLOADER_SALT_FILE: /run/secrets/uploader_salt + OPENAI_API_KEY_FILE: /run/secrets/openai_api_key + HUGGING_FACE_HUB_TOKEN_FILE: /run/secrets/hf_token + secrets: + - flask_uploader_app_secret_key + - uploader_salt + - openai_api_key + - hf_token + ports: + - 5004:5001 # host:container + volumes: + - a2rchi-prod-801-data:/root/data/ + - /home/tier3/a2rchi/801-content/:/root/data/801-content/ + restart: always + + chromadb-prod-801: + build: + context: ../.. + dockerfile: deploy/dockerfiles/Dockerfile-chroma + environment: + RUNTIME_ENV: prod-801 + ports: + - 8003:8000 # host:container + volumes: + - a2rchi-prod-801-data:/chroma/chroma/ + restart: always + # healthcheck originates from inside container; so use container port + healthcheck: + test: ["CMD", "curl", "-f", "http://0.0.0.0:8000/api/v1/heartbeat"] + interval: 15s + timeout: 10s + retries: 3 + start_period: 10s + start_interval: 5s + +volumes: + a2rchi-prod-801-data: + external: true + +secrets: + flask_uploader_app_secret_key: + file: secrets/flask_uploader_app_secret_key.txt + uploader_salt: + file: secrets/uploader_salt.txt + openai_api_key: + file: secrets/openai_api_key.txt + hf_token: + file: secrets/hf_token.txt diff --git a/deploy/prod-801/prod-801-install.sh b/deploy/prod-801/prod-801-install.sh new file mode 100644 index 00000000..0e3691e5 --- /dev/null +++ b/deploy/prod-801/prod-801-install.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# create volume if it doesn't already exist +exists=`docker volume ls | awk '{print $2}' | grep a2rchi-prod-801-data` +if [[ $exists != 'a2rchi-prod-801-data' ]]; then + docker volume create --name a2rchi-prod-801-data +fi + +# start services +echo "Starting docker compose" +cd A2rchi-prod-801/deploy/prod-801/ +docker compose -f prod-801-compose.yaml up -d --build --force-recreate --always-recreate-deps + +# # secrets files are created by CI pipeline and destroyed here +# rm secrets/cleo_*.txt +# rm secrets/imap_*.txt +# rm secrets/sender_*.txt +# rm secrets/flask_uploader_app_secret_key.txt +# rm secrets/uploader_salt.txt +# rm secrets/openai_api_key.txt +# rm secrets/hf_token.txt diff --git a/deploy/prod-801/prod-801-stop.sh b/deploy/prod-801/prod-801-stop.sh new file mode 100644 index 00000000..d367bd5b --- /dev/null +++ b/deploy/prod-801/prod-801-stop.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +echo "Stop running docker compose" +cd A2rchi-prod-801/deploy/prod-801/ +docker compose -f prod-801-compose.yaml down diff --git a/deploy/prod/prod-compose.yaml b/deploy/prod/prod-compose.yaml index 45139990..a7d52d79 100644 --- a/deploy/prod/prod-compose.yaml +++ b/deploy/prod/prod-compose.yaml @@ -7,7 +7,7 @@ services: chromadb-prod: condition: service_healthy environment: - PROD_OR_DEV: prod + RUNTIME_ENV: prod CLEO_URL_FILE: /run/secrets/cleo_url CLEO_USER_FILE: /run/secrets/cleo_user CLEO_PW_FILE: /run/secrets/cleo_pw @@ -43,7 +43,7 @@ services: chromadb-prod: condition: service_healthy environment: - PROD_OR_DEV: prod + RUNTIME_ENV: prod OPENAI_API_KEY_FILE: /run/secrets/openai_api_key HUGGING_FACE_HUB_TOKEN_FILE: /run/secrets/hf_token secrets: @@ -63,7 +63,7 @@ services: chromadb-prod: condition: service_healthy environment: - PROD_OR_DEV: prod + RUNTIME_ENV: prod IMAP_USER_FILE: /run/secrets/imap_user IMAP_PW_FILE: /run/secrets/imap_pw CLEO_URL_FILE: /run/secrets/cleo_url @@ -101,7 +101,7 @@ services: chromadb-prod: condition: service_healthy environment: - PROD_OR_DEV: prod + RUNTIME_ENV: prod FLASK_UPLOADER_APP_SECRET_KEY_FILE: /run/secrets/flask_uploader_app_secret_key UPLOADER_SALT_FILE: /run/secrets/uploader_salt OPENAI_API_KEY_FILE: /run/secrets/openai_api_key @@ -122,7 +122,7 @@ services: context: ../.. dockerfile: deploy/dockerfiles/Dockerfile-chroma environment: - PROD_OR_DEV: prod + RUNTIME_ENV: prod ports: - 8000:8000 # host:container volumes: