Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

fix: ppo model platform integration (#2152)

Wendong-Fanac1ba3055d68
diff --git a/.github/workflows/build_package.yml b/.github/workflows/build_package.yml
index 2e35708a7..3e9abe561 100644
--- a/.github/workflows/build_package.yml
+++ b/.github/workflows/build_package.yml
@@ -103,6 +103,7 @@ jobs:
NOTION_TOKEN: "${{ secrets.NOTION_TOKEN }}"
GOOGLE_CLIENT_ID: "${{ secrets.GOOGLE_CLIENT_ID }}"
GOOGLE_CLIENT_SECRET: "${{ secrets.GOOGLE_CLIENT_SECRET }}"
+ PPIO_API_KEY: "${{ secrets.PPIO_API_KEY }}"
run: |
source test_venv/bin/activate
pytest --fast-test-mode ./test
diff --git a/.github/workflows/pytest_package.yml b/.github/workflows/pytest_package.yml
index 8d94662ca..215c51f46 100644
--- a/.github/workflows/pytest_package.yml
+++ b/.github/workflows/pytest_package.yml
@@ -68,6 +68,7 @@ jobs:
NOTION_TOKEN: "${{ secrets.NOTION_TOKEN }}"
GOOGLE_CLIENT_ID: "${{ secrets.GOOGLE_CLIENT_ID }}"
GOOGLE_CLIENT_SECRET: "${{ secrets.GOOGLE_CLIENT_SECRET }}"
+ PPIO_API_KEY: "${{ secrets.PPIO_API_KEY }}"
run: |
source .venv/bin/activate
uv pip install -e ".[all, dev, docs]"
@@ -128,6 +129,7 @@ jobs:
NOTION_TOKEN: "${{ secrets.NOTION_TOKEN }}"
GOOGLE_CLIENT_ID: "${{ secrets.GOOGLE_CLIENT_ID }}"
GOOGLE_CLIENT_SECRET: "${{ secrets.GOOGLE_CLIENT_SECRET }}"
+ PPIO_API_KEY: "${{ secrets.PPIO_API_KEY }}"
run: |
source .venv/bin/activate
uv pip install -e ".[all, dev, docs]"
@@ -186,6 +188,7 @@ jobs:
NOTION_TOKEN: "${{ secrets.NOTION_TOKEN }}"
GOOGLE_CLIENT_ID: "${{ secrets.GOOGLE_CLIENT_ID }}"
GOOGLE_CLIENT_SECRET: "${{ secrets.GOOGLE_CLIENT_SECRET }}"
+ PPIO_API_KEY: "${{ secrets.PPIO_API_KEY }}"
run: |
source .venv/bin/activate
uv pip install -e ".[all, dev, docs]"
diff --git a/camel/configs/ppio_config.py b/camel/configs/ppio_config.py
index 11f3e959d..5890f39ac 100644
--- a/camel/configs/ppio_config.py
+++ b/camel/configs/ppio_config.py
@@ -13,12 +13,11 @@
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
from __future__ import annotations
-from typing import Any, Sequence, Union
+from typing import Dict, Optional, Sequence, Type, Union
-from pydantic import Field
+from pydantic import BaseModel
from camel.configs.base_config import BaseConfig
-from camel.types import NOT_GIVEN, NotGiven
class PPIOConfig(BaseConfig):
@@ -29,14 +28,14 @@ class PPIOConfig(BaseConfig):
temperature (float, optional): Sampling temperature to use, between
:obj:`0` and :obj:`2`. Higher values make the output more random,
while lower values make it more focused and deterministic.
- (default: :obj:`0.2`)
+ (default: :obj:`None`)
top_p (float, optional): An alternative to sampling with temperature,
called nucleus sampling, where the model considers the results of
the tokens with top_p probability mass. So :obj:`0.1` means only
the tokens comprising the top 10% probability mass are considered.
- (default: :obj:`1.0`)
+ (default: :obj:`None`)
n (int, optional): How many chat completion choices to generate for
- each input message. (default: :obj:`1`)
+ each input message. (default: :obj:`None`)
response_format (object, optional): An object specifying the format
that the model must output. Compatible with GPT-4 Turbo and all
GPT-3.5 Turbo models newer than gpt-3.5-turbo-1106. Setting to
@@ -52,7 +51,7 @@ class PPIOConfig(BaseConfig):
max context length.
stream (bool, optional): If True, partial message deltas will be sent
as data-only server-sent events as they become available.
- (default: :obj:`False`)
+ (default: :obj:`None`)
stop (str or list, optional): Up to :obj:`4` sequences where the API
will stop generating further tokens. (default: :obj:`None`)
max_tokens (int, optional): The maximum number of tokens to generate
@@ -63,12 +62,12 @@ class PPIOConfig(BaseConfig):
:obj:`2.0`. Positive values penalize new tokens based on whether
they appear in the text so far, increasing the model's likelihood
to talk about new topics. See more information about frequency and
- presence penalties. (default: :obj:`0.0`)
+ presence penalties. (default: :obj:`None`)
frequency_penalty (float, optional): Number between :obj:`-2.0` and
:obj:`2.0`. Positive values penalize new tokens based on their
existing frequency in the text so far, decreasing the model's
likelihood to repeat the same line verbatim. See more information
- about frequency and presence penalties. (default: :obj:`0.0`)
+ about frequency and presence penalties. (default: :obj:`None`)
logit_bias (dict, optional): Modify the likelihood of specified tokens
appearing in the completion. Accepts a json object that maps tokens
(specified by their token ID in the tokenizer) to an associated
@@ -77,29 +76,27 @@ class PPIOConfig(BaseConfig):
The exact effect will vary per model, but values between:obj:` -1`
and :obj:`1` should decrease or increase likelihood of selection;
values like :obj:`-100` or :obj:`100` should result in a ban or
- exclusive selection of the relevant token. (default: :obj:`{}`)
+ exclusive selection of the relevant token. (default: :obj:`None`)
user (str, optional): A unique identifier representing your end-user,
which can help OpenAI to monitor and detect abuse.
- (default: :obj:`""`)
+ (default: :obj:`None`)
+ tools (list[FunctionTool], optional): A list of tools the model may
+ call. Currently, only functions are supported as a tool. Use this
+ to provide a list of functions the model may generate JSON inputs
+ for. A max of 128 functions are supported.
"""
- temperature: float = 0.2 # openai default: 1.0
- top_p: float = 1.0
- n: int = 1
- stream: bool = False
- stop: Union[str, Sequence[str], NotGiven] = NOT_GIVEN
- max_tokens: Union[int, NotGiven] = NOT_GIVEN
- presence_penalty: float = 0.0
- response_format: Union[dict, NotGiven] = NOT_GIVEN
- frequency_penalty: float = 0.0
- logit_bias: dict = Field(default_factory=dict)
- user: str = ""
-
- def as_dict(self) -> dict[str, Any]:
- config_dict = super().as_dict()
- if "tools" in config_dict:
- del config_dict["tools"] # Currently does not support tool calling
- return config_dict
+ temperature: Optional[float] = None
+ top_p: Optional[float] = None
+ n: Optional[int] = None
+ stream: Optional[bool] = None
+ stop: Optional[Union[str, Sequence[str]]] = None
+ max_tokens: Optional[int] = None
+ presence_penalty: Optional[float] = None
+ response_format: Optional[Union[Type[BaseModel], Dict]] = None
+ frequency_penalty: Optional[float] = None
+ logit_bias: Optional[Dict] = None
+ user: Optional[str] = None
PPIO_API_PARAMS = {param for param in PPIOConfig.model_fields.keys()}
diff --git a/camel/configs/reka_config.py b/camel/configs/reka_config.py
index 446247db0..186f6b348 100644
--- a/camel/configs/reka_config.py
+++ b/camel/configs/reka_config.py
@@ -13,7 +13,7 @@
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
from __future__ import annotations
-from typing import Any, Optional, Union
+from typing import Optional, Union
from camel.configs.base_config import BaseConfig
@@ -65,11 +65,5 @@ class RekaConfig(BaseConfig):
presence_penalty: Optional[float] = None
use_search_engine: Optional[bool] = None
- def as_dict(self) -> dict[str, Any]:
- config_dict = super().as_dict()
- if "tools" in config_dict:
- del config_dict["tools"] # Reka does not support tool calling
- return config_dict
-
REKA_API_PARAMS = {param for param in RekaConfig().model_fields.keys()}
diff --git a/camel/configs/samba_config.py b/camel/configs/samba_config.py
index 83010485b..8c44c957b 100644
--- a/camel/configs/samba_config.py
+++ b/camel/configs/samba_config.py
@@ -13,7 +13,7 @@
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
from __future__ import annotations
-from typing import Any, Optional, Sequence, Union
+from typing import Optional, Sequence, Union
from pydantic import Field
@@ -63,12 +63,6 @@ class SambaVerseAPIConfig(BaseConfig):
stop: Optional[Union[str, list[str]]] = None
stream: Optional[bool] = None
- def as_dict(self) -> dict[str, Any]:
- config_dict = super().as_dict()
- if "tools" in config_dict:
- del config_dict["tools"] # SambaNova does not support tool calling
- return config_dict
-
SAMBA_VERSE_API_PARAMS = {
param for param in SambaVerseAPIConfig().model_fields.keys()
diff --git a/camel/configs/togetherai_config.py b/camel/configs/togetherai_config.py
index 1a25e0a6c..2ed22b3e3 100644
--- a/camel/configs/togetherai_config.py
+++ b/camel/configs/togetherai_config.py
@@ -13,7 +13,7 @@
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
from __future__ import annotations
-from typing import Any, Optional, Sequence, Union
+from typing import Optional, Sequence, Union
from pydantic import Field
@@ -94,12 +94,6 @@ class TogetherAIConfig(BaseConfig):
logit_bias: dict = Field(default_factory=dict)
user: Optional[str] = None
- def as_dict(self) -> dict[str, Any]:
- config_dict = super().as_dict()
- if "tools" in config_dict:
- del config_dict["tools"] # Currently does not support tool calling
- return config_dict
-
TOGETHERAI_API_PARAMS = {
param for param in TogetherAIConfig.model_fields.keys()
diff --git a/camel/models/ppio_model.py b/camel/models/ppio_model.py
index 5754a2165..ccc0a37ac 100644
--- a/camel/models/ppio_model.py
+++ b/camel/models/ppio_model.py
@@ -52,6 +52,10 @@ class PPIOModel(BaseModelBackend):
token_counter (Optional[BaseTokenCounter], optional): Token counter to
use for the model. If not provided, :obj:`OpenAITokenCounter(
ModelType.GPT_4O_MINI)` will be used.
+ timeout (Optional[float], optional): The timeout value in seconds for
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
+ environment variable or default to 180 seconds.
+ (default: :obj:`None`)
"""
@api_keys_required(
@@ -66,6 +70,7 @@ class PPIOModel(BaseModelBackend):
api_key: Optional[str] = None,
url: Optional[str] = None,
token_counter: Optional[BaseTokenCounter] = None,
+ timeout: Optional[float] = None,
) -> None:
if model_config_dict is None:
model_config_dict = PPIOConfig().as_dict()
@@ -73,18 +78,20 @@ class PPIOModel(BaseModelBackend):
url = url or os.environ.get(
"PPIO_API_BASE_URL", "https://api.ppinfra.com/v3/openai"
)
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
+
super().__init__(
- model_type, model_config_dict, api_key, url, token_counter
+ model_type, model_config_dict, api_key, url, token_counter, timeout
)
self._client = OpenAI(
- timeout=180,
+ timeout=self._timeout,
max_retries=3,
api_key=self._api_key,
base_url=self._url,
)
self._async_client = AsyncOpenAI(
- timeout=180,
+ timeout=self._timeout,
max_retries=3,
api_key=self._api_key,
base_url=self._url,