Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tongyi[patch]: standardize init args #20210

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion libs/community/langchain_community/chat_models/tongyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def lc_secrets(self) -> Dict[str, str]:
top_p: float = 0.8
"""Total probability mass of tokens to consider at each step."""

dashscope_api_key: Optional[SecretStr] = None
dashscope_api_key: Optional[SecretStr] = Field(None, alias="api_key")
liugddx marked this conversation as resolved.
Show resolved Hide resolved
"""Dashscope api key provide by Alibaba Cloud."""

streaming: bool = False
Expand All @@ -167,6 +167,11 @@ def lc_secrets(self) -> Dict[str, str]:
max_retries: int = 10
"""Maximum number of retries to make when generating."""

class Config:
"""Configuration for this pydantic object."""

allow_population_by_field_name = True

@property
def _llm_type(self) -> str:
"""Return type of llm."""
Expand Down
11 changes: 11 additions & 0 deletions libs/community/tests/integration_tests/chat_models/test_tongyi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test Alibaba Tongyi Chat Model."""
from typing import cast

from langchain_core.callbacks import CallbackManager
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage
Expand All @@ -10,6 +11,16 @@
from tests.unit_tests.callbacks.fake_callback_handler import FakeCallbackHandler


def test_initialization() -> None:
"""Test chat model initialization."""
for model in [
ChatTongyi(model_name="qwen-turbo", api_key="xyz"),
ChatTongyi(model="qwen-turbo", dashscope_api_key="xyz"),
]:
assert model.model_name == "qwen-turbo"
assert cast(SecretStr, model.dashscope_api_key).get_secret_value() == "xyz"


def test_api_key_is_string() -> None:
llm = ChatTongyi(dashscope_api_key="secret-api-key")
assert isinstance(llm.dashscope_api_key, SecretStr)
Expand Down
Loading