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

[HOTFIX] Fix the error when using multiple dashscope api keys #478

Merged
merged 4 commits into from
Nov 5, 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
2 changes: 1 addition & 1 deletion src/agentscope/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
""" Version of AgentScope."""

__version__ = "0.1.0"
__version__ = "0.1.1.dev"
7 changes: 4 additions & 3 deletions src/agentscope/models/dashscope_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ def __init__(
self.generate_args = generate_args or {}

self.api_key = api_key
if self.api_key:
dashscope.api_key = self.api_key
self.max_length = None

def format(
Expand Down Expand Up @@ -245,7 +243,7 @@ def __call__(
if stream:
kwargs["incremental_output"] = True

response = dashscope.Generation.call(**kwargs)
response = dashscope.Generation.call(api_key=self.api_key, **kwargs)

# step3: invoke llm api, record the invocation and update the monitor
if stream:
Expand Down Expand Up @@ -490,6 +488,7 @@ def __call__(
response = dashscope.ImageSynthesis.call(
model=self.model_name,
prompt=prompt,
api_key=self.api_key,
**kwargs,
)
if response.status_code != HTTPStatus.OK:
Expand Down Expand Up @@ -603,6 +602,7 @@ def __call__(
response = dashscope.TextEmbedding.call(
input=texts,
model=self.model_name,
api_key=self.api_key,
**kwargs,
)

Expand Down Expand Up @@ -735,6 +735,7 @@ def __call__(
response = dashscope.MultiModalConversation.call(
model=self.model_name,
messages=messages,
api_key=self.api_key,
**kwargs,
)
# Unhandled code path here
Expand Down
7 changes: 7 additions & 0 deletions tests/dashscope_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def test_call_success(self, mock_generation_call: MagicMock) -> None:
messages=messages,
result_format="message",
stream=False,
api_key="test_api_key",
)

@patch("agentscope.models.dashscope_model.dashscope.Generation.call")
Expand Down Expand Up @@ -102,6 +103,7 @@ def test_call_failure(self, mock_generation_call: MagicMock) -> None:
messages=messages,
result_format="message",
stream=False,
api_key="test_api_key",
)

def tearDown(self) -> None:
Expand Down Expand Up @@ -194,6 +196,7 @@ def test_image_synthesis_wrapper_call_failure(
model=self.model_name,
prompt=prompt,
n=1, # Assuming this is a default value used to call the API
api_key="test_api_key",
)

def tearDown(self) -> None:
Expand Down Expand Up @@ -235,6 +238,7 @@ def test_call_success(self, mock_call: MagicMock) -> None:
mock_call.assert_called_once_with(
input=texts,
model=self.wrapper.model_name,
api_key="test_key",
**self.wrapper.generate_args,
)

Expand Down Expand Up @@ -267,6 +271,7 @@ def test_call_failure(self, mock_call: MagicMock) -> None:
mock_call.assert_called_once_with(
input=texts,
model=self.wrapper.model_name,
api_key="test_key",
**self.wrapper.generate_args,
)

Expand Down Expand Up @@ -327,6 +332,7 @@ def test_call_success(self, mock_call: MagicMock) -> None:
mock_call.assert_called_once_with(
model=self.wrapper.model_name,
messages=messages,
api_key="test_key",
)

@patch(
Expand Down Expand Up @@ -366,6 +372,7 @@ def test_call_failure(self, mock_call: MagicMock) -> None:
mock_call.assert_called_once_with(
model=self.wrapper.model_name,
messages=messages,
api_key="test_key",
)

def tearDown(self) -> None:
Expand Down