The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
community: Remove all other keys in ChatLiteLLM and add api_key (#28097)
chenzimin169d4195814f
diff --git a/libs/community/langchain_community/chat_models/litellm.py b/libs/community/langchain_community/chat_models/litellm.pyindex 83c3020910..d836a9d02f 100644--- a/libs/community/langchain_community/chat_models/litellm.py+++ b/libs/community/langchain_community/chat_models/litellm.py@@ -253,6 +253,7 @@ class ChatLiteLLM(BaseChatModel):replicate_api_key: Optional[str] = Nonecohere_api_key: Optional[str] = Noneopenrouter_api_key: Optional[str] = None+ api_key: Optional[str] = Nonestreaming: bool = Falseapi_base: Optional[str] = Noneorganization: Optional[str] = None@@ -299,6 +300,21 @@ class ChatLiteLLM(BaseChatModel):if self.model_name is not None:set_model_value = self.model_nameself.client.api_base = self.api_base+ self.client.api_key = self.api_key+ for named_api_key in [+ "openai_api_key",+ "azure_api_key",+ "anthropic_api_key",+ "replicate_api_key",+ "cohere_api_key",+ "openrouter_api_key",+ ]:+ if api_key_value := getattr(self, named_api_key):+ setattr(+ self.client,+ named_api_key.replace("_api_key", "_key"),+ api_key_value,+ )self.client.organization = self.organizationcreds: Dict[str, Any] = {"model": set_model_value,