1212
1313# Provider-specific package mapping
1414PROVIDER_PACKAGES = {
15- # "Anthropic": "langchain_anthropic", # Special handling for Anthropic with Pydantic v2
15+ "Anthropic" : "langchain_anthropic" ,
1616 "MistralAI" : "langchain_mistralai" ,
1717 "Fireworks" : "langchain_fireworks" ,
1818 "AzureOpenAI" : "langchain_openai" ,
@@ -135,18 +135,25 @@ def __init__(self, config: Optional[BaseLlmConfig] = None):
135135 try :
136136 # Check if this provider needs a specialized package
137137 if provider in PROVIDER_PACKAGES :
138- package_name = PROVIDER_PACKAGES [provider ]
139- try :
140- # Import the model class directly from the package
141- module_path = f"{ package_name } "
142- model_class = __import__ (module_path , fromlist = [model_name ])
143- model_class = getattr (model_class , model_name )
144- except ImportError :
145- raise ImportError (
146- f"Package { package_name } not found. " f"Please install it with `pip install { package_name } `"
147- )
148- except AttributeError :
149- raise ImportError (f"Model { model_name } not found in { package_name } " )
138+ if provider == "Anthropic" : # Special handling for Anthropic with Pydantic v2
139+ try :
140+ from langchain_anthropic import ChatAnthropic
141+ model_class = ChatAnthropic
142+ except ImportError :
143+ raise ImportError ("langchain_anthropic not found. Please install it with `pip install langchain-anthropic`" )
144+ else :
145+ package_name = PROVIDER_PACKAGES [provider ]
146+ try :
147+ # Import the model class directly from the package
148+ module_path = f"{ package_name } "
149+ model_class = __import__ (module_path , fromlist = [model_name ])
150+ model_class = getattr (model_class , model_name )
151+ except ImportError :
152+ raise ImportError (
153+ f"Package { package_name } not found. " f"Please install it with `pip install { package_name } `"
154+ )
155+ except AttributeError :
156+ raise ImportError (f"Model { model_name } not found in { package_name } " )
150157 else :
151158 # Use the default langchain_community module
152159 if not hasattr (chat_models , model_name ):
@@ -158,8 +165,7 @@ def __init__(self, config: Optional[BaseLlmConfig] = None):
158165 self .langchain_model = model_class (
159166 model = self .config .model ,
160167 temperature = self .config .temperature ,
161- max_tokens = self .config .max_tokens ,
162- api_key = self .config .api_key ,
168+ max_tokens = self .config .max_tokens
163169 )
164170 except (ImportError , AttributeError , ValueError ) as e :
165171 raise ImportError (f"Error setting up langchain model for provider { provider } : { str (e )} " )
0 commit comments