Skip to content

Commit 151326a

Browse files
authored
Merge branch 'master' into issue-3352
2 parents cd462c8 + 5f188c1 commit 151326a

34 files changed

+1959
-1004
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.79a0
29+
placeholder: E.g., 0.2.79a2
3030
validations:
3131
required: true
3232

.github/workflows/pytest_package.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ jobs:
209209
ZHIPUAI_API_BASE_URL: "${{ secrets.ZHIPUAI_API_BASE_URL }}"
210210
ZHIPUAI_API_KEY: "${{ secrets.ZHIPUAI_API_KEY }}"
211211
HF_TOKEN: "${{ secrets.HF_TOKEN }}"
212-
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}"
213-
AZURE_API_VERSION: ${{ secrets.AZURE_API_VERSION }}"
214-
AZURE_DEPLOYMENT_NAME: ${{ secrets.AZURE_DEPLOYMENT_NAME }}"
215-
AZURE_OPENAI_BASE_URL: ${{ secrets.AZURE_OPENAI_BASE_URL }}"
212+
AZURE_OPENAI_API_KEY: "${{ secrets.AZURE_OPENAI_API_KEY }}"
213+
AZURE_API_VERSION: "${{ secrets.AZURE_API_VERSION }}"
214+
AZURE_DEPLOYMENT_NAME: "${{ secrets.AZURE_DEPLOYMENT_NAME }}"
215+
AZURE_OPENAI_BASE_URL: "${{ secrets.AZURE_OPENAI_BASE_URL }}"
216216
MISTRAL_API_KEY: "${{ secrets.MISTRAL_API_KEY }}"
217217
REKA_API_KEY: "${{ secrets.REKA_API_KEY }}"
218218
NEO4J_URI: "${{ secrets.NEO4J_URI }}"

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.79a0'
17+
__version__ = '0.2.79a2'
1818

1919
__all__ = [
2020
'__version__',

camel/configs/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14+
from .aihubmix_config import AIHUBMIX_API_PARAMS, AihubMixConfig
1415
from .aiml_config import AIML_API_PARAMS, AIMLConfig
1516
from .amd_config import AMD_API_PARAMS, AMDConfig
1617
from .anthropic_config import ANTHROPIC_API_PARAMS, AnthropicConfig
@@ -57,6 +58,8 @@
5758
'BaseConfig',
5859
'ChatGPTConfig',
5960
'OPENAI_API_PARAMS',
61+
'AihubMixConfig',
62+
'AIHUBMIX_API_PARAMS',
6063
'AnthropicConfig',
6164
'ANTHROPIC_API_PARAMS',
6265
'GROQ_API_PARAMS',

camel/configs/aihubmix_config.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 Dict, Optional, Union
17+
18+
from camel.configs.base_config import BaseConfig
19+
20+
21+
class AihubMixConfig(BaseConfig):
22+
r"""Defines the parameters for generating chat completions using the
23+
AihubMix API.
24+
25+
Args:
26+
temperature (float, optional): Sampling temperature to use, between
27+
:obj:`0` and :obj:`2`. Higher values make the output more random,
28+
while lower values make it more focused and deterministic.
29+
(default: :obj:`0.8`)
30+
max_tokens (int, optional): The maximum number of tokens to generate
31+
in the chat completion. The total length of input tokens and
32+
generated tokens is limited by the model's context length.
33+
(default: :obj:`1024`)
34+
top_p (float, optional): An alternative to sampling with temperature,
35+
called nucleus sampling, where the model considers the results of
36+
the tokens with top_p probability mass. So :obj:`0.1` means only
37+
the tokens comprising the top 10% probability mass are considered.
38+
(default: :obj:`1`)
39+
frequency_penalty (float, optional): Number between :obj:`-2.0` and
40+
:obj:`2.0`. Positive values penalize new tokens based on their
41+
existing frequency in the text so far, decreasing the model's
42+
likelihood to repeat the same line verbatim.
43+
(default: :obj:`0`)
44+
presence_penalty (float, optional): Number between :obj:`-2.0` and
45+
:obj:`2.0`. Positive values penalize new tokens based on whether
46+
they appear in the text so far, increasing the model's likelihood
47+
to talk about new topics.
48+
(default: :obj:`0`)
49+
stream (bool, optional): If True, partial message deltas will be sent
50+
as data-only server-sent events as they become available.
51+
(default: :obj:`False`)
52+
web_search_options (dict, optional): Search model's web search options,
53+
only supported by specific search models.
54+
(default: :obj:`None`)
55+
tools (list[FunctionTool], optional): A list of tools the model may
56+
call. Currently, only functions are supported as a tool. Use this
57+
to provide a list of functions the model may generate JSON inputs
58+
for. A max of 128 functions are supported.
59+
tool_choice (Union[dict[str, str], str], optional): Controls which (if
60+
any) tool is called by the model. :obj:`"none"` means the model
61+
will not call any tool and instead generates a message.
62+
:obj:`"auto"` means the model can pick between generating a
63+
message or calling one or more tools. :obj:`"required"` means the
64+
model must call one or more tools. Specifying a particular tool
65+
via {"type": "function", "function": {"name": "my_function"}}
66+
forces the model to call that tool. :obj:`"none"` is the default
67+
when no tools are present. :obj:`"auto"` is the default if tools
68+
are present.
69+
parallel_tool_calls (bool, optional): A parameter specifying whether
70+
the model should call tools in parallel or not.
71+
(default: :obj:`None`)
72+
extra_headers: Optional[Dict[str, str]]: Extra headers to use for the
73+
model. (default: :obj:`None`)
74+
"""
75+
76+
temperature: Optional[float] = 0.8
77+
max_tokens: Optional[int] = 1024
78+
top_p: Optional[float] = 1.0
79+
frequency_penalty: Optional[float] = 0.0
80+
presence_penalty: Optional[float] = 0.0
81+
stream: Optional[bool] = False
82+
web_search_options: Optional[Dict] = None
83+
tool_choice: Optional[Union[Dict[str, str], str]] = None
84+
parallel_tool_calls: Optional[bool] = None
85+
extra_headers: Optional[Dict[str, str]] = None
86+
87+
88+
AIHUBMIX_API_PARAMS = {param for param in AihubMixConfig.model_fields.keys()}

camel/memories/agent_memories.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,23 @@ def clean_tool_calls(self) -> None:
118118
indices_to_remove.append(i)
119119
# Mark ASSISTANT messages with tool_calls for removal
120120
elif role == OpenAIBackendRole.ASSISTANT.value:
121-
meta_dict = record.get('meta_dict', {})
122-
if meta_dict and 'tool_calls' in meta_dict:
121+
message_dict = record.get('message', {})
122+
# Check for tool_calls in message
123+
has_tool_calls = 'tool_calls' in message_dict
124+
is_func_calling = (
125+
message_dict.get('__class__') == 'FunctionCallingMessage'
126+
and 'args' in message_dict
127+
)
128+
129+
if has_tool_calls or is_func_calling:
123130
indices_to_remove.append(i)
124131

125132
# Remove records in-place
126133
for i in reversed(indices_to_remove):
127134
del record_dicts[i]
128135

129-
# Save the modified records back to storage
136+
# Clear storage and save the modified records back
137+
self._chat_history_block.storage.clear()
130138
self._chat_history_block.storage.save(record_dicts)
131139

132140
def pop_records(self, count: int) -> List[MemoryRecord]:

camel/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14+
from .aihubmix_model import AihubMixModel
1415
from .aiml_model import AIMLModel
1516
from .amd_model import AMDModel
1617
from .anthropic_model import AnthropicModel
@@ -106,4 +107,5 @@
106107
'WatsonXModel',
107108
'QianfanModel',
108109
'CrynuxModel',
110+
'AihubMixModel',
109111
]

