Skip to content

Commit aade9bf

Browse files
onesolparkccurme
andauthored
Mask API key for ChatOpenAI based chat_models (#14293)
- **Description**: Mask API key for ChatOpenAi based chat_models (openai, azureopenai, anyscale, everlyai). Made changes to all chat_models that are based on ChatOpenAI since all of them assumes that openai_api_key is str rather than SecretStr. - **Issue:**: #12165 - **Dependencies:** N/A - **Tag maintainer:** @eyurtsev - **Twitter handle:** N/A --------- Co-authored-by: Chester Curme <[email protected]>
1 parent 0ee6ed7 commit aade9bf

File tree

1 file changed

+7
-5
lines changed
  • libs/community/langchain_community/chat_models

1 file changed

+7
-5
lines changed

libs/community/langchain_community/chat_models/everlyai.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from langchain_core.messages import BaseMessage
1010
from langchain_core.pydantic_v1 import Field, root_validator
11-
from langchain_core.utils import get_from_dict_or_env
11+
from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env
1212

1313
from langchain_community.adapters.openai import convert_message_to_dict
1414
from langchain_community.chat_models.openai import (
@@ -79,10 +79,12 @@ def get_available_models() -> Set[str]:
7979
@root_validator(pre=True)
8080
def validate_environment_override(cls, values: dict) -> dict:
8181
"""Validate that api key and python package exists in environment."""
82-
values["openai_api_key"] = get_from_dict_or_env(
83-
values,
84-
"everlyai_api_key",
85-
"EVERLYAI_API_KEY",
82+
values["openai_api_key"] = convert_to_secret_str(
83+
get_from_dict_or_env(
84+
values,
85+
"everlyai_api_key",
86+
"EVERLYAI_API_KEY",
87+
)
8688
)
8789
values["openai_api_base"] = DEFAULT_API_BASE
8890

0 commit comments

Comments
 (0)