fix: MoonshotChat fails when setting the moonshot_api_key through the OS environment. (#23176)

Close #23174

Co-authored-by: tianming <tianming@bytenew.com>
pull/23185/head
chenxi 3 months ago committed by GitHub
parent 677408bfc9
commit 505a2e8743
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2,7 +2,10 @@
from typing import Dict
from langchain_core.pydantic_v1 import root_validator
from langchain_core.utils import get_from_dict_or_env
from langchain_core.utils import (
convert_to_secret_str,
get_from_dict_or_env,
)
from langchain_community.chat_models import ChatOpenAI
from langchain_community.llms.moonshot import MOONSHOT_SERVICE_URL_BASE, MoonshotCommon
@ -28,8 +31,8 @@ class MoonshotChat(MoonshotCommon, ChatOpenAI): # type: ignore[misc]
@root_validator()
def validate_environment(cls, values: Dict) -> Dict:
"""Validate that the environment is set up correctly."""
values["moonshot_api_key"] = get_from_dict_or_env(
values, "moonshot_api_key", "MOONSHOT_API_KEY"
values["moonshot_api_key"] = convert_to_secret_str(
get_from_dict_or_env(values, "moonshot_api_key", "MOONSHOT_API_KEY")
)
try:

Loading…
Cancel
Save