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

Feature/login page #157

Closed
wants to merge 82 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
a808cde
Merge pull request #105 from mit-submit/hotfix/malformed-json-lock-ra…
julius-heitkoetter Oct 16, 2023
364efad
Merge pull request #110 from mit-submit/main
julius-heitkoetter Oct 18, 2023
7c6811c
Merge pull request #116 from mit-submit/main
julius-heitkoetter Oct 20, 2023
5053f3a
Merge pull request #118 from mit-submit/main
mdr223 Oct 21, 2023
15714bb
up query limit and fail gracefully if history is empty
mdr223 Oct 25, 2023
44243d8
Merge pull request #120 from mit-submit/hotfix/up-query-limit-fail-gr…
mdr223 Oct 25, 2023
79b6271
sleep for 5 mins to let data manager catch up
mdr223 Oct 26, 2023
3c6c58d
move sleep inside init
mdr223 Oct 26, 2023
b277f9f
remove sleep
mdr223 Oct 26, 2023
588d64a
move to 7684
mdr223 Oct 26, 2023
34eaaaa
moving back to port 7683
julius-heitkoetter Oct 26, 2023
aa556a8
Merge pull request #128 from mit-submit/cleanup/8.01_release_after_lo…
julius-heitkoetter Oct 26, 2023
6f46f4e
added classes for user login
julius-heitkoetter Nov 27, 2023
829153c
added image for login page background
julius-heitkoetter Nov 27, 2023
cf6452c
added login capabilities to the back end
julius-heitkoetter Nov 27, 2023
a12bad0
added function for the sidebar
julius-heitkoetter Nov 27, 2023
4f6a9d5
styling for sidebar and login page
julius-heitkoetter Nov 27, 2023
f68979b
adding sidebar to homepage
julius-heitkoetter Nov 27, 2023
d2b9c6c
added other pages for logged in users
julius-heitkoetter Nov 27, 2023
752782f
added login manager and database to launch service
julius-heitkoetter Nov 27, 2023
2d8c9da
changed deploy and config for dev
julius-heitkoetter Nov 27, 2023
5a17315
merge resolving conflicts
julius-heitkoetter Nov 27, 2023
4e15eeb
Merge pull request #156 from mit-submit/temp-login-merge-resolution
julius-heitkoetter Nov 27, 2023
507e952
adding required packages
julius-heitkoetter Nov 27, 2023
37c744b
changing A2rchi->a2rchi
julius-heitkoetter Nov 27, 2023
10581fe
adding to test deployment
julius-heitkoetter Nov 27, 2023
ecf581f
adding merge conflict resolution
julius-heitkoetter Nov 27, 2023
5244e3c
moving to t3desk
julius-heitkoetter Nov 27, 2023
6cee11c
fixing secret loading bug
julius-heitkoetter Nov 28, 2023
3a1e070
adding flask login page to requirements
julius-heitkoetter Nov 28, 2023
00a186b
updating pyproject
julius-heitkoetter Nov 28, 2023
d0f3163
constraining werkzeug version
julius-heitkoetter Nov 28, 2023
129d51c
updating requirements
julius-heitkoetter Nov 28, 2023
8656700
added secrets for login
julius-heitkoetter Nov 28, 2023
9f362c7
typo fix
julius-heitkoetter Nov 28, 2023
356e16d
changing db init path
julius-heitkoetter Nov 28, 2023
3b223bd
typo in config
julius-heitkoetter Nov 28, 2023
9edf7bf
renaming flask uploader key to flask key
julius-heitkoetter Nov 28, 2023
09a2ae3
fix typo in flask key
julius-heitkoetter Nov 28, 2023
3c5abb5
temparily removing docker down
julius-heitkoetter Nov 28, 2023
687f56e
adding back docker down
julius-heitkoetter Nov 28, 2023
74a536c
making temporary files for ssl certificates
julius-heitkoetter Nov 28, 2023
705ae2f
trying without ssl certificate
julius-heitkoetter Nov 28, 2023
e074b94
making callback method dynamic to update users
julius-heitkoetter Nov 28, 2023
dfb9274
adding final changes to include update config command
mdr223 Jan 5, 2024
30149a4
adding summary prompt for future
mdr223 Jan 5, 2024
ec82ce8
removed legacy A2rchi folder
julius-heitkoetter Jan 9, 2024
28bbd15
adding legacy testapp code for tracking
julius-heitkoetter Jan 9, 2024
0b04f01
removing legacy testapp code
julius-heitkoetter Jan 9, 2024
6ed105e
updating configurations for login
julius-heitkoetter Jan 9, 2024
9be3748
updating deployment folder
julius-heitkoetter Jan 9, 2024
3d358a0
updating workflows
julius-heitkoetter Jan 9, 2024
1a721f5
added admin settings to main menu for admins
julius-heitkoetter Jan 9, 2024
39fc410
updated 801 course info to f24
Sep 10, 2024
e26e03d
redeploying with f24 syllabus in place
Sep 12, 2024
993b079
adding piazza service for 801
Sep 17, 2024
d99d8bd
removing extra ' in compose yaml
pmlugato Sep 19, 2024
6e8d154
Merge pull request #165 from mit-submit/feature/801_piazza_service
pmlugato Sep 19, 2024
03c0088
missing comma in pyproject.toml
Sep 19, 2024
243660b
Merge pull request #167 from mit-submit/feature/801_piazza_service
pmlugato Sep 19, 2024
f96d11b
wrong filename
Sep 19, 2024
584ea41
changing code to better reflect new deployment scheme; minor bug fixes
julius-heitkoetter Oct 30, 2024
ecf44cb
removing old deployment scheme and million configuration files
julius-heitkoetter Oct 30, 2024
72e8607
small update to requirements and pyproject.toml
julius-heitkoetter Oct 30, 2024
2c159a9
updating cli code to use local image builds with updated code when rerun
julius-heitkoetter Oct 30, 2024
6c4d130
changing configurations such that user configuration is override of w…
julius-heitkoetter Oct 30, 2024
1097092
adding cli documentation
julius-heitkoetter Oct 30, 2024
af44639
changing pyproject to be lightweight
julius-heitkoetter Oct 30, 2024
f2f4ea9
requirements.txt
julius-heitkoetter Oct 30, 2024
157a95d
catching up 801
Oct 30, 2024
5f00e0c
Merge pull request #175 from mit-submit/release-8.01
pmlugato Oct 30, 2024
fef33b2
Merge pull request #176 from mit-submit/staging/801_to_cleanup
pmlugato Oct 30, 2024
77af384
adding uploader service and more documentation
julius-heitkoetter Oct 30, 2024
494ab39
Merge branch 'cleanup/october_merge' of https://github.com/mit-submit…
julius-heitkoetter Oct 30, 2024
498f473
migrating anthropic functionality to cleanup
Oct 30, 2024
47637c5
new langchain new requirements
Oct 30, 2024
5568659
anthropic for base compose and config
Oct 30, 2024
f105d59
adding ability to specify which port things are being run on
julius-heitkoetter Oct 31, 2024
9f3a0c0
little updates and configs folder
Oct 31, 2024
8b9ddf6
bug fixes
Nov 1, 2024
369b122
8511 intitial stuff
Nov 1, 2024
7a16ed3
resolving merge conflicts between feature/login_branch and october merge
julius-heitkoetter Nov 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .github/workflows/dev-ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- feature/login_page
jobs:
deploy-dev-system:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -45,12 +46,18 @@ jobs:
/bin/bash ${workspace}/deploy/create_secret.sh sender_replyto.txt ${{ secrets.DEV_SENDER_REPLYTO }}
/bin/bash ${workspace}/deploy/create_secret.sh sender_user.txt ${{ secrets.DEV_SENDER_USER }}
/bin/bash ${workspace}/deploy/create_secret.sh sender_pw.txt ${{ secrets.DEV_SENDER_PW }}
/bin/bash ${workspace}/deploy/create_secret.sh flask_uploader_app_secret_key.txt ${{ secrets.DEV_FLASK_UPLOADER_APP_SECRET_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh flask_app_secret_key.txt ${{ secrets.DEV_FLASK_APP_SECRET_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh uploader_salt.txt ${{ secrets.DEV_UPLOADER_SALT }}
/bin/bash ${workspace}/deploy/create_secret.sh openai_api_key.txt ${{ secrets.OPENAI_API_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh hf_token.txt ${{ secrets.HF_TOKEN }}
/bin/bash ${workspace}/deploy/create_secret.sh pg_password.txt ${{ secrets.DEV_PG_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh grafana_password.txt ${{ secrets.DEV_GRAFANA_PG_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate_key.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_id.txt ${{ secrets.DEV_MIT_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_secret.txt ${{ secrets.DEV_MIT_CLIENT_SECRET }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_id.txt ${{ secrets.DEV_GOOGLE_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_secret.txt ${{ secrets.DEV_GOOGLE_CLIENT_SECRET }}

# create env file to set tag(s) for docker-compose
- name: Create Env File
Expand All @@ -63,25 +70,25 @@ jobs:
# create deployment directory if it doesn't already exist
- name: Create Directory
run: |
ssh submit06 "mkdir -p ~/A2rchi-dev/"
ssh submit-t3desk "mkdir -p ~/A2rchi-dev/"

# stop any existing docker compose that's running
- name: Stop Docker Compose
run: |
ssh submit06 'bash -s' < ${{ github.workspace }}/deploy/dev/dev-stop.sh
ssh submit-t3desk 'bash -s' < ${{ github.workspace }}/deploy/dev/dev-stop.sh

# copy repository to machine
- name: Copy Repository
run: |
rsync -e ssh -r ${{ github.workspace}}/* --exclude .git/ --delete submit06:~/A2rchi-dev/
rsync -e ssh -r ${{ github.workspace}}/* --exclude .git/ --delete submit-t3desk:~/A2rchi-dev/

# run deploy script
- name: Run Deploy Script
run: |
export tag="${GITHUB_REF#refs/heads/}"
export tag="${tag//\//-}.${GITHUB_SHA}"
sed -i "s/BASE_TAG/${tag}/" ${{ github.workspace }}/deploy/dev/dev-install.sh
ssh submit06 'bash -s' < ${{ github.workspace }}/deploy/dev/dev-install.sh
ssh submit-t3desk 'bash -s' < ${{ github.workspace }}/deploy/dev/dev-install.sh

# clean up secret files
- name: Remove Secrets from Runner
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/prod-801-ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ jobs:
/bin/bash ${workspace}/deploy/create_secret.sh hf_token.txt ${{ secrets.HF_TOKEN }}
/bin/bash ${workspace}/deploy/create_secret.sh pg_password.txt ${{ secrets.PROD_801_PG_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh grafana_password.txt ${{ secrets.PROD_801_GRAFANA_PG_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate_key.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_id.txt ${{ secrets.DEV_MIT_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_secret.txt ${{ secrets.DEV_MIT_CLIENT_SECRET }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_id.txt ${{ secrets.DEV_GOOGLE_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_secret.txt ${{ secrets.DEV_GOOGLE_CLIENT_SECRET }}
/bin/bash ${workspace}/deploy/create_secret.sh piazza_email.txt ${{ secrets.PROD_801_PIAZZA_EMAIL }}
/bin/bash ${workspace}/deploy/create_secret.sh piazza_password.txt ${{ secrets.PROD_801_PIAZZA_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh slack_webhook.txt ${{ secrets.PROD_801_SLACK_WEBHOOK }}

# create env file to set tag(s) for docker-compose
- name: Create Env File
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/prod-ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ jobs:
/bin/bash ${workspace}/deploy/create_secret.sh hf_token.txt ${{ secrets.HF_TOKEN }}
/bin/bash ${workspace}/deploy/create_secret.sh pg_password.txt ${{ secrets.PROD_PG_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh grafana_password.txt ${{ secrets.PROD_GRAFANA_PG_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate_key.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_id.txt ${{ secrets.DEV_MIT_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_secret.txt ${{ secrets.DEV_MIT_CLIENT_SECRET }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_id.txt ${{ secrets.DEV_GOOGLE_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_secret.txt ${{ secrets.DEV_GOOGLE_CLIENT_SECRET }}

# create env file to set tag(s) for docker-compose
- name: Create Env File
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/prod-meta-ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ jobs:
/bin/bash ${workspace}/deploy/create_secret.sh uploader_salt.txt ${{ secrets.PROD_UPLOADER_SALT }}
/bin/bash ${workspace}/deploy/create_secret.sh openai_api_key.txt ${{ secrets.OPENAI_API_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh hf_token.txt ${{ secrets.HF_TOKEN }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate_key.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_id.txt ${{ secrets.DEV_MIT_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_secret.txt ${{ secrets.DEV_MIT_CLIENT_SECRET }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_id.txt ${{ secrets.DEV_GOOGLE_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_secret.txt ${{ secrets.DEV_GOOGLE_CLIENT_SECRET }}

# create env file to set tag(s) for docker-compose
- name: Create Env File
Expand Down
17 changes: 12 additions & 5 deletions .github/workflows/prod-root-ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ jobs:
/bin/bash ${workspace}/deploy/create_secret.sh flask_uploader_app_secret_key.txt ${{ secrets.PROD_FLASK_UPLOADER_APP_SECRET_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh uploader_salt.txt ${{ secrets.PROD_UPLOADER_SALT }}
/bin/bash ${workspace}/deploy/create_secret.sh openai_api_key.txt ${{ secrets.OPENAI_API_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh anthropic_api_key.txt ${{ secrets.ANTHROPIC_API_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh hf_token.txt ${{ secrets.HF_TOKEN }}
/bin/bash ${workspace}/deploy/create_secret.sh pg_password.txt ${{ secrets.PROD_ROOT_PG_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh grafana_password.txt ${{ secrets.PROD_ROOT_GRAFANA_PG_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate_key.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_id.txt ${{ secrets.DEV_MIT_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_secret.txt ${{ secrets.DEV_MIT_CLIENT_SECRET }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_id.txt ${{ secrets.DEV_GOOGLE_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_secret.txt ${{ secrets.DEV_GOOGLE_CLIENT_SECRET }}

# create env file to set tag(s) for docker-compose
- name: Create Env File
Expand All @@ -52,30 +59,30 @@ jobs:
# create deployment directory if it doesn't already exist
- name: Create Directory
run: |
ssh submit06 "mkdir -p ~/A2rchi-prod-root/"
ssh submit-t3desk018 "mkdir -p ~/A2rchi-prod-root/"

# stop any existing docker compose that's running
- name: Stop Docker Compose
run: |
ssh submit06 'bash -s' < ${{ github.workspace }}/deploy/prod-root/prod-root-stop.sh
ssh submit-t3desk018 'bash -s' < ${{ github.workspace }}/deploy/prod-root/prod-root-stop.sh

# copy repository to machine
- name: Copy Repository
run: |
rsync -e ssh -r ${{ github.workspace}}/* --exclude .git/ --delete submit06:~/A2rchi-prod-root/
rsync -e ssh -r ${{ github.workspace}}/* --exclude .git/ --delete submit-t3desk018:~/A2rchi-prod-root/

# run deploy script
- name: Run Deploy Script
run: |
export tag="${GITHUB_REF#refs/heads/}"
export tag="${tag//\//-}.${GITHUB_SHA}"
sed -i "s/BASE_TAG/${tag}/" ${{ github.workspace }}/deploy/prod-root/prod-root-install.sh
ssh submit06 'bash -s' < ${{ github.workspace }}/deploy/prod-root/prod-root-install.sh
ssh submit-t3desk018 'bash -s' < ${{ github.workspace }}/deploy/prod-root/prod-root-install.sh

# clean up secret files
- name: Remove Secrets from Runner
run: |
rm ${{ github.workspace }}/deploy/prod-root/secrets/*.txt

# print job status
- run: echo "🍏 This job's status is ${{ job.status }}."
- run: echo "🍏 This job's status is ${{ job.status }}."
79 changes: 73 additions & 6 deletions a2rchi/bin/service_chat.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
#!/bin/python

from a2rchi.interfaces.chat_app.app import FlaskAppWrapper
from a2rchi.interfaces.chat_app.user import User
from a2rchi.utils.config_loader import Config_Loader
from a2rchi.utils.env import read_secret

from flask import Flask
from flask_login import LoginManager
import tempfile

global_config = Config_Loader().config["global"]
app_config = Config_Loader().config["interfaces"]["chat_app"]

import os
import sqlite3

# set openai
os.environ['ANTHROPIC_API_KEY'] = read_secret("ANTHROPIC_API_KEY")
os.environ['OPENAI_API_KEY'] = read_secret("OPENAI_API_KEY")
os.environ['HUGGING_FACE_HUB_TOKEN'] = read_secret("HUGGING_FACE_HUB_TOKEN")

# database setup
print(f"Initializing database")
DB_PATH = os.path.join(global_config['DATA_PATH'], "flask_sqlite_db")

# read sql script
sql_script = None
with open(app_config['DB_INIT_SCRIPT'], 'r') as f:
sql_script = f.read()

# connect to db, create user table if it doesn't exist, and commit
db = sqlite3.connect(DB_PATH, detect_types=sqlite3.PARSE_DECLTYPES)
cursor = db.cursor()
cursor.executescript(sql_script)
db.commit()
cursor.close()
db.close()

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']})")
print(f"Accessible externally at (host, port): ({config['HOSTNAME']}, {config['EXTERNAL_PORT']})")

def generate_script(config):
"""
Expand All @@ -33,10 +61,49 @@ def generate_script(config):

return

generate_script(config)
app = FlaskAppWrapper(Flask(
# fill in template variables for front-end JS
generate_script(app_config)

# initialize app object
print("Initializing flask app")
app = Flask(
__name__,
template_folder=config["template_folder"],
static_folder=config["static_folder"],
))
app.run(debug=True, port=config["PORT"], host=config["HOST"])
template_folder=app_config["template_folder"],
static_folder=app_config["static_folder"],
)

# User session management setup: https://flask-login.readthedocs.io/en/latest
print("Setting up login manager")
login_manager = LoginManager()
login_manager.init_app(app)

# Flask-Login helper to retrieve a user from our db
@login_manager.user_loader
def load_user(user_id):
return User.get(user_id)

# start app
print(f"Starting Chat Service with (host, port): ({app_config['HOST']}, {app_config['PORT']})")
app = FlaskAppWrapper(app)
if False: #app_config["HOSTNAME"] == "a2rchi.mit.edu":

print("Adding SSL certificates for a2rchi.mit.edu")

#get the ssl cert and key and save them to temporary files
ssl_cert = read_secret("A2RCHI_SSL_CERTIFICATE")
ssl_key = read_secret("A2RCHI_SSL_CERTIFICATE_KEY")
cert_file = tempfile.NamedTemporaryFile(delete=False)
key_file = tempfile.NamedTemporaryFile(delete=False)
cert_file.write(ssl_cert.encode())
key_file.write(ssl_key.encode())

app.run(debug=True, port=app_config["PORT"], host=app_config["HOST"], ssl_context=(cert_file.name, key_file.name))

#remove the temp ssl cert and key temp files
os.unlink(cert_file.name)
os.unlink(key_file.name)

else:

print("No SSL certificate for this server found. Starting up with adhoc SSL certification")
app.run(debug=True, port=app_config["PORT"], host=app_config["HOST"], ssl_context="adhoc")
1 change: 1 addition & 0 deletions a2rchi/bin/service_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


# set openai
os.environ['ANTHROPIC_API_KEY'] = read_secret("ANTHROPIC_API_KEY")
os.environ['OPENAI_API_KEY'] = read_secret("OPENAI_API_KEY")
os.environ['HUGGING_FACE_HUB_TOKEN'] = read_secret("HUGGING_FACE_HUB_TOKEN")

Expand Down
31 changes: 19 additions & 12 deletions a2rchi/chains/base.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
"""Chain for chatting with a vector database."""
from __future__ import annotations
from pydantic import BaseModel
from loguru import logger
from langchain.callbacks import FileCallbackHandler
from langchain_core.callbacks.file import FileCallbackHandler

from a2rchi.chains.prompts import CONDENSE_QUESTION_PROMPT, QA_PROMPT
from a2rchi.chains.prompts import CONDENSE_QUESTION_PROMPT, QA_PROMPT #SUMMARY_PROMPT
from a2rchi.utils.config_loader import Config_Loader

from langchain.base_language import BaseLanguageModel
from langchain.chains.combine_documents.stuff import StuffDocumentsChain
from langchain_core.language_models.base import BaseLanguageModel
from langchain.chains.combine_documents.stuff import StuffDocumentsChain # deprecated, should update
from langchain.chains.conversational_retrieval.base import BaseConversationalRetrievalChain
from langchain.chains.llm import LLMChain
from langchain.schema import BaseRetriever, Document
from langchain.schema.prompt_template import BasePromptTemplate
from langchain.chains.llm import LLMChain # deprecated, should update
from langchain_core.retrievers import BaseRetriever
from langchain_core.documents import Document
from langchain_core.prompts.base import BasePromptTemplate
from langchain_core.runnables import RunnableSequence, RunnablePassthrough
from typing import Any, Dict, List, Optional, Tuple
from typing import Callable
import os


Expand Down Expand Up @@ -46,7 +50,7 @@ class BaseSubMITChain(BaseConversationalRetrievalChain):
"""
retriever: BaseRetriever # Index to connect to
max_tokens_limit: Optional[int] = None # restrict doc length to return from store, enforced only for StuffDocumentChain
get_chat_history: Optional[function] = _get_chat_history
get_chat_history: Optional[Callable[[List[Tuple[str, str]]], str]] = _get_chat_history

def _reduce_tokens_below_limit(self, docs: List[Document]) -> List[Document]:
num_docs = len(docs)
Expand Down Expand Up @@ -81,22 +85,25 @@ def from_llm(
cls,
llm: BaseLanguageModel,
retriever: BaseRetriever,
qa_prompt: BasePromptTemplate = QA_PROMPT,
condense_question_prompt: BasePromptTemplate = CONDENSE_QUESTION_PROMPT,
summary_prompt: BasePromptTemplate = CONDENSE_QUESTION_PROMPT,
chain_type: str = "stuff",
verbose: bool = False,
condense_question_llm: Optional[BaseLanguageModel] = None,
summary_llm: Optional[BaseLanguageModel] = None,
combine_docs_chain_kwargs: Optional[Dict] = None,
**kwargs: Any,
) -> BaseConversationalRetrievalChain:
# Load chain from LLM
combine_docs_chain_kwargs = combine_docs_chain_kwargs or {}
_prompt = QA_PROMPT
_prompt = qa_prompt
document_variable_name = "context"

#Add logger for storing input to the QA chain, ie filled QA template
logfile = os.path.join(data_path,config["logging"]["input_output_filename"])
logfile = os.path.join(data_path, config["logging"]["input_output_filename"])
logger.add(logfile, colorize=True, enqueue=True)
handler = FileCallbackHandler(logfile)
handler = FileCallbackHandler(logfile)

llm_chain = LLMChain(
llm=llm,
Expand All @@ -121,4 +128,4 @@ def from_llm(
question_generator=condense_question_chain,
**kwargs,
)


Loading
Loading