Skip to content

Commit

Permalink
Merge pull request #161 from mit-submit/development/anthropic_claude
Browse files Browse the repository at this point in the history
Adding Anthropic LLM
  • Loading branch information
pmlugato authored Aug 29, 2024
2 parents 91aaf55 + 194687d commit 148c6b5
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/prod-root-ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ 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 }}
Expand Down
1 change: 1 addition & 0 deletions a2rchi/bin/service_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os

# 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")
config = Config_Loader().config["interfaces"]["chat_app"]
Expand Down
2 changes: 2 additions & 0 deletions a2rchi/bin/service_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@


# 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
17 changes: 17 additions & 0 deletions a2rchi/chains/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from langchain.callbacks.manager import CallbackManagerForLLMRun
from langchain.llms.base import LLM
from langchain.chat_models import ChatOpenAI
from langchain.chat_models import ChatAnthropic
from langchain.llms import LlamaCpp

class BaseCustomLLM(LLM):
Expand Down Expand Up @@ -46,6 +47,22 @@ def _call(
time.sleep(sleep_time)
return "I am just a dumb LLM, I will give you a number: " + str(np.random.randint(10000, 99999))


class AnthropicLLM(ChatAnthropic):
"""
Loading Anthropic model from langchain package and specifying version. Options include:
model: str = "claude-3-opus-20240229"
model: str = "claude-3-sonnet-20240229"
Model comparison: https://docs.anthropic.com/en/docs/about-claude/models#model-comparison
"""

model: str = "claude-3-opus-20240229"

temp: int = 1



class LlamaLLM(BaseCustomLLM):
"""
Loading the Llama LLM from facebook. Make sure that the model
Expand Down
3 changes: 2 additions & 1 deletion a2rchi/utils/config_loader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from a2rchi.chains.models import OpenAILLM, DumbLLM, LlamaLLM
from a2rchi.chains.models import OpenAILLM, DumbLLM, LlamaLLM, AnthropicLLM

from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.embeddings import HuggingFaceEmbeddings
Expand All @@ -23,6 +23,7 @@ def load_config(self):

# change the model class parameter from a string to an actual class
MODEL_MAPPING = {
"AnthropicLLM": AnthropicLLM
"OpenAILLM": OpenAILLM,
"DumbLLM": DumbLLM,
"LlamaLLM": LlamaLLM
Expand Down
9 changes: 7 additions & 2 deletions config/prod-root-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ chains:
MAIN_PROMPT: config/prompts/root.prompt
chain:
# pick one of the models listed in the model class map below
MODEL_NAME: OpenAILLM
MODEL_NAME: AnthropicLLM
# map of all the class models and their keyword arguments
MODEL_CLASS_MAP:
AnthropicLLM:
class: AnthropicLLM
kwargs:
model_name: claude-3-opus-20240229
temperature: 1 # not sure if 1 is best value? for now keeping consistent with prior settings.
OpenAILLM:
class: OpenAILLM
kwargs:
Expand Down Expand Up @@ -120,4 +125,4 @@ utils:
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
enable_warnings: False # keeps output clean if verify == False
8 changes: 7 additions & 1 deletion deploy/prod-root/prod-root-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
chat:
image: chat-prod-root:${TAG}
image: chat-prod-root:${TAG}
build:
context: ../..
dockerfile: deploy/dockerfiles/Dockerfile-chat
Expand All @@ -14,10 +14,12 @@ services:
environment:
RUNTIME_ENV: prod-root
OPENAI_API_KEY_FILE: /run/secrets/openai_api_key
ANTHROPIC_API_KEY_FILE: /run/secrets/anthropic_api_key
HUGGING_FACE_HUB_TOKEN_FILE: /run/secrets/hf_token
POSTGRES_PASSWORD_FILE: /run/secrets/pg_password
secrets:
- openai_api_key
- anthropic_api_key
- hf_token
- pg_password
volumes:
Expand Down Expand Up @@ -46,10 +48,12 @@ services:
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
ANTHROPIC_API_KEY_FILE: /run/secrets/anthropic_api_key
HUGGING_FACE_HUB_TOKEN_FILE: /run/secrets/hf_token
secrets:
- flask_uploader_app_secret_key
- uploader_salt
- anthropic_api_key
- openai_api_key
- hf_token
ports:
Expand Down Expand Up @@ -141,6 +145,8 @@ secrets:
file: secrets/uploader_salt.txt
openai_api_key:
file: secrets/openai_api_key.txt
anthropic_api_key:
file: secrets/anthropic_api_key.txt
hf_token:
file: secrets/hf_token.txt
pg_password:
Expand Down
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ HERE=`pwd`
echo "# DO NOT EDIT !! THIS FILE IS GENERATED AT INSTALL (install.sh) !!
export A2RCHI_BASE=$HERE
export OPENAI_API_KEY=\`cat $HOME/.openai/api.key\`
export ANTHROPIC_API_KEY=\'cat $HOME/.claudeai/api.key\'
export PATH=\${PATH}:\${A2RCHI_BASE}/bin
export PYTHONPATH=\${PYTHONPATH}:\${A2RCHI_BASE}/chains:\${A2RCHI_BASE}/interfaces:\${A2RCHI_BASE}/utils
Expand Down

0 comments on commit 148c6b5

Please sign in to comment.