mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-08 04:25:46 +00:00
community: Remove all other keys in ChatLiteLLM and add api_key (#28097)
Thank you for contributing to LangChain! - **PR title**: "community: Remove all other keys in ChatLiteLLM and add api_key" - **PR message**: Currently, no api_key are passed to LiteLLM, and LiteLLM only takes on api_key parameter. Therefore I removed all current `*_api_key` attributes (They are not used), and added `api_key` that is passed to ChatLiteLLM. - Should fix issue #27826 --------- Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
parent
d5d18c62b3
commit
169d419581
@ -253,6 +253,7 @@ class ChatLiteLLM(BaseChatModel):
|
|||||||
replicate_api_key: Optional[str] = None
|
replicate_api_key: Optional[str] = None
|
||||||
cohere_api_key: Optional[str] = None
|
cohere_api_key: Optional[str] = None
|
||||||
openrouter_api_key: Optional[str] = None
|
openrouter_api_key: Optional[str] = None
|
||||||
|
api_key: Optional[str] = None
|
||||||
streaming: bool = False
|
streaming: bool = False
|
||||||
api_base: Optional[str] = None
|
api_base: Optional[str] = None
|
||||||
organization: Optional[str] = None
|
organization: Optional[str] = None
|
||||||
@ -299,6 +300,21 @@ class ChatLiteLLM(BaseChatModel):
|
|||||||
if self.model_name is not None:
|
if self.model_name is not None:
|
||||||
set_model_value = self.model_name
|
set_model_value = self.model_name
|
||||||
self.client.api_base = self.api_base
|
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
|
self.client.organization = self.organization
|
||||||
creds: Dict[str, Any] = {
|
creds: Dict[str, Any] = {
|
||||||
"model": set_model_value,
|
"model": set_model_value,
|
||||||
|
Loading…
Reference in New Issue
Block a user