mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-12 06:13:36 +00:00
Fix MoonshotChat instantiate with alias (#25755)
- **Description:** - Fix `MoonshotChat` instantiate with alias - Add `MoonshotChat` to `__init__.py` --------- Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
parent
ec99f0d193
commit
a566a15930
@ -122,6 +122,9 @@ if TYPE_CHECKING:
|
|||||||
from langchain_community.chat_models.mlx import (
|
from langchain_community.chat_models.mlx import (
|
||||||
ChatMLX,
|
ChatMLX,
|
||||||
)
|
)
|
||||||
|
from langchain_community.chat_models.moonshot import (
|
||||||
|
MoonshotChat,
|
||||||
|
)
|
||||||
from langchain_community.chat_models.oci_generative_ai import (
|
from langchain_community.chat_models.oci_generative_ai import (
|
||||||
ChatOCIGenAI, # noqa: F401
|
ChatOCIGenAI, # noqa: F401
|
||||||
)
|
)
|
||||||
@ -224,6 +227,7 @@ __all__ = [
|
|||||||
"JinaChat",
|
"JinaChat",
|
||||||
"LlamaEdgeChatService",
|
"LlamaEdgeChatService",
|
||||||
"MiniMaxChat",
|
"MiniMaxChat",
|
||||||
|
"MoonshotChat",
|
||||||
"PaiEasChatEndpoint",
|
"PaiEasChatEndpoint",
|
||||||
"PromptLayerChatOpenAI",
|
"PromptLayerChatOpenAI",
|
||||||
"QianfanChatEndpoint",
|
"QianfanChatEndpoint",
|
||||||
@ -280,6 +284,7 @@ _module_lookup = {
|
|||||||
"JinaChat": "langchain_community.chat_models.jinachat",
|
"JinaChat": "langchain_community.chat_models.jinachat",
|
||||||
"LlamaEdgeChatService": "langchain_community.chat_models.llama_edge",
|
"LlamaEdgeChatService": "langchain_community.chat_models.llama_edge",
|
||||||
"MiniMaxChat": "langchain_community.chat_models.minimax",
|
"MiniMaxChat": "langchain_community.chat_models.minimax",
|
||||||
|
"MoonshotChat": "langchain_community.chat_models.moonshot",
|
||||||
"PaiEasChatEndpoint": "langchain_community.chat_models.pai_eas_endpoint",
|
"PaiEasChatEndpoint": "langchain_community.chat_models.pai_eas_endpoint",
|
||||||
"PromptLayerChatOpenAI": "langchain_community.chat_models.promptlayer_openai",
|
"PromptLayerChatOpenAI": "langchain_community.chat_models.promptlayer_openai",
|
||||||
"SolarChat": "langchain_community.chat_models.solar",
|
"SolarChat": "langchain_community.chat_models.solar",
|
||||||
|
@ -33,7 +33,11 @@ class MoonshotChat(MoonshotCommon, ChatOpenAI): # type: ignore[misc]
|
|||||||
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"] = convert_to_secret_str(
|
values["moonshot_api_key"] = convert_to_secret_str(
|
||||||
get_from_dict_or_env(values, "moonshot_api_key", "MOONSHOT_API_KEY")
|
get_from_dict_or_env(
|
||||||
|
values,
|
||||||
|
["moonshot_api_key", "api_key", "openai_api_key"],
|
||||||
|
"MOONSHOT_API_KEY",
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
"""Test Moonshot Chat Model."""
|
"""Test Moonshot Chat Model."""
|
||||||
|
|
||||||
from typing import Type
|
from typing import Type, cast
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from langchain_core.language_models import BaseChatModel
|
from langchain_core.language_models import BaseChatModel
|
||||||
|
from langchain_core.pydantic_v1 import SecretStr
|
||||||
from langchain_standard_tests.integration_tests import ChatModelIntegrationTests
|
from langchain_standard_tests.integration_tests import ChatModelIntegrationTests
|
||||||
|
|
||||||
from langchain_community.chat_models.moonshot import MoonshotChat
|
from langchain_community.chat_models.moonshot import MoonshotChat
|
||||||
@ -21,3 +22,10 @@ class TestMoonshotChat(ChatModelIntegrationTests):
|
|||||||
@pytest.mark.xfail(reason="Not yet implemented.")
|
@pytest.mark.xfail(reason="Not yet implemented.")
|
||||||
def test_usage_metadata(self, model: BaseChatModel) -> None:
|
def test_usage_metadata(self, model: BaseChatModel) -> None:
|
||||||
super().test_usage_metadata(model)
|
super().test_usage_metadata(model)
|
||||||
|
|
||||||
|
|
||||||
|
def test_chat_moonshot_instantiate_with_alias() -> None:
|
||||||
|
"""Test MoonshotChat instantiate when using alias."""
|
||||||
|
api_key = "your-api-key"
|
||||||
|
chat = MoonshotChat(api_key=api_key) # type: ignore[call-arg]
|
||||||
|
assert cast(SecretStr, chat.moonshot_api_key).get_secret_value() == api_key
|
||||||
|
@ -48,6 +48,7 @@ EXPECTED_ALL = [
|
|||||||
"JinaChat",
|
"JinaChat",
|
||||||
"LlamaEdgeChatService",
|
"LlamaEdgeChatService",
|
||||||
"MiniMaxChat",
|
"MiniMaxChat",
|
||||||
|
"MoonshotChat",
|
||||||
"PaiEasChatEndpoint",
|
"PaiEasChatEndpoint",
|
||||||
"PromptLayerChatOpenAI",
|
"PromptLayerChatOpenAI",
|
||||||
"SolarChat",
|
"SolarChat",
|
||||||
|
Loading…
Reference in New Issue
Block a user