mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-22 06:39:52 +00:00
fix: MoonshotChat fails when setting the moonshot_api_key through the OS environment. (#23176)
Close #23174 Co-authored-by: tianming <tianming@bytenew.com>
This commit is contained in:
parent
677408bfc9
commit
505a2e8743
@ -2,7 +2,10 @@
|
|||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from langchain_core.pydantic_v1 import root_validator
|
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.chat_models import ChatOpenAI
|
||||||
from langchain_community.llms.moonshot import MOONSHOT_SERVICE_URL_BASE, MoonshotCommon
|
from langchain_community.llms.moonshot import MOONSHOT_SERVICE_URL_BASE, MoonshotCommon
|
||||||
@ -28,8 +31,8 @@ class MoonshotChat(MoonshotCommon, ChatOpenAI): # type: ignore[misc]
|
|||||||
@root_validator()
|
@root_validator()
|
||||||
def validate_environment(cls, values: Dict) -> Dict:
|
def validate_environment(cls, values: Dict) -> Dict:
|
||||||
"""Validate that the environment is set up correctly."""
|
"""Validate that the environment is set up correctly."""
|
||||||
values["moonshot_api_key"] = get_from_dict_or_env(
|
values["moonshot_api_key"] = convert_to_secret_str(
|
||||||
values, "moonshot_api_key", "MOONSHOT_API_KEY"
|
get_from_dict_or_env(values, "moonshot_api_key", "MOONSHOT_API_KEY")
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user