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

community: Remove all other keys in ChatLiteLLM and add api_key #28097

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions libs/community/langchain_community/chat_models/litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class ChatLiteLLM(BaseChatModel):
replicate_api_key: Optional[str] = None
cohere_api_key: Optional[str] = None
openrouter_api_key: Optional[str] = None
api_key: Optional[str] = None
streaming: bool = False
api_base: Optional[str] = None
organization: Optional[str] = None
Expand Down Expand Up @@ -271,6 +272,21 @@ def _client_params(self) -> Dict[str, Any]:
if self.model_name is not None:
set_model_value = self.model_name
self.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.organization
creds: Dict[str, Any] = {
"model": set_model_value,
Expand Down
Loading