🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
enhance: AWS bedrock and LM studio integration PR 1194, 2193 (#2229)
Wendong-Fan9f18a9c18865
diff --git a/camel/configs/bedrock_config.py b/camel/configs/bedrock_config.pyindex 279ccf5ab..98fcbc665 100644--- a/camel/configs/bedrock_config.py+++ b/camel/configs/bedrock_config.py@@ -11,26 +11,63 @@# See the License for the specific language governing permissions and# limitations under the License.# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========-from typing import Optional+from typing import Dict, Optional, Unionfrom camel.configs.base_config import BaseConfigclass BedrockConfig(BaseConfig):- r"""Defines the parameters for generating chat completions using Bedrock+ r"""Defines the parameters for generating chat completions using OpenAIcompatibility.Args:- maxTokens (int, optional): The maximum number of tokens.- temperatue (float, optional): Controls the randomness of the output.- top_p (float, optional): Use nucleus sampling.+ max_tokens (int, optional): The maximum number of tokens to generate+ in the chat completion. The total length of input tokens and+ generated tokens is limited by the model's context length.+ (default: :obj:`None`)+ 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:`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:`None`)top_k (int, optional): The number of top tokens to consider.+ stream (bool, optional): If True, partial message deltas will be sent+ as data-only server-sent events as they become available.+ (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.+ tool_choice (Union[dict[str, str], str], optional): Controls which (if+ any) tool is called by the model. :obj:`"none"` means the model+ will not call any tool and instead generates a message.+ :obj:`"auto"` means the model can pick between generating a+ message or calling one or more tools. :obj:`"required"` means the+ model must call one or more tools. Specifying a particular tool+ via {"type": "function", "function": {"name": "my_function"}}+ forces the model to call that tool. :obj:`"none"` is the default+ when no tools are present. :obj:`"auto"` is the default if tools+ are present.+ reasoning_effort(str, optional): A parameter specifying the level of+ reasoning used by certain model types. Valid values are :obj:+ `"low"`, :obj:`"medium"`, or :obj:`"high"`. If set, it is only+ applied to the model types that support it (e.g., :obj:`o1`,+ :obj:`o1mini`, :obj:`o1preview`, :obj:`o3mini`). If not provided+ or if the model type does not support it, this parameter is+ ignored. (default: :obj:`None`)"""max_tokens: Optional[int] = Nonetemperature: Optional[float] = Nonetop_p: Optional[float] = Nonetop_k: Optional[int] = None+ stream: Optional[bool] = None+ tool_choice: Optional[Union[Dict[str, str], str]] = None+ reasoning_effort: Optional[str] = NoneBEDROCK_API_PARAMS = {param for param in BedrockConfig.model_fields.keys()}diff --git a/camel/configs/lmstudio_config.py b/camel/configs/lmstudio_config.pyindex 6f65eac59..f3e3cd5a8 100644--- a/camel/configs/lmstudio_config.py+++ b/camel/configs/lmstudio_config.py@@ -32,8 +32,6 @@ class LMStudioConfig(BaseConfig):the tokens with top_p probability mass. So :obj:`0.1` means onlythe tokens comprising the top 10% probability mass are considered.(default: :obj:`None`)- n (int, optional): How many chat completion choices to generate for- each input message. (default: :obj:`None`)response_format (object, optional): An object specifying the formatthat the model must output. Compatible with GPT-4 Turbo and allGPT-3.5 Turbo models newer than gpt-3.5-turbo-1106. Setting to@@ -66,9 +64,6 @@ class LMStudioConfig(BaseConfig):existing frequency in the text so far, decreasing the model'slikelihood to repeat the same line verbatim. See more informationabout frequency and presence penalties. (default: :obj:`None`)- user (str, optional): A unique identifier representing your end-user,- which can help OpenAI to monitor and detect abuse.- (default: :obj:`None`)tools (list[FunctionTool], optional): A list of tools the model maycall. Currently, only functions are supported as a tool. Use thisto provide a list of functions the model may generate JSON inputs@@ -87,14 +82,12 @@ class LMStudioConfig(BaseConfig):temperature: Optional[float] = Nonetop_p: Optional[float] = None- n: Optional[int] = Nonestream: Optional[bool] = Nonestop: Optional[Union[str, Sequence[str]]] = Nonemax_tokens: Optional[int] = Nonepresence_penalty: Optional[float] = Noneresponse_format: Optional[dict] = Nonefrequency_penalty: Optional[float] = None- user: Optional[str] = Nonetool_choice: Optional[Union[dict[str, str], str]] = Nonediff --git a/camel/models/aws_bedrock_model.py b/camel/models/aws_bedrock_model.pyindex bee836ed4..983a888b1 100644--- a/camel/models/aws_bedrock_model.py+++ b/camel/models/aws_bedrock_model.py@@ -50,6 +50,7 @@ class AWSBedrockModel(OpenAICompatibleModel):API calls. If not provided, will fall back to the MODEL_TIMEOUTenvironment variable or default to 180 seconds.(default: :obj:`None`)+References:https://docs.aws.amazon.com/bedrock/latest/APIReference/welcome.html"""diff --git a/camel/models/lmstudio_model.py b/camel/models/lmstudio_model.pyindex 8f7472bf2..edc9a1eb2 100644--- a/camel/models/lmstudio_model.py+++ b/camel/models/lmstudio_model.py@@ -30,8 +30,9 @@ class LMStudioModel(OpenAICompatibleModel):that will be fed into:obj:`openai.ChatCompletion.create()`.If:obj:`None`, :obj:`LMStudioConfig().as_dict()` will be used.(default: :obj:`None`)- api_key (Optional[str], optional): The API key for authenticating- with the LMStudio service. (default: :obj:`None`).+ api_key (Optional[str], optional): The API key for authenticating with+ the model service. LMStudio doesn't need API key, it would be+ ignored if set. (default: :obj:`None`)url (Optional[str], optional): The url to the LMStudio service.(default: :obj:`None`)token_counter (Optional[BaseTokenCounter], optional): Token counter todiff --git a/camel/models/model_factory.py b/camel/models/model_factory.pyindex d8f97c89f..2f40e769d 100644--- a/camel/models/model_factory.py+++ b/camel/models/model_factory.py@@ -67,7 +67,7 @@ class ModelFactory:token_counter: Optional[BaseTokenCounter] = None,api_key: Optional[str] = None,url: Optional[str] = None,- timeout: Optional[int] = None,+ timeout: Optional[float] = None,) -> BaseModelBackend:r"""Creates an instance of `BaseModelBackend` of the specified type.diff --git a/camel/models/sglang_model.py b/camel/models/sglang_model.pyindex 12945019a..8651212ac 100644--- a/camel/models/sglang_model.py+++ b/camel/models/sglang_model.py@@ -119,7 +119,9 @@ class SGLangModel(BaseModelBackend):)server_process = _execute_shell_command(cmd)- _wait_for_server("http://localhost:30000")+ _wait_for_server(+ base_url="http://localhost:30000", timeout=self._timeout+ )self._url = "http://127.0.0.1:30000/v1"self.server_process = server_process # type: ignore[assignment]# Start the inactivity monitor in a background thread@@ -356,12 +358,12 @@ def _execute_shell_command(command: str) -> subprocess.Popen:return subprocess.Popen(parts, text=True, stderr=subprocess.STDOUT)-def _wait_for_server(base_url: str, timeout: Optional[int] = 30) -> None:+def _wait_for_server(base_url: str, timeout: Optional[float] = 30) -> None:r"""Wait for the server to be ready by polling the /v1/models endpoint.Args:base_url (str): The base URL of the server- timeout (Optional[int]): Maximum time to wait in seconds.+ timeout (Optional[float]): Maximum time to wait in seconds.(default: :obj:`30`)"""import requestsdiff --git a/test/toolkits/test_video_analysis_toolkit.py b/test/toolkits/test_video_analysis_toolkit.pyindex f1ae88ef4..8f1c2f0f6 100644--- a/test/toolkits/test_video_analysis_toolkit.py+++ b/test/toolkits/test_video_analysis_toolkit.py@@ -274,7 +274,7 @@ def test_extract_keyframes_with_scenes(mock_video_toolkit):):mock_scene_manager.get_scene_list.return_value = mock_scene_list- result = mock_video_toolkit._extract_keyframes("/path/to/video.mp4", 2)+ result = mock_video_toolkit._extract_keyframes("/path/to/video.mp4")assert len(result) == 2assert result[0] == mock_frame@@ -311,7 +311,7 @@ def test_extract_keyframes_no_scenes(mock_video_toolkit):),):# Call the method directly to verify our patch works- frames = mock_video_toolkit._extract_keyframes("/path/to/video.mp4", 2)+ frames = mock_video_toolkit._extract_keyframes("/path/to/video.mp4")# Assert that our patch returns the expected number of framesassert len(frames) == 2@@ -355,9 +355,7 @@ def test_extract_keyframes_invalid_num_frames(mock_video_toolkit):):mock_scene_manager.get_scene_list.return_value = mock_scene_list- result = mock_video_toolkit._extract_keyframes(- "/path/to/video.mp4", -1- )+ result = mock_video_toolkit._extract_keyframes("/path/to/video.mp4")assert len(result) == 1assert result[0] == mock_frame@@ -445,12 +443,6 @@ def test_ask_question_about_video_no_audio(mock_video_toolkit):assert "No audio transcription available" in call_args.content-def test_ask_question_about_video_empty_question(mock_video_toolkit):- r"""Test asking an empty question"""- with pytest.raises(ValueError):- mock_video_toolkit.ask_question_about_video("/path/to/video.mp4", "")--def test_ask_question_about_video_file_not_found(mock_video_toolkit):r"""Test handling file not found error"""with patch("os.path.exists", return_value=False):