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

Bug fix tongyi.py to be compatible with DashScope API #11956

Merged
merged 3 commits into from
Oct 20, 2023
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
9 changes: 8 additions & 1 deletion libs/langchain/langchain/chat_models/tongyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,14 @@ def _generate(
)
return _generate_from_stream(stream_iter)

if not messages:
raise ValueError("No messages provided.")

message_dicts, params = self._create_message_dicts(messages, stop)

if message_dicts[-1]["role"] != "user":
raise ValueError("Last message should be user message.")

params = {**params, **kwargs}
response = self.completion_with_retry(
messages=message_dicts, run_manager=run_manager, **params
Expand Down Expand Up @@ -374,7 +381,7 @@ def _create_message_dicts(
def _client_params(self) -> Dict[str, Any]:
"""Get the parameters used for the openai client."""
creds: Dict[str, Any] = {
"dashscope_api_key": self.dashscope_api_key,
"api_key": self.dashscope_api_key,
}
return {**self._default_params, **creds}

Expand Down