camel-ai 0.2.67__py3-none-any.whl → 0.2.80a2__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.
- camel/__init__.py +1 -1
- camel/agents/_types.py +6 -2
- camel/agents/_utils.py +38 -0
- camel/agents/chat_agent.py +4014 -410
- camel/agents/mcp_agent.py +30 -27
- camel/agents/repo_agent.py +2 -1
- camel/benchmarks/browsecomp.py +6 -6
- camel/configs/__init__.py +15 -0
- camel/configs/aihubmix_config.py +88 -0
- camel/configs/amd_config.py +70 -0
- camel/configs/cometapi_config.py +104 -0
- camel/configs/minimax_config.py +93 -0
- camel/configs/nebius_config.py +103 -0
- camel/configs/vllm_config.py +2 -0
- camel/data_collectors/alpaca_collector.py +15 -6
- camel/datagen/self_improving_cot.py +1 -1
- camel/datasets/base_generator.py +39 -10
- camel/environments/__init__.py +12 -0
- camel/environments/rlcards_env.py +860 -0
- camel/environments/single_step.py +28 -3
- camel/environments/tic_tac_toe.py +1 -1
- camel/interpreters/__init__.py +2 -0
- camel/interpreters/docker/Dockerfile +4 -16
- camel/interpreters/docker_interpreter.py +3 -2
- camel/interpreters/e2b_interpreter.py +34 -1
- camel/interpreters/internal_python_interpreter.py +51 -2
- camel/interpreters/microsandbox_interpreter.py +395 -0
- camel/loaders/__init__.py +11 -2
- camel/loaders/base_loader.py +85 -0
- camel/loaders/chunkr_reader.py +9 -0
- camel/loaders/firecrawl_reader.py +4 -4
- camel/logger.py +1 -1
- camel/memories/agent_memories.py +84 -1
- camel/memories/base.py +34 -0
- camel/memories/blocks/chat_history_block.py +122 -4
- camel/memories/blocks/vectordb_block.py +8 -1
- camel/memories/context_creators/score_based.py +29 -237
- camel/memories/records.py +88 -8
- camel/messages/base.py +166 -40
- camel/messages/func_message.py +32 -5
- camel/models/__init__.py +10 -0
- camel/models/aihubmix_model.py +83 -0
- camel/models/aiml_model.py +1 -16
- camel/models/amd_model.py +101 -0
- camel/models/anthropic_model.py +117 -18
- camel/models/aws_bedrock_model.py +2 -33
- camel/models/azure_openai_model.py +205 -91
- camel/models/base_audio_model.py +3 -1
- camel/models/base_model.py +189 -24
- camel/models/cohere_model.py +5 -17
- camel/models/cometapi_model.py +83 -0
- camel/models/crynux_model.py +1 -16
- camel/models/deepseek_model.py +6 -16
- camel/models/fish_audio_model.py +6 -0
- camel/models/gemini_model.py +71 -20
- camel/models/groq_model.py +1 -17
- camel/models/internlm_model.py +1 -16
- camel/models/litellm_model.py +49 -32
- camel/models/lmstudio_model.py +1 -17
- camel/models/minimax_model.py +83 -0
- camel/models/mistral_model.py +1 -16
- camel/models/model_factory.py +27 -1
- camel/models/model_manager.py +24 -6
- camel/models/modelscope_model.py +1 -16
- camel/models/moonshot_model.py +185 -19
- camel/models/nebius_model.py +83 -0
- camel/models/nemotron_model.py +0 -5
- camel/models/netmind_model.py +1 -16
- camel/models/novita_model.py +1 -16
- camel/models/nvidia_model.py +1 -16
- camel/models/ollama_model.py +4 -19
- camel/models/openai_compatible_model.py +171 -46
- camel/models/openai_model.py +205 -77
- camel/models/openrouter_model.py +1 -17
- camel/models/ppio_model.py +1 -16
- camel/models/qianfan_model.py +1 -16
- camel/models/qwen_model.py +1 -16
- camel/models/reka_model.py +1 -16
- camel/models/samba_model.py +34 -47
- camel/models/sglang_model.py +64 -31
- camel/models/siliconflow_model.py +1 -16
- camel/models/stub_model.py +0 -4
- camel/models/togetherai_model.py +1 -16
- camel/models/vllm_model.py +1 -16
- camel/models/volcano_model.py +0 -17
- camel/models/watsonx_model.py +1 -16
- camel/models/yi_model.py +1 -16
- camel/models/zhipuai_model.py +60 -16
- camel/parsers/__init__.py +18 -0
- camel/parsers/mcp_tool_call_parser.py +176 -0
- camel/retrievers/auto_retriever.py +1 -0
- camel/runtimes/configs.py +11 -11
- camel/runtimes/daytona_runtime.py +15 -16
- camel/runtimes/docker_runtime.py +6 -6
- camel/runtimes/remote_http_runtime.py +5 -5
- camel/services/agent_openapi_server.py +380 -0
- camel/societies/__init__.py +2 -0
- camel/societies/role_playing.py +26 -28
- camel/societies/workforce/__init__.py +2 -0
- camel/societies/workforce/events.py +122 -0
- camel/societies/workforce/prompts.py +249 -38
- camel/societies/workforce/role_playing_worker.py +82 -20
- camel/societies/workforce/single_agent_worker.py +634 -34
- camel/societies/workforce/structured_output_handler.py +512 -0
- camel/societies/workforce/task_channel.py +169 -23
- camel/societies/workforce/utils.py +176 -9
- camel/societies/workforce/worker.py +77 -23
- camel/societies/workforce/workflow_memory_manager.py +772 -0
- camel/societies/workforce/workforce.py +3168 -478
- camel/societies/workforce/workforce_callback.py +74 -0
- camel/societies/workforce/workforce_logger.py +203 -175
- camel/societies/workforce/workforce_metrics.py +33 -0
- camel/storages/__init__.py +4 -0
- camel/storages/key_value_storages/json.py +15 -2
- camel/storages/key_value_storages/mem0_cloud.py +48 -47
- camel/storages/object_storages/google_cloud.py +1 -1
- camel/storages/vectordb_storages/__init__.py +6 -0
- camel/storages/vectordb_storages/chroma.py +731 -0
- camel/storages/vectordb_storages/oceanbase.py +13 -13
- camel/storages/vectordb_storages/pgvector.py +349 -0
- camel/storages/vectordb_storages/qdrant.py +3 -3
- camel/storages/vectordb_storages/surreal.py +365 -0
- camel/storages/vectordb_storages/tidb.py +8 -6
- camel/tasks/task.py +244 -27
- camel/toolkits/__init__.py +46 -8
- camel/toolkits/aci_toolkit.py +64 -19
- camel/toolkits/arxiv_toolkit.py +6 -6
- camel/toolkits/base.py +63 -5
- camel/toolkits/code_execution.py +28 -1
- camel/toolkits/context_summarizer_toolkit.py +684 -0
- camel/toolkits/craw4ai_toolkit.py +93 -0
- camel/toolkits/dappier_toolkit.py +10 -6
- camel/toolkits/dingtalk.py +1135 -0
- camel/toolkits/edgeone_pages_mcp_toolkit.py +49 -0
- camel/toolkits/excel_toolkit.py +901 -67
- camel/toolkits/file_toolkit.py +1402 -0
- camel/toolkits/function_tool.py +30 -6
- camel/toolkits/github_toolkit.py +107 -20
- camel/toolkits/gmail_toolkit.py +1839 -0
- camel/toolkits/google_calendar_toolkit.py +38 -4
- camel/toolkits/google_drive_mcp_toolkit.py +54 -0
- camel/toolkits/human_toolkit.py +34 -10
- camel/toolkits/hybrid_browser_toolkit/__init__.py +18 -0
- camel/toolkits/hybrid_browser_toolkit/config_loader.py +185 -0
- camel/toolkits/hybrid_browser_toolkit/hybrid_browser_toolkit.py +246 -0
- camel/toolkits/hybrid_browser_toolkit/hybrid_browser_toolkit_ts.py +1973 -0
- camel/toolkits/hybrid_browser_toolkit/installer.py +203 -0
- camel/toolkits/hybrid_browser_toolkit/ts/package-lock.json +3749 -0
- camel/toolkits/hybrid_browser_toolkit/ts/package.json +32 -0
- camel/toolkits/hybrid_browser_toolkit/ts/src/browser-scripts.js +125 -0
- camel/toolkits/hybrid_browser_toolkit/ts/src/browser-session.ts +1815 -0
- camel/toolkits/hybrid_browser_toolkit/ts/src/config-loader.ts +233 -0
- camel/toolkits/hybrid_browser_toolkit/ts/src/hybrid-browser-toolkit.ts +590 -0
- camel/toolkits/hybrid_browser_toolkit/ts/src/index.ts +7 -0
- camel/toolkits/hybrid_browser_toolkit/ts/src/parent-child-filter.ts +226 -0
- camel/toolkits/hybrid_browser_toolkit/ts/src/snapshot-parser.ts +219 -0
- camel/toolkits/hybrid_browser_toolkit/ts/src/som-screenshot-injected.ts +543 -0
- camel/toolkits/hybrid_browser_toolkit/ts/src/types.ts +130 -0
- camel/toolkits/hybrid_browser_toolkit/ts/tsconfig.json +26 -0
- camel/toolkits/hybrid_browser_toolkit/ts/websocket-server.js +319 -0
- camel/toolkits/hybrid_browser_toolkit/ws_wrapper.py +1032 -0
- camel/toolkits/hybrid_browser_toolkit_py/__init__.py +17 -0
- camel/toolkits/hybrid_browser_toolkit_py/actions.py +575 -0
- camel/toolkits/hybrid_browser_toolkit_py/agent.py +311 -0
- camel/toolkits/hybrid_browser_toolkit_py/browser_session.py +787 -0
- camel/toolkits/hybrid_browser_toolkit_py/config_loader.py +490 -0
- camel/toolkits/hybrid_browser_toolkit_py/hybrid_browser_toolkit.py +2390 -0
- camel/toolkits/hybrid_browser_toolkit_py/snapshot.py +233 -0
- camel/toolkits/hybrid_browser_toolkit_py/stealth_script.js +0 -0
- camel/toolkits/hybrid_browser_toolkit_py/unified_analyzer.js +1043 -0
- camel/toolkits/image_generation_toolkit.py +390 -0
- camel/toolkits/jina_reranker_toolkit.py +3 -4
- camel/toolkits/klavis_toolkit.py +5 -1
- camel/toolkits/markitdown_toolkit.py +104 -0
- camel/toolkits/math_toolkit.py +64 -10
- camel/toolkits/mcp_toolkit.py +370 -45
- camel/toolkits/memory_toolkit.py +5 -1
- camel/toolkits/message_agent_toolkit.py +608 -0
- camel/toolkits/message_integration.py +724 -0
- camel/toolkits/minimax_mcp_toolkit.py +195 -0
- camel/toolkits/note_taking_toolkit.py +277 -0
- camel/toolkits/notion_mcp_toolkit.py +224 -0
- camel/toolkits/openbb_toolkit.py +5 -1
- camel/toolkits/origene_mcp_toolkit.py +56 -0
- camel/toolkits/playwright_mcp_toolkit.py +12 -31
- camel/toolkits/pptx_toolkit.py +25 -12
- camel/toolkits/resend_toolkit.py +168 -0
- camel/toolkits/screenshot_toolkit.py +213 -0
- camel/toolkits/search_toolkit.py +437 -142
- camel/toolkits/slack_toolkit.py +104 -50
- camel/toolkits/sympy_toolkit.py +1 -1
- camel/toolkits/task_planning_toolkit.py +3 -3
- camel/toolkits/terminal_toolkit/__init__.py +18 -0
- camel/toolkits/terminal_toolkit/terminal_toolkit.py +957 -0
- camel/toolkits/terminal_toolkit/utils.py +532 -0
- camel/toolkits/thinking_toolkit.py +1 -1
- camel/toolkits/vertex_ai_veo_toolkit.py +590 -0
- camel/toolkits/video_analysis_toolkit.py +106 -26
- camel/toolkits/video_download_toolkit.py +17 -14
- camel/toolkits/web_deploy_toolkit.py +1219 -0
- camel/toolkits/wechat_official_toolkit.py +483 -0
- camel/toolkits/zapier_toolkit.py +5 -1
- camel/types/__init__.py +2 -2
- camel/types/agents/tool_calling_record.py +4 -1
- camel/types/enums.py +316 -40
- camel/types/openai_types.py +2 -2
- camel/types/unified_model_type.py +31 -4
- camel/utils/commons.py +36 -5
- camel/utils/constants.py +3 -0
- camel/utils/context_utils.py +1003 -0
- camel/utils/mcp.py +138 -4
- camel/utils/mcp_client.py +45 -1
- camel/utils/message_summarizer.py +148 -0
- camel/utils/token_counting.py +43 -20
- camel/utils/tool_result.py +44 -0
- {camel_ai-0.2.67.dist-info → camel_ai-0.2.80a2.dist-info}/METADATA +296 -85
- {camel_ai-0.2.67.dist-info → camel_ai-0.2.80a2.dist-info}/RECORD +219 -146
- camel/loaders/pandas_reader.py +0 -368
- camel/toolkits/dalle_toolkit.py +0 -175
- camel/toolkits/file_write_toolkit.py +0 -444
- camel/toolkits/openai_agent_toolkit.py +0 -135
- camel/toolkits/terminal_toolkit.py +0 -1037
- {camel_ai-0.2.67.dist-info → camel_ai-0.2.80a2.dist-info}/WHEEL +0 -0
- {camel_ai-0.2.67.dist-info → camel_ai-0.2.80a2.dist-info}/licenses/LICENSE +0 -0
camel/loaders/pandas_reader.py
DELETED
|
@@ -1,368 +0,0 @@
|
|
|
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 functools import wraps
|
|
15
|
-
from pathlib import Path
|
|
16
|
-
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
|
|
17
|
-
|
|
18
|
-
if TYPE_CHECKING:
|
|
19
|
-
from pandas import DataFrame
|
|
20
|
-
from pandasai import SmartDataframe
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def check_suffix(valid_suffixs: List[str]) -> Callable:
|
|
24
|
-
r"""A decorator to check the file suffix of a given file path.
|
|
25
|
-
|
|
26
|
-
Args:
|
|
27
|
-
valid_suffix (str): The required file suffix.
|
|
28
|
-
|
|
29
|
-
Returns:
|
|
30
|
-
Callable: The decorator function.
|
|
31
|
-
"""
|
|
32
|
-
|
|
33
|
-
def decorator(func: Callable):
|
|
34
|
-
@wraps(func)
|
|
35
|
-
def wrapper(
|
|
36
|
-
self, file_path: str, *args: Any, **kwargs: Dict[str, Any]
|
|
37
|
-
) -> "DataFrame":
|
|
38
|
-
suffix = Path(file_path).suffix
|
|
39
|
-
if suffix not in valid_suffixs:
|
|
40
|
-
raise ValueError(
|
|
41
|
-
f"Only {', '.join(valid_suffixs)} files are supported"
|
|
42
|
-
)
|
|
43
|
-
return func(self, file_path, *args, **kwargs)
|
|
44
|
-
|
|
45
|
-
return wrapper
|
|
46
|
-
|
|
47
|
-
return decorator
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
class PandasReader:
|
|
51
|
-
def __init__(self, config: Optional[Dict[str, Any]] = None) -> None:
|
|
52
|
-
r"""Initializes the PandasReader class.
|
|
53
|
-
|
|
54
|
-
Args:
|
|
55
|
-
config (Optional[Dict[str, Any]], optional): The configuration
|
|
56
|
-
dictionary that can include LLM API settings for LLM-based
|
|
57
|
-
processing. If not provided, no LLM will be configured by
|
|
58
|
-
default. You can customize the LLM configuration by providing
|
|
59
|
-
a 'llm' key in the config dictionary. (default: :obj:`None`)
|
|
60
|
-
"""
|
|
61
|
-
self.config = config or {}
|
|
62
|
-
|
|
63
|
-
self.__LOADER = {
|
|
64
|
-
".csv": self.read_csv,
|
|
65
|
-
".xlsx": self.read_excel,
|
|
66
|
-
".xls": self.read_excel,
|
|
67
|
-
".json": self.read_json,
|
|
68
|
-
".parquet": self.read_parquet,
|
|
69
|
-
".sql": self.read_sql,
|
|
70
|
-
".html": self.read_html,
|
|
71
|
-
".feather": self.read_feather,
|
|
72
|
-
".dta": self.read_stata,
|
|
73
|
-
".sas": self.read_sas,
|
|
74
|
-
".pkl": self.read_pickle,
|
|
75
|
-
".h5": self.read_hdf,
|
|
76
|
-
".orc": self.read_orc,
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
def load(
|
|
80
|
-
self,
|
|
81
|
-
data: Union["DataFrame", str],
|
|
82
|
-
*args: Any,
|
|
83
|
-
**kwargs: Dict[str, Any],
|
|
84
|
-
) -> Union["DataFrame", "SmartDataframe"]:
|
|
85
|
-
r"""Loads a file or DataFrame and returns a DataFrame or
|
|
86
|
-
SmartDataframe object.
|
|
87
|
-
|
|
88
|
-
If an LLM is configured in the config dictionary, a SmartDataframe
|
|
89
|
-
will be returned, otherwise a regular pandas DataFrame will be
|
|
90
|
-
returned.
|
|
91
|
-
|
|
92
|
-
args:
|
|
93
|
-
data (Union[DataFrame, str]): The data to load.
|
|
94
|
-
*args (Any): Additional positional arguments.
|
|
95
|
-
**kwargs (Dict[str, Any]): Additional keyword arguments.
|
|
96
|
-
|
|
97
|
-
Returns:
|
|
98
|
-
Union[DataFrame, SmartDataframe]: The DataFrame or SmartDataframe
|
|
99
|
-
object.
|
|
100
|
-
"""
|
|
101
|
-
from pandas import DataFrame
|
|
102
|
-
|
|
103
|
-
# Load the data into a pandas DataFrame
|
|
104
|
-
if isinstance(data, DataFrame):
|
|
105
|
-
df = data
|
|
106
|
-
else:
|
|
107
|
-
file_path = str(data)
|
|
108
|
-
path = Path(file_path)
|
|
109
|
-
if not file_path.startswith("http") and not path.exists():
|
|
110
|
-
raise FileNotFoundError(f"File {file_path} not found")
|
|
111
|
-
if path.suffix in self.__LOADER:
|
|
112
|
-
df = self.__LOADER[path.suffix](file_path, *args, **kwargs) # type: ignore[operator]
|
|
113
|
-
else:
|
|
114
|
-
raise ValueError(f"Unsupported file format: {path.suffix}")
|
|
115
|
-
|
|
116
|
-
# If an LLM is configured, return a SmartDataframe, otherwise return a
|
|
117
|
-
# regular DataFrame
|
|
118
|
-
if "llm" in self.config:
|
|
119
|
-
from pandasai import SmartDataframe
|
|
120
|
-
|
|
121
|
-
return SmartDataframe(df, config=self.config)
|
|
122
|
-
else:
|
|
123
|
-
return df
|
|
124
|
-
|
|
125
|
-
@check_suffix([".csv"])
|
|
126
|
-
def read_csv(
|
|
127
|
-
self, file_path: str, *args: Any, **kwargs: Dict[str, Any]
|
|
128
|
-
) -> "DataFrame":
|
|
129
|
-
r"""Reads a CSV file and returns a DataFrame.
|
|
130
|
-
|
|
131
|
-
Args:
|
|
132
|
-
file_path (str): The path to the CSV file.
|
|
133
|
-
*args (Any): Additional positional arguments.
|
|
134
|
-
**kwargs (Dict[str, Any]): Additional keyword arguments.
|
|
135
|
-
|
|
136
|
-
Returns:
|
|
137
|
-
DataFrame: The DataFrame object.
|
|
138
|
-
"""
|
|
139
|
-
import pandas as pd
|
|
140
|
-
|
|
141
|
-
return pd.read_csv(file_path, *args, **kwargs)
|
|
142
|
-
|
|
143
|
-
@check_suffix([".xlsx", ".xls"])
|
|
144
|
-
def read_excel(
|
|
145
|
-
self, file_path: str, *args: Any, **kwargs: Dict[str, Any]
|
|
146
|
-
) -> "DataFrame":
|
|
147
|
-
r"""Reads an Excel file and returns a DataFrame.
|
|
148
|
-
|
|
149
|
-
Args:
|
|
150
|
-
file_path (str): The path to the Excel file.
|
|
151
|
-
*args (Any): Additional positional arguments.
|
|
152
|
-
**kwargs (Dict[str, Any]): Additional keyword arguments.
|
|
153
|
-
|
|
154
|
-
Returns:
|
|
155
|
-
DataFrame: The DataFrame object.
|
|
156
|
-
"""
|
|
157
|
-
import pandas as pd
|
|
158
|
-
|
|
159
|
-
return pd.read_excel(file_path, *args, **kwargs)
|
|
160
|
-
|
|
161
|
-
@check_suffix([".json"])
|
|
162
|
-
def read_json(
|
|
163
|
-
self, file_path: str, *args: Any, **kwargs: Dict[str, Any]
|
|
164
|
-
) -> "DataFrame":
|
|
165
|
-
r"""Reads a JSON file and returns a DataFrame.
|
|
166
|
-
|
|
167
|
-
Args:
|
|
168
|
-
file_path (str): The path to the JSON file.
|
|
169
|
-
*args (Any): Additional positional arguments.
|
|
170
|
-
**kwargs (Dict[str, Any]): Additional keyword arguments.
|
|
171
|
-
|
|
172
|
-
Returns:
|
|
173
|
-
DataFrame: The DataFrame object.
|
|
174
|
-
"""
|
|
175
|
-
import pandas as pd
|
|
176
|
-
|
|
177
|
-
return pd.read_json(file_path, *args, **kwargs)
|
|
178
|
-
|
|
179
|
-
@check_suffix([".parquet"])
|
|
180
|
-
def read_parquet(
|
|
181
|
-
self, file_path: str, *args: Any, **kwargs: Dict[str, Any]
|
|
182
|
-
) -> "DataFrame":
|
|
183
|
-
r"""Reads a Parquet file and returns a DataFrame.
|
|
184
|
-
|
|
185
|
-
Args:
|
|
186
|
-
file_path (str): The path to the Parquet file.
|
|
187
|
-
*args (Any): Additional positional arguments.
|
|
188
|
-
**kwargs (Dict[str, Any]): Additional keyword arguments.
|
|
189
|
-
|
|
190
|
-
Returns:
|
|
191
|
-
DataFrame: The DataFrame object.
|
|
192
|
-
"""
|
|
193
|
-
import pandas as pd
|
|
194
|
-
|
|
195
|
-
return pd.read_parquet(file_path, *args, **kwargs)
|
|
196
|
-
|
|
197
|
-
def read_sql(self, *args: Any, **kwargs: Dict[str, Any]) -> "DataFrame":
|
|
198
|
-
r"""Reads a SQL file and returns a DataFrame.
|
|
199
|
-
|
|
200
|
-
Args:
|
|
201
|
-
*args (Any): Additional positional arguments.
|
|
202
|
-
**kwargs (Dict[str, Any]): Additional keyword arguments.
|
|
203
|
-
|
|
204
|
-
Returns:
|
|
205
|
-
DataFrame: The DataFrame object.
|
|
206
|
-
"""
|
|
207
|
-
import pandas as pd
|
|
208
|
-
|
|
209
|
-
return pd.read_sql(*args, **kwargs)
|
|
210
|
-
|
|
211
|
-
def read_table(
|
|
212
|
-
self, file_path: str, *args: Any, **kwargs: Dict[str, Any]
|
|
213
|
-
) -> "DataFrame":
|
|
214
|
-
r"""Reads a table and returns a DataFrame.
|
|
215
|
-
|
|
216
|
-
Args:
|
|
217
|
-
file_path (str): The path to the table.
|
|
218
|
-
*args (Any): Additional positional arguments.
|
|
219
|
-
**kwargs (Dict[str, Any]): Additional keyword arguments.
|
|
220
|
-
|
|
221
|
-
Returns:
|
|
222
|
-
DataFrame: The DataFrame object.
|
|
223
|
-
"""
|
|
224
|
-
import pandas as pd
|
|
225
|
-
|
|
226
|
-
return pd.read_table(file_path, *args, **kwargs)
|
|
227
|
-
|
|
228
|
-
def read_clipboard(
|
|
229
|
-
self, *args: Any, **kwargs: Dict[str, Any]
|
|
230
|
-
) -> "DataFrame":
|
|
231
|
-
r"""Reads a clipboard and returns a DataFrame.
|
|
232
|
-
|
|
233
|
-
Args:
|
|
234
|
-
*args (Any): Additional positional arguments.
|
|
235
|
-
**kwargs (Dict[str, Any]): Additional keyword arguments.
|
|
236
|
-
|
|
237
|
-
Returns:
|
|
238
|
-
DataFrame: The DataFrame object.
|
|
239
|
-
"""
|
|
240
|
-
import pandas as pd
|
|
241
|
-
|
|
242
|
-
return pd.read_clipboard(*args, **kwargs)
|
|
243
|
-
|
|
244
|
-
@check_suffix([".html"])
|
|
245
|
-
def read_html(
|
|
246
|
-
self, file_path: str, *args: Any, **kwargs: Dict[str, Any]
|
|
247
|
-
) -> "DataFrame":
|
|
248
|
-
r"""Reads an HTML file and returns a DataFrame.
|
|
249
|
-
|
|
250
|
-
Args:
|
|
251
|
-
file_path (str): The path to the HTML file.
|
|
252
|
-
*args (Any): Additional positional arguments.
|
|
253
|
-
**kwargs (Dict[str, Any]): Additional keyword arguments.
|
|
254
|
-
|
|
255
|
-
Returns:
|
|
256
|
-
DataFrame: The DataFrame object.
|
|
257
|
-
"""
|
|
258
|
-
import pandas as pd
|
|
259
|
-
|
|
260
|
-
return pd.read_html(file_path, *args, **kwargs)
|
|
261
|
-
|
|
262
|
-
@check_suffix([".feather"])
|
|
263
|
-
def read_feather(
|
|
264
|
-
self, file_path: str, *args: Any, **kwargs: Dict[str, Any]
|
|
265
|
-
) -> "DataFrame":
|
|
266
|
-
r"""Reads a Feather file and returns a DataFrame.
|
|
267
|
-
|
|
268
|
-
Args:
|
|
269
|
-
file_path (str): The path to the Feather file.
|
|
270
|
-
*args (Any): Additional positional arguments.
|
|
271
|
-
**kwargs (Dict[str, Any]): Additional keyword arguments.
|
|
272
|
-
|
|
273
|
-
Returns:
|
|
274
|
-
DataFrame: The DataFrame object.
|
|
275
|
-
"""
|
|
276
|
-
import pandas as pd
|
|
277
|
-
|
|
278
|
-
return pd.read_feather(file_path, *args, **kwargs)
|
|
279
|
-
|
|
280
|
-
@check_suffix([".dta"])
|
|
281
|
-
def read_stata(
|
|
282
|
-
self, file_path: str, *args: Any, **kwargs: Dict[str, Any]
|
|
283
|
-
) -> "DataFrame":
|
|
284
|
-
r"""Reads a Stata file and returns a DataFrame.
|
|
285
|
-
|
|
286
|
-
Args:
|
|
287
|
-
file_path (str): The path to the Stata file.
|
|
288
|
-
*args (Any): Additional positional arguments.
|
|
289
|
-
**kwargs (Dict[str, Any]): Additional keyword arguments.
|
|
290
|
-
|
|
291
|
-
Returns:
|
|
292
|
-
DataFrame: The DataFrame object.
|
|
293
|
-
"""
|
|
294
|
-
import pandas as pd
|
|
295
|
-
|
|
296
|
-
return pd.read_stata(file_path, *args, **kwargs)
|
|
297
|
-
|
|
298
|
-
@check_suffix([".sas"])
|
|
299
|
-
def read_sas(
|
|
300
|
-
self, file_path: str, *args: Any, **kwargs: Dict[str, Any]
|
|
301
|
-
) -> "DataFrame":
|
|
302
|
-
r"""Reads a SAS file and returns a DataFrame.
|
|
303
|
-
|
|
304
|
-
Args:
|
|
305
|
-
file_path (str): The path to the SAS file.
|
|
306
|
-
*args (Any): Additional positional arguments.
|
|
307
|
-
**kwargs (Dict[str, Any]): Additional keyword arguments.
|
|
308
|
-
|
|
309
|
-
Returns:
|
|
310
|
-
DataFrame: The DataFrame object.
|
|
311
|
-
"""
|
|
312
|
-
import pandas as pd
|
|
313
|
-
|
|
314
|
-
return pd.read_sas(file_path, *args, **kwargs)
|
|
315
|
-
|
|
316
|
-
@check_suffix([".pkl"])
|
|
317
|
-
def read_pickle(
|
|
318
|
-
self, file_path: str, *args: Any, **kwargs: Dict[str, Any]
|
|
319
|
-
) -> "DataFrame":
|
|
320
|
-
r"""Reads a Pickle file and returns a DataFrame.
|
|
321
|
-
|
|
322
|
-
Args:
|
|
323
|
-
file_path (str): The path to the Pickle file.
|
|
324
|
-
*args (Any): Additional positional arguments.
|
|
325
|
-
**kwargs (Dict[str, Any]): Additional keyword arguments.
|
|
326
|
-
|
|
327
|
-
Returns:
|
|
328
|
-
DataFrame: The DataFrame object.
|
|
329
|
-
"""
|
|
330
|
-
import pandas as pd
|
|
331
|
-
|
|
332
|
-
return pd.read_pickle(file_path, *args, **kwargs)
|
|
333
|
-
|
|
334
|
-
@check_suffix([".h5"])
|
|
335
|
-
def read_hdf(
|
|
336
|
-
self, file_path: str, *args: Any, **kwargs: Dict[str, Any]
|
|
337
|
-
) -> "DataFrame":
|
|
338
|
-
r"""Reads an HDF file and returns a DataFrame.
|
|
339
|
-
|
|
340
|
-
Args:
|
|
341
|
-
file_path (str): The path to the HDF file.
|
|
342
|
-
*args (Any): Additional positional arguments.
|
|
343
|
-
**kwargs (Dict[str, Any]): Additional keyword arguments.
|
|
344
|
-
|
|
345
|
-
Returns:
|
|
346
|
-
DataFrame: The DataFrame object.
|
|
347
|
-
"""
|
|
348
|
-
import pandas as pd
|
|
349
|
-
|
|
350
|
-
return pd.read_hdf(file_path, *args, **kwargs)
|
|
351
|
-
|
|
352
|
-
@check_suffix([".orc"])
|
|
353
|
-
def read_orc(
|
|
354
|
-
self, file_path: str, *args: Any, **kwargs: Dict[str, Any]
|
|
355
|
-
) -> "DataFrame":
|
|
356
|
-
r"""Reads an ORC file and returns a DataFrame.
|
|
357
|
-
|
|
358
|
-
Args:
|
|
359
|
-
file_path (str): The path to the ORC file.
|
|
360
|
-
*args (Any): Additional positional arguments.
|
|
361
|
-
**kwargs (Dict[str, Any]): Additional keyword arguments.
|
|
362
|
-
|
|
363
|
-
Returns:
|
|
364
|
-
DataFrame: The DataFrame object.
|
|
365
|
-
"""
|
|
366
|
-
import pandas as pd
|
|
367
|
-
|
|
368
|
-
return pd.read_orc(file_path, *args, **kwargs)
|
camel/toolkits/dalle_toolkit.py
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
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
|
-
# Enables postponed evaluation of annotations (for string-based type hints)
|
|
16
|
-
from __future__ import annotations
|
|
17
|
-
|
|
18
|
-
import base64
|
|
19
|
-
import os
|
|
20
|
-
import uuid
|
|
21
|
-
from io import BytesIO
|
|
22
|
-
from typing import List, Optional
|
|
23
|
-
|
|
24
|
-
from openai import OpenAI
|
|
25
|
-
from PIL import Image
|
|
26
|
-
|
|
27
|
-
from camel.logger import get_logger
|
|
28
|
-
from camel.toolkits import FunctionTool
|
|
29
|
-
from camel.toolkits.base import BaseToolkit
|
|
30
|
-
from camel.utils import MCPServer
|
|
31
|
-
|
|
32
|
-
logger = get_logger(__name__)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
@MCPServer()
|
|
36
|
-
class DalleToolkit(BaseToolkit):
|
|
37
|
-
r"""A class representing a toolkit for image generation using OpenAI's
|
|
38
|
-
DALL-E model.
|
|
39
|
-
"""
|
|
40
|
-
|
|
41
|
-
def __init__(
|
|
42
|
-
self,
|
|
43
|
-
timeout: Optional[float] = None,
|
|
44
|
-
):
|
|
45
|
-
r"""Initializes a new instance of the DalleToolkit class.
|
|
46
|
-
|
|
47
|
-
Args:
|
|
48
|
-
timeout (Optional[float]): The timeout value for API requests
|
|
49
|
-
in seconds. If None, no timeout is applied.
|
|
50
|
-
(default: :obj:`None`)
|
|
51
|
-
"""
|
|
52
|
-
super().__init__(timeout=timeout)
|
|
53
|
-
|
|
54
|
-
def base64_to_image(self, base64_string: str) -> Optional[Image.Image]:
|
|
55
|
-
r"""Converts a base64 encoded string into a PIL Image object.
|
|
56
|
-
|
|
57
|
-
Args:
|
|
58
|
-
base64_string (str): The base64 encoded string of the image.
|
|
59
|
-
|
|
60
|
-
Returns:
|
|
61
|
-
Optional[Image.Image]: The PIL Image object or None if conversion
|
|
62
|
-
fails.
|
|
63
|
-
"""
|
|
64
|
-
try:
|
|
65
|
-
# Decode the base64 string to get the image data
|
|
66
|
-
image_data = base64.b64decode(base64_string)
|
|
67
|
-
# Create a memory buffer for the image data
|
|
68
|
-
image_buffer = BytesIO(image_data)
|
|
69
|
-
# Open the image using the PIL library
|
|
70
|
-
image = Image.open(image_buffer)
|
|
71
|
-
return image
|
|
72
|
-
except Exception as e:
|
|
73
|
-
error_msg = (
|
|
74
|
-
f"An error occurred while converting base64 to image: {e}"
|
|
75
|
-
)
|
|
76
|
-
logger.error(error_msg)
|
|
77
|
-
return None
|
|
78
|
-
|
|
79
|
-
def image_path_to_base64(self, image_path: str) -> str:
|
|
80
|
-
r"""Converts the file path of an image to a Base64 encoded string.
|
|
81
|
-
|
|
82
|
-
Args:
|
|
83
|
-
image_path (str): The path to the image file.
|
|
84
|
-
|
|
85
|
-
Returns:
|
|
86
|
-
str: A Base64 encoded string representing the content of the image
|
|
87
|
-
file.
|
|
88
|
-
"""
|
|
89
|
-
try:
|
|
90
|
-
with open(image_path, "rb") as image_file:
|
|
91
|
-
return base64.b64encode(image_file.read()).decode('utf-8')
|
|
92
|
-
except Exception as e:
|
|
93
|
-
error_msg = (
|
|
94
|
-
f"An error occurred while converting image path to base64: {e}"
|
|
95
|
-
)
|
|
96
|
-
logger.error(error_msg)
|
|
97
|
-
return error_msg
|
|
98
|
-
|
|
99
|
-
def image_to_base64(self, image: Image.Image) -> str:
|
|
100
|
-
r"""Converts an image into a base64-encoded string.
|
|
101
|
-
|
|
102
|
-
This function takes an image object as input, encodes the image into a
|
|
103
|
-
PNG format base64 string, and returns it.
|
|
104
|
-
If the encoding process encounters an error, it prints the error
|
|
105
|
-
message and returns None.
|
|
106
|
-
|
|
107
|
-
Args:
|
|
108
|
-
image: The image object to be encoded, supports any image format
|
|
109
|
-
that can be saved in PNG format.
|
|
110
|
-
|
|
111
|
-
Returns:
|
|
112
|
-
str: A base64-encoded string of the image.
|
|
113
|
-
"""
|
|
114
|
-
try:
|
|
115
|
-
with BytesIO() as buffered_image:
|
|
116
|
-
image.save(buffered_image, format="PNG")
|
|
117
|
-
buffered_image.seek(0)
|
|
118
|
-
image_bytes = buffered_image.read()
|
|
119
|
-
base64_str = base64.b64encode(image_bytes).decode('utf-8')
|
|
120
|
-
return base64_str
|
|
121
|
-
except Exception as e:
|
|
122
|
-
error_msg = f"An error occurred: {e}"
|
|
123
|
-
logger.error(error_msg)
|
|
124
|
-
return error_msg
|
|
125
|
-
|
|
126
|
-
def get_dalle_img(self, prompt: str, image_dir: str = "img") -> str:
|
|
127
|
-
r"""Generate an image using OpenAI's DALL-E model.
|
|
128
|
-
The generated image is saved to the specified directory.
|
|
129
|
-
|
|
130
|
-
Args:
|
|
131
|
-
prompt (str): The text prompt based on which the image is
|
|
132
|
-
generated.
|
|
133
|
-
image_dir (str): The directory to save the generated image.
|
|
134
|
-
Defaults to 'img'.
|
|
135
|
-
|
|
136
|
-
Returns:
|
|
137
|
-
str: The path to the saved image.
|
|
138
|
-
"""
|
|
139
|
-
|
|
140
|
-
dalle_client = OpenAI()
|
|
141
|
-
response = dalle_client.images.generate(
|
|
142
|
-
model="dall-e-3",
|
|
143
|
-
prompt=prompt,
|
|
144
|
-
size="1024x1792",
|
|
145
|
-
quality="standard",
|
|
146
|
-
n=1, # NOTE: now dall-e-3 only supports n=1
|
|
147
|
-
response_format="b64_json",
|
|
148
|
-
)
|
|
149
|
-
if response.data is None or len(response.data) == 0:
|
|
150
|
-
error_msg = "No image data returned from DALL-E API."
|
|
151
|
-
logger.error(error_msg)
|
|
152
|
-
return error_msg
|
|
153
|
-
image_b64 = response.data[0].b64_json
|
|
154
|
-
image = self.base64_to_image(image_b64) # type: ignore[arg-type]
|
|
155
|
-
|
|
156
|
-
if image is None:
|
|
157
|
-
error_msg = "Failed to convert base64 string to image."
|
|
158
|
-
logger.error(error_msg)
|
|
159
|
-
return error_msg
|
|
160
|
-
|
|
161
|
-
os.makedirs(image_dir, exist_ok=True)
|
|
162
|
-
image_path = os.path.join(image_dir, f"{uuid.uuid4()}.png")
|
|
163
|
-
image.save(image_path)
|
|
164
|
-
|
|
165
|
-
return image_path
|
|
166
|
-
|
|
167
|
-
def get_tools(self) -> List[FunctionTool]:
|
|
168
|
-
r"""Returns a list of FunctionTool objects representing the
|
|
169
|
-
functions in the toolkit.
|
|
170
|
-
|
|
171
|
-
Returns:
|
|
172
|
-
List[FunctionTool]: A list of FunctionTool objects
|
|
173
|
-
representing the functions in the toolkit.
|
|
174
|
-
"""
|
|
175
|
-
return [FunctionTool(self.get_dalle_img)]
|