Skip to content

Commit

Permalink
✨ Added support for Anthropic, updated to latest langchain 0.3.7;
Browse files Browse the repository at this point in the history
  • Loading branch information
danpe committed Nov 16, 2024
1 parent e67372c commit 889d7f1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/config_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ eval:
error_threshold: 0.5

llm:
type: 'OpenAI'
name: 'gpt-4-1106-preview' # This is the meta-prompt LLM, it should be a strong model. For example, using GPT-3.5 will cause an error in many cases.
type: 'OpenAI' # Can be OpenAI, Anthropic, Google, Azure
temperature: 0.8

stop_criteria:
Expand Down
2 changes: 2 additions & 0 deletions config/llm_env.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
anthropic:
ANTHROPIC_API_KEY: ''
openai:
OPENAI_API_KEY: ''
OPENAI_API_BASE: ''
Expand Down
4 changes: 2 additions & 2 deletions environment_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies:
- python=3.10.13
- pip>=2.22.0
- openai
- anthropic
- langchain
- pandas
- wandb
Expand All @@ -19,5 +20,4 @@ dependencies:
- schedule
- pandas
- easydict
- pillow==10.2.0
- langchain-google-genai==0.0.9
- pillow==10.2.0
13 changes: 9 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ schedule==1.2.1
pandas==1.5.3
tqdm==4.66.1
prodict==0.8.18
langchain==0.1.9
openai==1.1.0
langchain==0.3.7
openai==1.54.4
anthropic==0.39.0
tiktoken==0.5.1
easydict==1.11
wandb==0.16.0
wandb==0.18.7
transformers==4.35.2
scikit-learn==1.3.2
faiss-cpu==1.7.4
sentence-transformers==2.2.2
langchain-google-genai==0.0.9
langchain-core==0.3.18
langchain-openai==0.2.8
langchain-anthropic==0.3.0
langchain-community==0.3.7
langchain-google-genai==2.0.4
pillow==10.2.0
6 changes: 6 additions & 0 deletions utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def get_llm(config: dict):
return ChatGoogleGenerativeAI(temperature=temperature, model=config['name'],
google_api_key=LLM_ENV['google']['GOOGLE_API_KEY'],
model_kwargs=model_kwargs)

elif config['type'].lower() == 'anthropic':
from langchain_anthropic import ChatAnthropic
return ChatAnthropic(temperature=temperature, model=config['name'],
api_key=LLM_ENV['anthropic']['ANTHROPIC_API_KEY'],
model_kwargs=model_kwargs)


elif config['type'].lower() == 'huggingfacepipeline':
Expand Down
4 changes: 2 additions & 2 deletions utils/llm_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def build_chain(self):
"""
Build the chain according to the LLM type
"""
if (self.llm_config.type.lower() == 'openai' or self.llm_config.type.lower() == 'azure') and self.json_schema is not None:
self.chain = create_structured_output_runnable(self.json_schema, self.llm, self.prompt)
if (self.llm_config.type.lower() in ['openai', 'azure', 'anthropic']) and self.json_schema is not None:
self.chain = self.prompt | self.llm.with_structured_output(self.json_schema)
else:
self.chain = LLMChain(llm=self.llm, prompt=self.prompt)

Expand Down

0 comments on commit 889d7f1

Please sign in to comment.