camel-ai 0.2.45__py3-none-any.whl → 0.2.47__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of camel-ai might be problematic. Click here for more details.
- camel/__init__.py +1 -1
- camel/configs/__init__.py +6 -0
- camel/configs/bedrock_config.py +73 -0
- camel/configs/lmstudio_config.py +94 -0
- camel/configs/qwen_config.py +3 -3
- camel/datasets/few_shot_generator.py +19 -3
- camel/datasets/models.py +1 -1
- camel/loaders/__init__.py +2 -0
- camel/loaders/scrapegraph_reader.py +96 -0
- camel/models/__init__.py +4 -0
- camel/models/aiml_model.py +11 -104
- camel/models/anthropic_model.py +11 -76
- camel/models/aws_bedrock_model.py +112 -0
- camel/models/deepseek_model.py +11 -44
- camel/models/gemini_model.py +10 -72
- camel/models/groq_model.py +11 -131
- camel/models/internlm_model.py +11 -61
- camel/models/lmstudio_model.py +82 -0
- camel/models/model_factory.py +7 -1
- camel/models/modelscope_model.py +11 -122
- camel/models/moonshot_model.py +10 -76
- camel/models/nemotron_model.py +4 -60
- camel/models/nvidia_model.py +11 -111
- camel/models/ollama_model.py +12 -205
- camel/models/openai_compatible_model.py +51 -12
- camel/models/openai_model.py +3 -1
- camel/models/openrouter_model.py +12 -131
- camel/models/ppio_model.py +10 -99
- camel/models/qwen_model.py +11 -122
- camel/models/reka_model.py +1 -1
- camel/models/sglang_model.py +5 -3
- camel/models/siliconflow_model.py +10 -58
- camel/models/togetherai_model.py +10 -177
- camel/models/vllm_model.py +11 -218
- camel/models/volcano_model.py +1 -15
- camel/models/yi_model.py +11 -98
- camel/models/zhipuai_model.py +11 -102
- camel/storages/__init__.py +2 -0
- camel/storages/vectordb_storages/__init__.py +2 -0
- camel/storages/vectordb_storages/oceanbase.py +458 -0
- camel/toolkits/__init__.py +4 -0
- camel/toolkits/browser_toolkit.py +4 -7
- camel/toolkits/jina_reranker_toolkit.py +231 -0
- camel/toolkits/pyautogui_toolkit.py +428 -0
- camel/toolkits/search_toolkit.py +167 -0
- camel/toolkits/video_analysis_toolkit.py +215 -80
- camel/toolkits/video_download_toolkit.py +10 -3
- camel/types/enums.py +70 -0
- camel/types/unified_model_type.py +10 -0
- camel/utils/token_counting.py +7 -3
- {camel_ai-0.2.45.dist-info → camel_ai-0.2.47.dist-info}/METADATA +13 -1
- {camel_ai-0.2.45.dist-info → camel_ai-0.2.47.dist-info}/RECORD +54 -46
- {camel_ai-0.2.45.dist-info → camel_ai-0.2.47.dist-info}/WHEEL +0 -0
- {camel_ai-0.2.45.dist-info → camel_ai-0.2.47.dist-info}/licenses/LICENSE +0 -0
camel/__init__.py
CHANGED
camel/configs/__init__.py
CHANGED
|
@@ -14,12 +14,14 @@
|
|
|
14
14
|
from .aiml_config import AIML_API_PARAMS, AIMLConfig
|
|
15
15
|
from .anthropic_config import ANTHROPIC_API_PARAMS, AnthropicConfig
|
|
16
16
|
from .base_config import BaseConfig
|
|
17
|
+
from .bedrock_config import BEDROCK_API_PARAMS, BedrockConfig
|
|
17
18
|
from .cohere_config import COHERE_API_PARAMS, CohereConfig
|
|
18
19
|
from .deepseek_config import DEEPSEEK_API_PARAMS, DeepSeekConfig
|
|
19
20
|
from .gemini_config import Gemini_API_PARAMS, GeminiConfig
|
|
20
21
|
from .groq_config import GROQ_API_PARAMS, GroqConfig
|
|
21
22
|
from .internlm_config import INTERNLM_API_PARAMS, InternLMConfig
|
|
22
23
|
from .litellm_config import LITELLM_API_PARAMS, LiteLLMConfig
|
|
24
|
+
from .lmstudio_config import LMSTUDIO_API_PARAMS, LMStudioConfig
|
|
23
25
|
from .mistral_config import MISTRAL_API_PARAMS, MistralConfig
|
|
24
26
|
from .modelscope_config import MODELSCOPE_API_PARAMS, ModelScopeConfig
|
|
25
27
|
from .moonshot_config import MOONSHOT_API_PARAMS, MoonshotConfig
|
|
@@ -81,6 +83,8 @@ __all__ = [
|
|
|
81
83
|
'YI_API_PARAMS',
|
|
82
84
|
'QwenConfig',
|
|
83
85
|
'QWEN_API_PARAMS',
|
|
86
|
+
'BedrockConfig',
|
|
87
|
+
'BEDROCK_API_PARAMS',
|
|
84
88
|
'DeepSeekConfig',
|
|
85
89
|
'DEEPSEEK_API_PARAMS',
|
|
86
90
|
'PPIOConfig',
|
|
@@ -97,4 +101,6 @@ __all__ = [
|
|
|
97
101
|
'AIML_API_PARAMS',
|
|
98
102
|
'OpenRouterConfig',
|
|
99
103
|
'OPENROUTER_API_PARAMS',
|
|
104
|
+
'LMSTUDIO_API_PARAMS',
|
|
105
|
+
'LMStudioConfig',
|
|
100
106
|
]
|
|
@@ -0,0 +1,73 @@
|
|
|
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 typing import Dict, Optional, Union
|
|
15
|
+
|
|
16
|
+
from camel.configs.base_config import BaseConfig
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class BedrockConfig(BaseConfig):
|
|
20
|
+
r"""Defines the parameters for generating chat completions using OpenAI
|
|
21
|
+
compatibility.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
max_tokens (int, optional): The maximum number of tokens to generate
|
|
25
|
+
in the chat completion. The total length of input tokens and
|
|
26
|
+
generated tokens is limited by the model's context length.
|
|
27
|
+
(default: :obj:`None`)
|
|
28
|
+
temperature (float, optional): Sampling temperature to use, between
|
|
29
|
+
:obj:`0` and :obj:`2`. Higher values make the output more random,
|
|
30
|
+
while lower values make it more focused and deterministic.
|
|
31
|
+
(default: :obj:`None`)
|
|
32
|
+
top_p (float, optional): An alternative to sampling with temperature,
|
|
33
|
+
called nucleus sampling, where the model considers the results of
|
|
34
|
+
the tokens with top_p probability mass. So :obj:`0.1` means only
|
|
35
|
+
the tokens comprising the top 10% probability mass are considered.
|
|
36
|
+
(default: :obj:`None`)
|
|
37
|
+
top_k (int, optional): The number of top tokens to consider.
|
|
38
|
+
stream (bool, optional): If True, partial message deltas will be sent
|
|
39
|
+
as data-only server-sent events as they become available.
|
|
40
|
+
(default: :obj:`None`)
|
|
41
|
+
tools (list[FunctionTool], optional): A list of tools the model may
|
|
42
|
+
call. Currently, only functions are supported as a tool. Use this
|
|
43
|
+
to provide a list of functions the model may generate JSON inputs
|
|
44
|
+
for. A max of 128 functions are supported.
|
|
45
|
+
tool_choice (Union[dict[str, str], str], optional): Controls which (if
|
|
46
|
+
any) tool is called by the model. :obj:`"none"` means the model
|
|
47
|
+
will not call any tool and instead generates a message.
|
|
48
|
+
:obj:`"auto"` means the model can pick between generating a
|
|
49
|
+
message or calling one or more tools. :obj:`"required"` means the
|
|
50
|
+
model must call one or more tools. Specifying a particular tool
|
|
51
|
+
via {"type": "function", "function": {"name": "my_function"}}
|
|
52
|
+
forces the model to call that tool. :obj:`"none"` is the default
|
|
53
|
+
when no tools are present. :obj:`"auto"` is the default if tools
|
|
54
|
+
are present.
|
|
55
|
+
reasoning_effort(str, optional): A parameter specifying the level of
|
|
56
|
+
reasoning used by certain model types. Valid values are :obj:
|
|
57
|
+
`"low"`, :obj:`"medium"`, or :obj:`"high"`. If set, it is only
|
|
58
|
+
applied to the model types that support it (e.g., :obj:`o1`,
|
|
59
|
+
:obj:`o1mini`, :obj:`o1preview`, :obj:`o3mini`). If not provided
|
|
60
|
+
or if the model type does not support it, this parameter is
|
|
61
|
+
ignored. (default: :obj:`None`)
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
max_tokens: Optional[int] = None
|
|
65
|
+
temperature: Optional[float] = None
|
|
66
|
+
top_p: Optional[float] = None
|
|
67
|
+
top_k: Optional[int] = None
|
|
68
|
+
stream: Optional[bool] = None
|
|
69
|
+
tool_choice: Optional[Union[Dict[str, str], str]] = None
|
|
70
|
+
reasoning_effort: Optional[str] = None
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
BEDROCK_API_PARAMS = {param for param in BedrockConfig.model_fields.keys()}
|
|
@@ -0,0 +1,94 @@
|
|
|
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 Optional, Sequence, Union
|
|
17
|
+
|
|
18
|
+
from camel.configs.base_config import BaseConfig
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class LMStudioConfig(BaseConfig):
|
|
22
|
+
r"""Defines the parameters for generating chat completions using OpenAI
|
|
23
|
+
compatibility.
|
|
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:`None`)
|
|
30
|
+
top_p (float, optional): An alternative to sampling with temperature,
|
|
31
|
+
called nucleus sampling, where the model considers the results of
|
|
32
|
+
the tokens with top_p probability mass. So :obj:`0.1` means only
|
|
33
|
+
the tokens comprising the top 10% probability mass are considered.
|
|
34
|
+
(default: :obj:`None`)
|
|
35
|
+
response_format (object, optional): An object specifying the format
|
|
36
|
+
that the model must output. Compatible with GPT-4 Turbo and all
|
|
37
|
+
GPT-3.5 Turbo models newer than gpt-3.5-turbo-1106. Setting to
|
|
38
|
+
{"type": "json_object"} enables JSON mode, which guarantees the
|
|
39
|
+
message the model generates is valid JSON. Important: when using
|
|
40
|
+
JSON mode, you must also instruct the model to produce JSON
|
|
41
|
+
yourself via a system or user message. Without this, the model
|
|
42
|
+
may generate an unending stream of whitespace until the generation
|
|
43
|
+
reaches the token limit, resulting in a long-running and seemingly
|
|
44
|
+
"stuck" request. Also note that the message content may be
|
|
45
|
+
partially cut off if finish_reason="length", which indicates the
|
|
46
|
+
generation exceeded max_tokens or the conversation exceeded the
|
|
47
|
+
max context length.
|
|
48
|
+
stream (bool, optional): If True, partial message deltas will be sent
|
|
49
|
+
as data-only server-sent events as they become available.
|
|
50
|
+
(default: :obj:`None`)
|
|
51
|
+
stop (str or list, optional): Up to :obj:`4` sequences where the API
|
|
52
|
+
will stop generating further tokens. (default: :obj:`None`)
|
|
53
|
+
max_tokens (int, optional): The maximum number of tokens to generate
|
|
54
|
+
in the chat completion. The total length of input tokens and
|
|
55
|
+
generated tokens is limited by the model's context length.
|
|
56
|
+
(default: :obj:`None`)
|
|
57
|
+
presence_penalty (float, optional): Number between :obj:`-2.0` and
|
|
58
|
+
:obj:`2.0`. Positive values penalize new tokens based on whether
|
|
59
|
+
they appear in the text so far, increasing the model's likelihood
|
|
60
|
+
to talk about new topics. See more information about frequency and
|
|
61
|
+
presence penalties. (default: :obj:`None`)
|
|
62
|
+
frequency_penalty (float, optional): Number between :obj:`-2.0` and
|
|
63
|
+
:obj:`2.0`. Positive values penalize new tokens based on their
|
|
64
|
+
existing frequency in the text so far, decreasing the model's
|
|
65
|
+
likelihood to repeat the same line verbatim. See more information
|
|
66
|
+
about frequency and presence penalties. (default: :obj:`None`)
|
|
67
|
+
tools (list[FunctionTool], optional): A list of tools the model may
|
|
68
|
+
call. Currently, only functions are supported as a tool. Use this
|
|
69
|
+
to provide a list of functions the model may generate JSON inputs
|
|
70
|
+
for. A max of 128 functions are supported.
|
|
71
|
+
tool_choice (Union[dict[str, str], str], optional): Controls which (if
|
|
72
|
+
any) tool is called by the model. :obj:`"none"` means the model
|
|
73
|
+
will not call any tool and instead generates a message.
|
|
74
|
+
:obj:`"auto"` means the model can pick between generating a
|
|
75
|
+
message or calling one or more tools. :obj:`"required"` means the
|
|
76
|
+
model must call one or more tools. Specifying a particular tool
|
|
77
|
+
via {"type": "function", "function": {"name": "my_function"}}
|
|
78
|
+
forces the model to call that tool. :obj:`"none"` is the default
|
|
79
|
+
when no tools are present. :obj:`"auto"` is the default if tools
|
|
80
|
+
are present.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
temperature: Optional[float] = None
|
|
84
|
+
top_p: Optional[float] = None
|
|
85
|
+
stream: Optional[bool] = None
|
|
86
|
+
stop: Optional[Union[str, Sequence[str]]] = None
|
|
87
|
+
max_tokens: Optional[int] = None
|
|
88
|
+
presence_penalty: Optional[float] = None
|
|
89
|
+
response_format: Optional[dict] = None
|
|
90
|
+
frequency_penalty: Optional[float] = None
|
|
91
|
+
tool_choice: Optional[Union[dict[str, str], str]] = None
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
LMSTUDIO_API_PARAMS = {param for param in LMStudioConfig.model_fields.keys()}
|
camel/configs/qwen_config.py
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
14
|
from __future__ import annotations
|
|
15
15
|
|
|
16
|
-
from typing import Dict, List, Optional, Union
|
|
16
|
+
from typing import Any, Dict, List, Optional, Union
|
|
17
17
|
|
|
18
18
|
from camel.configs.base_config import BaseConfig
|
|
19
19
|
|
|
@@ -61,7 +61,7 @@ class QwenConfig(BaseConfig):
|
|
|
61
61
|
call. It can contain one or more tool objects. During a function
|
|
62
62
|
call process, the model will select one tool from the array.
|
|
63
63
|
(default: :obj:`None`)
|
|
64
|
-
extra_body (Optional[Dict[str,
|
|
64
|
+
extra_body (Optional[Dict[str, Any]], optional): Additional parameters
|
|
65
65
|
to be sent to the Qwen API. If you want to enable internet search,
|
|
66
66
|
you can set this parameter to `{"enable_search": True}`.
|
|
67
67
|
(default: :obj:`None`)
|
|
@@ -78,7 +78,7 @@ class QwenConfig(BaseConfig):
|
|
|
78
78
|
max_tokens: Optional[int] = None
|
|
79
79
|
seed: Optional[int] = None
|
|
80
80
|
stop: Optional[Union[str, List]] = None
|
|
81
|
-
extra_body: Optional[Dict[str,
|
|
81
|
+
extra_body: Optional[Dict[str, Any]] = None
|
|
82
82
|
|
|
83
83
|
def __init__(self, include_usage: bool = True, **kwargs):
|
|
84
84
|
super().__init__(**kwargs)
|
|
@@ -16,7 +16,7 @@ import asyncio
|
|
|
16
16
|
from datetime import datetime
|
|
17
17
|
from typing import List
|
|
18
18
|
|
|
19
|
-
from pydantic import ValidationError
|
|
19
|
+
from pydantic import BaseModel, Field, ValidationError
|
|
20
20
|
|
|
21
21
|
from camel.agents import ChatAgent
|
|
22
22
|
from camel.logger import get_logger
|
|
@@ -176,14 +176,30 @@ class FewShotGenerator(BaseGenerator):
|
|
|
176
176
|
]
|
|
177
177
|
prompt = self._construct_prompt(examples)
|
|
178
178
|
|
|
179
|
+
# Create a simplified version of DataPoint that omits metadata
|
|
180
|
+
# because agent.step's response_format parameter doesn't
|
|
181
|
+
# support type Dict[str, Any]
|
|
182
|
+
class DataPointSimplified(BaseModel):
|
|
183
|
+
question: str = Field(
|
|
184
|
+
description="The primary question or issue to "
|
|
185
|
+
"be addressed."
|
|
186
|
+
)
|
|
187
|
+
final_answer: str = Field(description="The final answer.")
|
|
188
|
+
rationale: str = Field(
|
|
189
|
+
description="Logical reasoning or explanation "
|
|
190
|
+
"behind the answer."
|
|
191
|
+
)
|
|
192
|
+
|
|
179
193
|
try:
|
|
180
194
|
agent_output = (
|
|
181
|
-
self.agent.step(
|
|
195
|
+
self.agent.step(
|
|
196
|
+
prompt, response_format=DataPointSimplified
|
|
197
|
+
)
|
|
182
198
|
.msgs[0]
|
|
183
199
|
.parsed
|
|
184
200
|
)
|
|
185
201
|
|
|
186
|
-
assert isinstance(agent_output,
|
|
202
|
+
assert isinstance(agent_output, DataPointSimplified)
|
|
187
203
|
|
|
188
204
|
self.agent.reset()
|
|
189
205
|
|
camel/datasets/models.py
CHANGED
|
@@ -24,7 +24,7 @@ class DataPoint(BaseModel):
|
|
|
24
24
|
final_answer (str): The final answer.
|
|
25
25
|
rationale (Optional[str]): Logical reasoning or explanation behind the
|
|
26
26
|
answer. (default: :obj:`None`)
|
|
27
|
-
metadata Optional[Dict[str, Any]]: Additional metadata about the data
|
|
27
|
+
metadata (Optional[Dict[str, Any]]): Additional metadata about the data
|
|
28
28
|
point. (default: :obj:`None`)
|
|
29
29
|
"""
|
|
30
30
|
|
camel/loaders/__init__.py
CHANGED
|
@@ -20,6 +20,7 @@ from .firecrawl_reader import Firecrawl
|
|
|
20
20
|
from .jina_url_reader import JinaURLReader
|
|
21
21
|
from .mineru_extractor import MinerU
|
|
22
22
|
from .pandas_reader import PandasReader
|
|
23
|
+
from .scrapegraph_reader import ScrapeGraphAI
|
|
23
24
|
from .unstructured_io import UnstructuredIO
|
|
24
25
|
|
|
25
26
|
__all__ = [
|
|
@@ -34,4 +35,5 @@ __all__ = [
|
|
|
34
35
|
'PandasReader',
|
|
35
36
|
'MinerU',
|
|
36
37
|
'Crawl4AI',
|
|
38
|
+
'ScrapeGraphAI',
|
|
37
39
|
]
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ScrapeGraphAI:
|
|
20
|
+
r"""ScrapeGraphAI allows you to perform AI-powered web scraping and
|
|
21
|
+
searching.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
api_key (Optional[str]): API key for authenticating with the
|
|
25
|
+
ScrapeGraphAI API.
|
|
26
|
+
|
|
27
|
+
References:
|
|
28
|
+
https://scrapegraph.ai/
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(
|
|
32
|
+
self,
|
|
33
|
+
api_key: Optional[str] = None,
|
|
34
|
+
) -> None:
|
|
35
|
+
from scrapegraph_py import Client
|
|
36
|
+
from scrapegraph_py.logger import sgai_logger
|
|
37
|
+
|
|
38
|
+
self._api_key = api_key or os.environ.get("SCRAPEGRAPH_API_KEY")
|
|
39
|
+
sgai_logger.set_logging(level="INFO")
|
|
40
|
+
self.client = Client(api_key=self._api_key)
|
|
41
|
+
|
|
42
|
+
def search(
|
|
43
|
+
self,
|
|
44
|
+
user_prompt: str,
|
|
45
|
+
) -> Dict[str, Any]:
|
|
46
|
+
r"""Perform an AI-powered web search using ScrapeGraphAI.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
user_prompt (str): The search query or instructions.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
Dict[str, Any]: The search results including answer and reference
|
|
53
|
+
URLs.
|
|
54
|
+
|
|
55
|
+
Raises:
|
|
56
|
+
RuntimeError: If the search process fails.
|
|
57
|
+
"""
|
|
58
|
+
try:
|
|
59
|
+
response = self.client.searchscraper(user_prompt=user_prompt)
|
|
60
|
+
return response
|
|
61
|
+
except Exception as e:
|
|
62
|
+
raise RuntimeError(f"Failed to perform search: {e}")
|
|
63
|
+
|
|
64
|
+
def scrape(
|
|
65
|
+
self,
|
|
66
|
+
website_url: str,
|
|
67
|
+
user_prompt: str,
|
|
68
|
+
website_html: Optional[str] = None,
|
|
69
|
+
) -> Dict[str, Any]:
|
|
70
|
+
r"""Perform AI-powered web scraping using ScrapeGraphAI.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
website_url (str): The URL to scrape.
|
|
74
|
+
user_prompt (str): Instructions for what data to extract.
|
|
75
|
+
website_html (Optional[str]): Optional HTML content to use instead
|
|
76
|
+
of fetching from the URL.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
Dict[str, Any]: The scraped data including request ID and result.
|
|
80
|
+
|
|
81
|
+
Raises:
|
|
82
|
+
RuntimeError: If the scrape process fails.
|
|
83
|
+
"""
|
|
84
|
+
try:
|
|
85
|
+
response = self.client.smartscraper(
|
|
86
|
+
website_url=website_url,
|
|
87
|
+
user_prompt=user_prompt,
|
|
88
|
+
website_html=website_html,
|
|
89
|
+
)
|
|
90
|
+
return response
|
|
91
|
+
except Exception as e:
|
|
92
|
+
raise RuntimeError(f"Failed to perform scrape: {e}")
|
|
93
|
+
|
|
94
|
+
def close(self) -> None:
|
|
95
|
+
r"""Close the ScrapeGraphAI client connection."""
|
|
96
|
+
self.client.close()
|
camel/models/__init__.py
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
14
|
from .aiml_model import AIMLModel
|
|
15
15
|
from .anthropic_model import AnthropicModel
|
|
16
|
+
from .aws_bedrock_model import AWSBedrockModel
|
|
16
17
|
from .azure_openai_model import AzureOpenAIModel
|
|
17
18
|
from .base_audio_model import BaseAudioModel
|
|
18
19
|
from .base_model import BaseModelBackend
|
|
@@ -23,6 +24,7 @@ from .gemini_model import GeminiModel
|
|
|
23
24
|
from .groq_model import GroqModel
|
|
24
25
|
from .internlm_model import InternLMModel
|
|
25
26
|
from .litellm_model import LiteLLMModel
|
|
27
|
+
from .lmstudio_model import LMStudioModel
|
|
26
28
|
from .mistral_model import MistralModel
|
|
27
29
|
from .model_factory import ModelFactory
|
|
28
30
|
from .model_manager import ModelManager, ModelProcessingError
|
|
@@ -76,6 +78,7 @@ __all__ = [
|
|
|
76
78
|
'PPIOModel',
|
|
77
79
|
'YiModel',
|
|
78
80
|
'QwenModel',
|
|
81
|
+
'AWSBedrockModel',
|
|
79
82
|
'ModelProcessingError',
|
|
80
83
|
'DeepSeekModel',
|
|
81
84
|
'FishAudioModel',
|
|
@@ -86,4 +89,5 @@ __all__ = [
|
|
|
86
89
|
'BaseAudioModel',
|
|
87
90
|
'SiliconFlowModel',
|
|
88
91
|
'VolcanoModel',
|
|
92
|
+
'LMStudioModel',
|
|
89
93
|
]
|
camel/models/aiml_model.py
CHANGED
|
@@ -12,29 +12,19 @@
|
|
|
12
12
|
# limitations under the License.
|
|
13
13
|
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
14
|
import os
|
|
15
|
-
from typing import Any, Dict,
|
|
16
|
-
|
|
17
|
-
from openai import AsyncOpenAI, AsyncStream, OpenAI, Stream
|
|
18
|
-
from pydantic import BaseModel
|
|
15
|
+
from typing import Any, Dict, Optional, Union
|
|
19
16
|
|
|
20
17
|
from camel.configs import AIML_API_PARAMS, AIMLConfig
|
|
21
|
-
from camel.
|
|
22
|
-
from camel.
|
|
23
|
-
from camel.models.base_model import BaseModelBackend
|
|
24
|
-
from camel.types import (
|
|
25
|
-
ChatCompletion,
|
|
26
|
-
ChatCompletionChunk,
|
|
27
|
-
ModelType,
|
|
28
|
-
)
|
|
18
|
+
from camel.models.openai_compatible_model import OpenAICompatibleModel
|
|
19
|
+
from camel.types import ModelType
|
|
29
20
|
from camel.utils import (
|
|
30
21
|
BaseTokenCounter,
|
|
31
|
-
OpenAITokenCounter,
|
|
32
22
|
api_keys_required,
|
|
33
23
|
)
|
|
34
24
|
|
|
35
25
|
|
|
36
|
-
class AIMLModel(
|
|
37
|
-
r"""AIML API in a unified
|
|
26
|
+
class AIMLModel(OpenAICompatibleModel):
|
|
27
|
+
r"""AIML API in a unified OpenAICompatibleModel interface.
|
|
38
28
|
|
|
39
29
|
Args:
|
|
40
30
|
model_type (Union[ModelType, str]): Model for which a backend is
|
|
@@ -77,87 +67,14 @@ class AIMLModel(BaseModelBackend):
|
|
|
77
67
|
)
|
|
78
68
|
timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
|
|
79
69
|
super().__init__(
|
|
80
|
-
model_type,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
base_url=self._url,
|
|
87
|
-
)
|
|
88
|
-
self._async_client = AsyncOpenAI(
|
|
89
|
-
timeout=self._timeout,
|
|
90
|
-
max_retries=3,
|
|
91
|
-
api_key=self._api_key,
|
|
92
|
-
base_url=self._url,
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
def _prepare_request(
|
|
96
|
-
self,
|
|
97
|
-
messages: List[OpenAIMessage],
|
|
98
|
-
response_format: Optional[Type[BaseModel]] = None,
|
|
99
|
-
tools: Optional[List[Dict[str, Any]]] = None,
|
|
100
|
-
) -> Dict[str, Any]:
|
|
101
|
-
request_config = self.model_config_dict.copy()
|
|
102
|
-
if tools:
|
|
103
|
-
request_config["tools"] = tools
|
|
104
|
-
if response_format:
|
|
105
|
-
# AIML API does not natively support response format
|
|
106
|
-
try_modify_message_with_format(messages[-1], response_format)
|
|
107
|
-
return request_config
|
|
108
|
-
|
|
109
|
-
def _run(
|
|
110
|
-
self,
|
|
111
|
-
messages: List[OpenAIMessage],
|
|
112
|
-
response_format: Optional[Type[BaseModel]] = None,
|
|
113
|
-
tools: Optional[List[Dict[str, Any]]] = None,
|
|
114
|
-
) -> Union[ChatCompletion, Stream[ChatCompletionChunk]]:
|
|
115
|
-
r"""Runs inference of AIML chat completion.
|
|
116
|
-
|
|
117
|
-
Args:
|
|
118
|
-
messages (List[OpenAIMessage]): Message list with the chat history
|
|
119
|
-
in OpenAI API format.
|
|
120
|
-
|
|
121
|
-
Returns:
|
|
122
|
-
Union[ChatCompletion, Stream[ChatCompletionChunk]]:
|
|
123
|
-
`ChatCompletion` in the non-stream mode, or
|
|
124
|
-
`Stream[ChatCompletionChunk]` in the stream mode.
|
|
125
|
-
"""
|
|
126
|
-
request_config = self._prepare_request(
|
|
127
|
-
messages, response_format, tools
|
|
70
|
+
model_type=model_type,
|
|
71
|
+
model_config_dict=model_config_dict,
|
|
72
|
+
api_key=api_key,
|
|
73
|
+
url=url,
|
|
74
|
+
token_counter=token_counter,
|
|
75
|
+
timeout=timeout,
|
|
128
76
|
)
|
|
129
77
|
|
|
130
|
-
response = self._client.chat.completions.create(
|
|
131
|
-
messages=messages, model=self.model_type, **request_config
|
|
132
|
-
)
|
|
133
|
-
return response
|
|
134
|
-
|
|
135
|
-
async def _arun(
|
|
136
|
-
self,
|
|
137
|
-
messages: List[OpenAIMessage],
|
|
138
|
-
response_format: Optional[Type[BaseModel]] = None,
|
|
139
|
-
tools: Optional[List[Dict[str, Any]]] = None,
|
|
140
|
-
) -> Union[ChatCompletion, AsyncStream[ChatCompletionChunk]]:
|
|
141
|
-
request_config = self._prepare_request(
|
|
142
|
-
messages, response_format, tools
|
|
143
|
-
)
|
|
144
|
-
response = await self._async_client.chat.completions.create(
|
|
145
|
-
messages=messages, model=self.model_type, **request_config
|
|
146
|
-
)
|
|
147
|
-
return response
|
|
148
|
-
|
|
149
|
-
@property
|
|
150
|
-
def token_counter(self) -> BaseTokenCounter:
|
|
151
|
-
r"""Initialize the token counter for the model backend.
|
|
152
|
-
|
|
153
|
-
Returns:
|
|
154
|
-
BaseTokenCounter: The token counter following the model's
|
|
155
|
-
tokenization style.
|
|
156
|
-
"""
|
|
157
|
-
if not self._token_counter:
|
|
158
|
-
self._token_counter = OpenAITokenCounter(ModelType.GPT_4O_MINI)
|
|
159
|
-
return self._token_counter
|
|
160
|
-
|
|
161
78
|
def check_model_config(self):
|
|
162
79
|
r"""Check whether the model configuration contains any
|
|
163
80
|
unexpected arguments to AIML API.
|
|
@@ -172,13 +89,3 @@ class AIMLModel(BaseModelBackend):
|
|
|
172
89
|
f"Unexpected argument `{param}` is "
|
|
173
90
|
"input into AIML model backend."
|
|
174
91
|
)
|
|
175
|
-
|
|
176
|
-
@property
|
|
177
|
-
def stream(self) -> bool:
|
|
178
|
-
"""Returns whether the model is in stream mode, which sends partial
|
|
179
|
-
results each time.
|
|
180
|
-
|
|
181
|
-
Returns:
|
|
182
|
-
bool: Whether the model is in stream mode.
|
|
183
|
-
"""
|
|
184
|
-
return self.model_config_dict.get("stream", False)
|