camel/models/aihubmix_model.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
import os
15+
from typing import Any, Dict, Optional, Union
16+
17+
from camel.models.openai_compatible_model import OpenAICompatibleModel
18+
from camel.types import ModelType
19+
from camel.utils import (
20+
BaseTokenCounter,
21+
api_keys_required,
22+
)
23+
24+
25+
class AihubMixModel(OpenAICompatibleModel):
26+
r"""AihubMix API in a unified OpenAICompatibleModel interface.
27+
28+
Args:
29+
model_type (Union[ModelType, str]): Model for which a backend is
30+
created.
31+
model_config_dict (Optional[Dict[str, Any]], optional): A dictionary
32+
that will be fed into OpenAI client. If :obj:`None`,
33+
:obj:`{}` will be used.
34+
(default: :obj:`None`)
35+
api_key (Optional[str], optional): The API key for authenticating with
36+
AihubMix service. (default: :obj:`None`)
37+
url (Optional[str], optional): The URL to AihubMix service. If
38+
not provided, :obj:`https://aihubmix.com/v1` will be used.
39+
(default: :obj:`None`)
40+
token_counter (Optional[BaseTokenCounter], optional): Token counter to
41+
use for the model. If not provided, :obj:`OpenAITokenCounter(
42+
ModelType.GPT_4O_MINI)` will be used.
43+
(default: :obj:`None`)
44+
timeout (Optional[float], optional): The timeout value in seconds for
45+
API calls. If not provided, will fall back to the MODEL_TIMEOUT
46+
environment variable or default to 180 seconds.
47+
(default: :obj:`None`)
48+
max_retries (int, optional): Maximum number of retries for API calls.
49+
(default: :obj:`3`)
50+
**kwargs (Any): Additional arguments to pass to the client
51+
initialization.
52+
"""
53+
54+
@api_keys_required([("api_key", "AIHUBMIX_API_KEY")])
55+
def __init__(
56+
self,
57+
model_type: Union[ModelType, str],
58+
model_config_dict: Optional[Dict[str, Any]] = None,
59+
api_key: Optional[str] = None,
60+
url: Optional[str] = None,
61+
token_counter: Optional[BaseTokenCounter] = None,
62+
timeout: Optional[float] = None,
63+
max_retries: int = 3,
64+
**kwargs: Any,
65+
) -> None:
66+
if model_config_dict is None:
67+
model_config_dict = {}
68+
api_key = api_key or os.environ.get("AIHUBMIX_API_KEY")
69+
url = url or os.environ.get(
70+
"AIHUBMIX_API_BASE_URL",
71+
"https://aihubmix.com/v1",
72+
)
73+
timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
74+
super().__init__(
75+
model_type=model_type,
76+
model_config_dict=model_config_dict,
77+
api_key=api_key,
78+
url=url,
79+
token_counter=token_counter,
80+
timeout=timeout,
81+
max_retries=max_retries,
82+
**kwargs,
83+
)

0 commit comments

Comments
 (0)