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

Update tongyi.py to support MultimodalConversation in dashscope. #21249

Merged
merged 7 commits into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 34 additions & 12 deletions libs/community/langchain_community/chat_models/tongyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,14 @@ def lc_secrets(self) -> Dict[str, str]:

client: Any #: :meta private:
model_name: str = Field(default="qwen-turbo", alias="model")

"""Model name to use."""
"""Model name to use.
callable multimodal model:
- qwen-vl-v1
- qwen-vl-chat-v1
- qwen-audio-turbo
- qwen-vl-plus
- qwen-vl-max
"""
model_kwargs: Dict[str, Any] = Field(default_factory=dict)

top_p: float = 0.8
Expand Down Expand Up @@ -280,18 +286,34 @@ def validate_environment(cls, values: Dict) -> Dict:
"Could not import dashscope python package. "
"Please install it with `pip install dashscope --upgrade`."
)
try:
if "vl" in values["model_name"]:
dashscope_multimodal_models = [
"qwen-vl-v1",
"qwen-vl-chat-v1",
"qwen-audio-turbo",
"qwen-vl-plus",
"qwen-vl-max",
]
if (
values["model_name"] in dashscope_multimodal_models
or "vl" in values["model_name"]
):
try:
values["client"] = dashscope.MultiModalConversation
else:
except AttributeError:
raise ValueError(
"`dashscope` has no `MultiModalConversation` attribute, this is "
"likely due to an old version of the dashscope package. Try "
"upgrading it with `pip install --upgrade dashscope`."
)
else:
try:
values["client"] = dashscope.Generation
except AttributeError:
raise ValueError(
"`dashscope` has no `Generation` attribute, this is likely "
"due to an old version of the dashscope package. Try upgrading it "
"with `pip install --upgrade dashscope`."
)

except AttributeError:
raise ValueError(
"`dashscope` has no `Generation` attribute, this is likely "
"due to an old version of the dashscope package. Try upgrading it "
"with `pip install --upgrade dashscope`."
)
return values

@property
Expand Down