Skip to content

Commit 6451159

Browse files
authored
feat: AWS Bedrock support aysnc run (#3315)
1 parent 00ddcf6 commit 6451159

File tree

7 files changed

+578
-520
lines changed

7 files changed

+578
-520
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ body:
2626
attributes:
2727
label: What version of camel are you using?
2828
description: Run command `python3 -c 'print(__import__("camel").__version__)'` in your shell and paste the output here.
29-
placeholder: E.g., 0.2.78
29+
placeholder: E.g., 0.2.79a0
3030
validations:
3131
required: true
3232

camel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from camel.logger import disable_logging, enable_logging, set_log_level
1616

17-
__version__ = '0.2.78'
17+
__version__ = '0.2.79a0'
1818

1919
__all__ = [
2020
'__version__',

camel/models/aws_bedrock_model.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,11 @@
1313
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
1414

1515
import os
16-
from typing import Any, Dict, List, Optional, Type, Union
17-
18-
from openai import AsyncStream
19-
from pydantic import BaseModel
16+
from typing import Any, Dict, Optional, Union
2017

2118
from camel.configs import BedrockConfig
22-
from camel.messages import OpenAIMessage
2319
from camel.models.openai_compatible_model import OpenAICompatibleModel
2420
from camel.types import (
25-
ChatCompletion,
26-
ChatCompletionChunk,
2721
ModelType,
2822
)
2923
from camel.utils import BaseTokenCounter, api_keys_required
@@ -93,13 +87,3 @@ def __init__(
9387
max_retries=max_retries,
9488
**kwargs,
9589
)
96-
97-
async def _arun(
98-
self,
99-
messages: List[OpenAIMessage],
100-
response_format: Optional[Type[BaseModel]] = None,
101-
tools: Optional[List[Dict[str, Any]]] = None,
102-
) -> Union[ChatCompletion, AsyncStream[ChatCompletionChunk]]:
103-
raise NotImplementedError(
104-
"AWS Bedrock does not support async inference."
105-
)

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
project = 'CAMEL'
2828
copyright = '2024, CAMEL-AI.org'
2929
author = 'CAMEL-AI.org'
30-
release = '0.2.78'
30+
release = '0.2.79a0'
3131

3232
html_favicon = (
3333
'https://raw.githubusercontent.com/camel-ai/camel/master/misc/favicon.png'

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "camel-ai"
7-
version = "0.2.78"
7+
version = "0.2.79a0"
88
description = "Communicative Agents for AI Society Study"
99
authors = [{ name = "CAMEL-AI.org" }]
1010
requires-python = ">=3.10,<3.15"

test/models/test_aws_bedrock_model.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737
)
3838
def test_aws_bedrock_model(model_type: ModelType):
3939
r"""Test AWSBedrockModel initialization with different model types."""
40-
model = AWSBedrockModel(model_type)
40+
model = AWSBedrockModel(
41+
model_type,
42+
api_key="dummy_key",
43+
url="http://dummy.url",
44+
)
4145
assert model.model_type == model_type
4246
assert model.model_config_dict == BedrockConfig().as_dict()
4347
assert isinstance(model.token_counter, OpenAITokenCounter)
@@ -47,12 +51,23 @@ def test_aws_bedrock_model(model_type: ModelType):
4751

4852
@pytest.mark.model_backend
4953
@pytest.mark.asyncio
50-
async def test_aws_bedrock_async_not_implemented():
51-
r"""Test AWSBedrockModel async method raising NotImplementedError."""
52-
model = AWSBedrockModel(ModelType.AWS_CLAUDE_3_HAIKU)
53-
54-
with pytest.raises(
55-
NotImplementedError,
56-
match="AWS Bedrock does not support async inference.",
57-
):
58-
await model._arun("Test message")
54+
async def test_aws_bedrock_async_supported():
55+
r"""Test AWSBedrockModel async method is now supported.
56+
57+
This test verifies that async inference is supported by ensuring
58+
it doesn't raise NotImplementedError. Instead, it should attempt
59+
to make a connection and fail with APIConnectionError due to
60+
invalid credentials in the test environment.
61+
"""
62+
from openai import APIConnectionError
63+
64+
model = AWSBedrockModel(
65+
ModelType.AWS_CLAUDE_3_HAIKU,
66+
api_key="dummy_key",
67+
url="http://dummy.url",
68+
)
69+
70+
# Async should now be supported, so it should attempt to connect
71+
# and fail with a connection error (not NotImplementedError)
72+
with pytest.raises(APIConnectionError):
73+
await model._arun([{"role": "user", "content": "Test message"}])

0 commit comments

Comments
 (0)