Skip to content

Commit b90c33e

Browse files
danielhua23rootWendong-Fan
authored
feat: add AMD model platform support (#2985)
Co-authored-by: root <root@banff-cyxtera-s83-5.amd.com> Co-authored-by: Wendong-Fan <133094783+Wendong-Fan@users.noreply.github.com>
1 parent 438562d commit b90c33e

File tree

10 files changed

+384
-1
lines changed

10 files changed

+384
-1
lines changed

.github/workflows/build_package.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ jobs:
9999
AZURE_API_VERSION: "${{ secrets.AZURE_API_VERSION }}"
100100
AZURE_DEPLOYMENT_NAME: "${{ secrets.AZURE_DEPLOYMENT_NAME }}"
101101
AZURE_OPENAI_BASE_URL: "${{ secrets.AZURE_OPENAI_BASE_URL }}"
102+
AMD_API_KEY: "${{ secrets.AMD_API_KEY }}"
102103
MISTRAL_API_KEY: "${{ secrets.MISTRAL_API_KEY }}"
103104
REKA_API_KEY: "${{ secrets.REKA_API_KEY }}"
104105
NEO4J_URI: "${{ secrets.NEO4J_URI }}"

.github/workflows/pytest_package.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
ZHIPUAI_API_BASE_URL: "${{ secrets.ZHIPUAI_API_BASE_URL }}"
3636
ZHIPUAI_API_KEY: "${{ secrets.ZHIPUAI_API_KEY }}"
3737
HF_TOKEN: "${{ secrets.HF_TOKEN }}"
38+
AMD_API_KEY: "${{ secrets.AMD_API_KEY }}"
3839
AZURE_OPENAI_API_KEY: "${{ secrets.AZURE_OPENAI_API_KEY }}"
3940
AZURE_API_VERSION: "${{ secrets.AZURE_API_VERSION }}"
4041
AZURE_DEPLOYMENT_NAME: "${{ secrets.AZURE_DEPLOYMENT_NAME }}"

camel/configs/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# limitations under the License.
1313
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
1414
from .aiml_config import AIML_API_PARAMS, AIMLConfig
15+
from .amd_config import AMD_API_PARAMS, AMDConfig
1516
from .anthropic_config import ANTHROPIC_API_PARAMS, AnthropicConfig
1617
from .base_config import BaseConfig
1718
from .bedrock_config import BEDROCK_API_PARAMS, BedrockConfig
@@ -111,6 +112,8 @@
111112
'SILICONFLOW_API_PARAMS',
112113
'AIMLConfig',
113114
'AIML_API_PARAMS',
115+
'AMDConfigs',
116+
'AMD_API_PARAMS',
114117
'OpenRouterConfig',
115118
'OPENROUTER_API_PARAMS',
116119
'LMSTUDIO_API_PARAMS',

camel/configs/amd_config.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14+
from __future__ import annotations
15+
16+
from typing import List, Optional, Union
17+
18+
from pydantic import Field
19+
20+
from camel.configs.base_config import BaseConfig
21+
from camel.types import NotGiven
22+
23+
24+
class AMDConfig(BaseConfig):
25+
r"""Configuration class for AMD API models.
26+
27+
This class defines the configuration parameters for AMD's language
28+
models, including temperature, sampling parameters, and response format
29+
settings.
30+
31+
Args:
32+
stream (bool, optional): Whether to stream the response.
33+
(default: :obj:`None`)
34+
temperature (float, optional): Controls randomness in the response.
35+
Higher values make output more random, lower values make it more
36+
deterministic. Range: [0.0, 2.0]. (default: :obj:`None`)
37+
top_p (float, optional): Controls diversity via nucleus sampling.
38+
Range: [0.0, 1.0]. (default: :obj:`None`)
39+
presence_penalty (float, optional): Penalizes new tokens based on
40+
whether they appear in the text so far. Range: [-2.0, 2.0].
41+
(default: :obj:`None`)
42+
frequency_penalty (float, optional): Penalizes new tokens based on
43+
their frequency in the text so far. Range: [-2.0, 2.0].
44+
(default: :obj:`None`)
45+
max_tokens (Union[int, NotGiven], optional): Maximum number of tokens
46+
to generate. If not provided, model will use its default maximum.
47+
(default: :obj:`None`)
48+
seed (Optional[int], optional): Random seed for deterministic sampling.
49+
(default: :obj:`None`)
50+
tools (Optional[List[Dict]], optional): List of tools available to the
51+
model. This includes tools such as a text editor, a calculator, or
52+
a search engine. (default: :obj:`None`)
53+
tool_choice (Optional[str], optional): Tool choice configuration.
54+
(default: :obj:`None`)
55+
stop (Optional[List[str]], optional): List of stop sequences.
56+
(default: :obj:`None`)
57+
"""
58+
59+
stream: Optional[bool] = Field(default=None)
60+
temperature: Optional[float] = Field(default=None)
61+
top_p: Optional[float] = Field(default=None)
62+
presence_penalty: Optional[float] = Field(default=None)
63+
frequency_penalty: Optional[float] = Field(default=None)
64+
max_tokens: Optional[Union[int, NotGiven]] = Field(default=None)
65+
seed: Optional[int] = Field(default=None)
66+
tool_choice: Optional[str] = Field(default=None)
67+
stop: Optional[List[str]] = Field(default=None)
68+
69+
70+
AMD_API_PARAMS = {param for param in AMDConfig.model_fields.keys()}

camel/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# limitations under the License.
1313
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
1414
from .aiml_model import AIMLModel
15+
from .amd_model import AMDModel
1516
from .anthropic_model import AnthropicModel
1617
from .aws_bedrock_model import AWSBedrockModel
1718
from .azure_openai_model import AzureOpenAIModel
@@ -62,6 +63,7 @@
6263
'OpenRouterModel',
6364
'AzureOpenAIModel',
6465
'AnthropicModel',
66+
'AMDModel',
6567
'MistralModel',
6668
'GroqModel',
6769
'StubModel',

camel/models/amd_model.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14+
15+
import os
16+
from typing import Any, Dict, Optional, Union
17+
18+
from camel.configs import AMD_API_PARAMS, AMDConfig
19+
from camel.models.openai_compatible_model import OpenAICompatibleModel
20+
from camel.types import ModelType
21+
from camel.utils import BaseTokenCounter, api_keys_required
22+
23+
24+
class AMDModel(OpenAICompatibleModel):
25+
r"""AMD API in a unified OpenAICompatibleModel interface.
26+
27+
Args:
28+
model_type (Union[ModelType, str]): Model for which a backend is
29+
created, one of AMD series.
30+
model_config_dict (Optional[Dict[str, Any]], optional): A dictionary
31+
that will be fed into:obj:`openai.ChatCompletion.create()`. If
32+
:obj:`None`, :obj:`AMDConfig().as_dict()` will be used.
33+
(default: :obj:`None`)
34+
api_key (Optional[str], optional): The API key for authenticating with
35+
the AMD service. (default: :obj:`None`)
36+
url (Optional[str], optional): The url to the AMD service.
37+
(default: :obj:`None`)
38+
token_counter (Optional[BaseTokenCounter], optional): Token counter to
39+
use for the model. If not provided, :obj:`OpenAITokenCounter(
40+
ModelType.GPT_4)` will be used.
41+
(default: :obj:`None`)
42+
timeout (Optional[float], optional): The timeout value in seconds for
43+
API calls. If not provided, will fall back to the MODEL_TIMEOUT
44+
environment variable or default to 180 seconds.
45+
(default: :obj:`None`)
46+
max_retries (int, optional): Maximum number of retries for API calls.
47+
(default: :obj:`3`)
48+
**kwargs (Any): Additional arguments to pass to the client
49+
initialization.
50+
"""
51+
52+
@api_keys_required(
53+
[
54+
("api_key", "AMD_API_KEY"),
55+
]
56+
)
57+
def __init__(
58+
self,
59+
model_type: Union[ModelType, str],
60+
model_config_dict: Optional[Dict[str, Any]] = None,
61+
api_key: Optional[str] = None,
62+
url: Optional[str] = None,
63+
token_counter: Optional[BaseTokenCounter] = None,
64+
timeout: Optional[float] = None,
65+
max_retries: int = 3,
66+
**kwargs: Any,
67+
) -> None:
68+
if model_config_dict is None:
69+
model_config_dict = AMDConfig().as_dict()
70+
api_key = api_key or os.environ.get("AMD_API_KEY")
71+
url = url or os.environ.get(
72+
"AMD_API_BASE_URL", "https://llm-api.amd.com"
73+
)
74+
headers = {
75+
'Ocp-Apim-Subscription-Key': api_key
76+
}
77+
kwargs["default_headers"] = headers
78+
timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
79+
super().__init__(
80+
model_type=model_type,
81+
model_config_dict=model_config_dict,
82+
api_key=api_key,
83+
url=url,
84+
token_counter=token_counter,
85+
timeout=timeout,
86+
max_retries=max_retries,
87+
**kwargs,
88+
)
89+
90+
def check_model_config(self):
91+
r"""Check whether the model configuration contains any
92+
unexpected arguments to AMD API.
93+
94+
Raises:
95+
ValueError: If the model configuration dictionary contains any
96+
unexpected arguments to AMD API.
97+
"""
98+
for param in self.model_config_dict:
99+
if param not in AMD_API_PARAMS:
100+
raise ValueError(
101+
f"Unexpected argument `{param}` is "
102+
"input into AMD model backend."
103+
)

camel/models/model_factory.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from typing import ClassVar, Dict, Optional, Type, Union
1717

1818
from camel.models.aiml_model import AIMLModel
19+
from camel.models.amd_model import AMDModel
1920
from camel.models.anthropic_model import AnthropicModel
2021
from camel.models.aws_bedrock_model import AWSBedrockModel
2122
from camel.models.azure_openai_model import AzureOpenAIModel
@@ -77,6 +78,7 @@ class ModelFactory:
7778
ModelPlatformType.AWS_BEDROCK: AWSBedrockModel,
7879
ModelPlatformType.NVIDIA: NvidiaModel,
7980
ModelPlatformType.SILICONFLOW: SiliconFlowModel,
81+
ModelPlatformType.AMD: AMDModel,
8082
ModelPlatformType.AIML: AIMLModel,
8183
ModelPlatformType.VOLCANO: VolcanoModel,
8284
ModelPlatformType.NETMIND: NetmindModel,

camel/types/enums.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class ModelType(UnifiedModelType, Enum):
6464
AWS_CLAUDE_OPUS_4 = "anthropic.claude-opus-4-20250514-v1:0"
6565
AWS_CLAUDE_OPUS_4_1 = "anthropic.claude-opus-4-1-20250805-v1:0"
6666

67+
AMD_GPT4 = "dvue-aoai-001-gpt-4.1"
68+
6769
GLM_4 = "glm-4"
6870
GLM_4V = "glm-4v"
6971
GLM_4V_FLASH = "glm-4v-flash"
@@ -515,7 +517,14 @@ def is_openai(self) -> bool:
515517
ModelType.O4_MINI,
516518
ModelType.O3,
517519
}
518-
520+
521+
@property
522+
def is_amd(self) -> bool:
523+
r"""Returns whether this type of models is a AMD model."""
524+
return self in {
525+
ModelType.AMD_GPT4,
526+
}
527+
519528
@property
520529
def is_aws_bedrock(self) -> bool:
521530
r"""Returns whether this type of models is an AWS Bedrock model."""
@@ -1349,6 +1358,7 @@ def token_limit(self) -> int:
13491358
ModelType.GLM_4_LONG,
13501359
ModelType.TOGETHER_LLAMA_4_MAVERICK,
13511360
ModelType.OPENROUTER_LLAMA_4_MAVERICK,
1361+
ModelType.AMD_GPT4,
13521362
ModelType.GPT_4_1,
13531363
ModelType.GPT_4_1_MINI,
13541364
ModelType.GPT_4_1_NANO,
@@ -1579,6 +1589,7 @@ class ModelPlatformType(Enum):
15791589
COHERE = "cohere"
15801590
YI = "lingyiwanwu"
15811591
QWEN = "tongyi-qianwen"
1592+
AMD = "amd"
15821593
NVIDIA = "nvidia"
15831594
DEEPSEEK = "deepseek"
15841595
PPIO = "ppio"

0 commit comments

Comments
 (0)