camel-ai 0.1.5.6__py3-none-any.whl → 0.1.5.7__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/agents/chat_agent.py +1 -1
- camel/configs/gemini_config.py +15 -14
- camel/configs/litellm_config.py +1 -1
- camel/configs/openai_config.py +1 -1
- camel/configs/zhipuai_config.py +1 -1
- camel/models/base_model.py +4 -1
- camel/models/litellm_model.py +16 -0
- camel/models/ollama_model.py +16 -0
- camel/models/zhipuai_model.py +0 -1
- camel/toolkits/__init__.py +36 -0
- camel/toolkits/base.py +1 -1
- camel/toolkits/code_execution.py +1 -1
- camel/toolkits/github_toolkit.py +3 -2
- camel/toolkits/google_maps_toolkit.py +367 -0
- camel/toolkits/math_toolkit.py +79 -0
- camel/toolkits/open_api_toolkit.py +548 -0
- camel/toolkits/retrieval_toolkit.py +76 -0
- camel/toolkits/search_toolkit.py +326 -0
- camel/toolkits/slack_toolkit.py +308 -0
- camel/toolkits/twitter_toolkit.py +522 -0
- camel/toolkits/weather_toolkit.py +173 -0
- camel/utils/async_func.py +1 -1
- {camel_ai-0.1.5.6.dist-info → camel_ai-0.1.5.7.dist-info}/METADATA +2 -2
- {camel_ai-0.1.5.6.dist-info → camel_ai-0.1.5.7.dist-info}/RECORD +52 -53
- camel/functions/__init__.py +0 -51
- camel/functions/google_maps_function.py +0 -335
- camel/functions/math_functions.py +0 -61
- camel/functions/open_api_function.py +0 -508
- camel/functions/retrieval_functions.py +0 -61
- camel/functions/search_functions.py +0 -298
- camel/functions/slack_functions.py +0 -286
- camel/functions/twitter_function.py +0 -479
- camel/functions/weather_functions.py +0 -144
- /camel/{functions → toolkits}/open_api_specs/biztoc/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/biztoc/ai-plugin.json +0 -0
- /camel/{functions → toolkits}/open_api_specs/biztoc/openapi.yaml +0 -0
- /camel/{functions → toolkits}/open_api_specs/coursera/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/coursera/openapi.yaml +0 -0
- /camel/{functions → toolkits}/open_api_specs/create_qr_code/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/create_qr_code/openapi.yaml +0 -0
- /camel/{functions → toolkits}/open_api_specs/klarna/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/klarna/openapi.yaml +0 -0
- /camel/{functions → toolkits}/open_api_specs/nasa_apod/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/nasa_apod/openapi.yaml +0 -0
- /camel/{functions → toolkits}/open_api_specs/outschool/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/outschool/ai-plugin.json +0 -0
- /camel/{functions → toolkits}/open_api_specs/outschool/openapi.yaml +0 -0
- /camel/{functions → toolkits}/open_api_specs/outschool/paths/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/outschool/paths/get_classes.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/outschool/paths/search_teachers.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/security_config.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/speak/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/speak/openapi.yaml +0 -0
- /camel/{functions → toolkits}/open_api_specs/web_scraper/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/web_scraper/ai-plugin.json +0 -0
- /camel/{functions → toolkits}/open_api_specs/web_scraper/openapi.yaml +0 -0
- /camel/{functions → toolkits}/open_api_specs/web_scraper/paths/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/web_scraper/paths/scraper.py +0 -0
- /camel/{functions → toolkits}/openai_function.py +0 -0
- {camel_ai-0.1.5.6.dist-info → camel_ai-0.1.5.7.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
# =========== Copyright 2023 @ 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 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
import logging
|
|
19
|
+
import os
|
|
20
|
+
from typing import TYPE_CHECKING, List, Optional
|
|
21
|
+
|
|
22
|
+
from camel.toolkits.base import BaseToolkit
|
|
23
|
+
|
|
24
|
+
if TYPE_CHECKING:
|
|
25
|
+
from ssl import SSLContext
|
|
26
|
+
|
|
27
|
+
from slack_sdk import WebClient
|
|
28
|
+
|
|
29
|
+
from camel.toolkits import OpenAIFunction
|
|
30
|
+
|
|
31
|
+
logger = logging.getLogger(__name__)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class SlackToolkit(BaseToolkit):
|
|
35
|
+
r"""A class representing a toolkit for Slack operations.
|
|
36
|
+
|
|
37
|
+
This class provides methods for Slack operations such as creating a new
|
|
38
|
+
channel, joining an existing channel, leaving a channel.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
def _login_slack(
|
|
42
|
+
self,
|
|
43
|
+
slack_token: Optional[str] = None,
|
|
44
|
+
ssl: Optional[SSLContext] = None,
|
|
45
|
+
) -> WebClient:
|
|
46
|
+
r"""Authenticate using the Slack API.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
slack_token (str, optional): The Slack API token.
|
|
50
|
+
If not provided, it attempts to retrieve the token from
|
|
51
|
+
the environment variable SLACK_BOT_TOKEN or SLACK_USER_TOKEN.
|
|
52
|
+
ssl (SSLContext, optional): SSL context for secure connections.
|
|
53
|
+
Defaults to `None`.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
WebClient: A WebClient object for interacting with Slack API.
|
|
57
|
+
|
|
58
|
+
Raises:
|
|
59
|
+
ImportError: If slack_sdk package is not installed.
|
|
60
|
+
KeyError: If SLACK_BOT_TOKEN or SLACK_USER_TOKEN
|
|
61
|
+
environment variables are not set.
|
|
62
|
+
"""
|
|
63
|
+
try:
|
|
64
|
+
from slack_sdk import WebClient
|
|
65
|
+
except ImportError as e:
|
|
66
|
+
raise ImportError(
|
|
67
|
+
"Cannot import slack_sdk. Please install the package with \
|
|
68
|
+
`pip install slack_sdk`."
|
|
69
|
+
) from e
|
|
70
|
+
if not slack_token:
|
|
71
|
+
slack_token = os.environ.get("SLACK_BOT_TOKEN") or os.environ.get(
|
|
72
|
+
"SLACK_USER_TOKEN"
|
|
73
|
+
)
|
|
74
|
+
if not slack_token:
|
|
75
|
+
raise KeyError(
|
|
76
|
+
"SLACK_BOT_TOKEN or SLACK_USER_TOKEN environment "
|
|
77
|
+
"variable not set."
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
client = WebClient(token=slack_token, ssl=ssl)
|
|
81
|
+
logger.info("Slack login successful.")
|
|
82
|
+
return client
|
|
83
|
+
|
|
84
|
+
def create_slack_channel(
|
|
85
|
+
self, name: str, is_private: Optional[bool] = True
|
|
86
|
+
) -> str:
|
|
87
|
+
r"""Creates a new slack channel, either public or private.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
name (str): Name of the public or private channel to create.
|
|
91
|
+
is_private (bool, optional): Whether to create a private channel
|
|
92
|
+
instead of a public one. Defaults to `True`.
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
str: JSON string containing information about Slack
|
|
96
|
+
channel created.
|
|
97
|
+
|
|
98
|
+
Raises:
|
|
99
|
+
SlackApiError: If there is an error during get slack channel
|
|
100
|
+
information.
|
|
101
|
+
"""
|
|
102
|
+
from slack_sdk.errors import SlackApiError
|
|
103
|
+
|
|
104
|
+
try:
|
|
105
|
+
slack_client = self._login_slack()
|
|
106
|
+
response = slack_client.conversations_create(
|
|
107
|
+
name=name, is_private=is_private
|
|
108
|
+
)
|
|
109
|
+
channel_id = response["channel"]["id"]
|
|
110
|
+
response = slack_client.conversations_archive(channel=channel_id)
|
|
111
|
+
return str(response)
|
|
112
|
+
except SlackApiError as e:
|
|
113
|
+
return f"Error creating conversation: {e.response['error']}"
|
|
114
|
+
|
|
115
|
+
def join_slack_channel(self, channel_id: str) -> str:
|
|
116
|
+
r"""Joins an existing Slack channel.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
channel_id (str): The ID of the Slack channel to join.
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
str: A confirmation message indicating whether join successfully
|
|
123
|
+
or an error message.
|
|
124
|
+
|
|
125
|
+
Raises:
|
|
126
|
+
SlackApiError: If there is an error during get slack channel
|
|
127
|
+
information.
|
|
128
|
+
"""
|
|
129
|
+
from slack_sdk.errors import SlackApiError
|
|
130
|
+
|
|
131
|
+
try:
|
|
132
|
+
slack_client = self._login_slack()
|
|
133
|
+
response = slack_client.conversations_join(channel=channel_id)
|
|
134
|
+
return str(response)
|
|
135
|
+
except SlackApiError as e:
|
|
136
|
+
return f"Error creating conversation: {e.response['error']}"
|
|
137
|
+
|
|
138
|
+
def leave_slack_channel(self, channel_id: str) -> str:
|
|
139
|
+
r"""Leaves an existing Slack channel.
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
channel_id (str): The ID of the Slack channel to leave.
|
|
143
|
+
|
|
144
|
+
Returns:
|
|
145
|
+
str: A confirmation message indicating whether leave successfully
|
|
146
|
+
or an error message.
|
|
147
|
+
|
|
148
|
+
Raises:
|
|
149
|
+
SlackApiError: If there is an error during get slack channel
|
|
150
|
+
information.
|
|
151
|
+
"""
|
|
152
|
+
from slack_sdk.errors import SlackApiError
|
|
153
|
+
|
|
154
|
+
try:
|
|
155
|
+
slack_client = self._login_slack()
|
|
156
|
+
response = slack_client.conversations_leave(channel=channel_id)
|
|
157
|
+
return str(response)
|
|
158
|
+
except SlackApiError as e:
|
|
159
|
+
return f"Error creating conversation: {e.response['error']}"
|
|
160
|
+
|
|
161
|
+
def get_slack_channel_information(self) -> str:
|
|
162
|
+
r"""Retrieve Slack channels and return relevant information in JSON
|
|
163
|
+
format.
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
str: JSON string containing information about Slack channels.
|
|
167
|
+
|
|
168
|
+
Raises:
|
|
169
|
+
SlackApiError: If there is an error during get slack channel
|
|
170
|
+
information.
|
|
171
|
+
"""
|
|
172
|
+
from slack_sdk.errors import SlackApiError
|
|
173
|
+
|
|
174
|
+
try:
|
|
175
|
+
slack_client = self._login_slack()
|
|
176
|
+
response = slack_client.conversations_list()
|
|
177
|
+
conversations = response["channels"]
|
|
178
|
+
# Filtering conversations and extracting required information
|
|
179
|
+
filtered_result = [
|
|
180
|
+
{
|
|
181
|
+
key: conversation[key]
|
|
182
|
+
for key in ("id", "name", "created", "num_members")
|
|
183
|
+
}
|
|
184
|
+
for conversation in conversations
|
|
185
|
+
if all(
|
|
186
|
+
key in conversation
|
|
187
|
+
for key in ("id", "name", "created", "num_members")
|
|
188
|
+
)
|
|
189
|
+
]
|
|
190
|
+
return json.dumps(filtered_result, ensure_ascii=False)
|
|
191
|
+
except SlackApiError as e:
|
|
192
|
+
return f"Error creating conversation: {e.response['error']}"
|
|
193
|
+
|
|
194
|
+
def get_slack_channel_message(self, channel_id: str) -> str:
|
|
195
|
+
r"""Retrieve messages from a Slack channel.
|
|
196
|
+
|
|
197
|
+
Args:
|
|
198
|
+
channel_id (str): The ID of the Slack channel to retrieve messages
|
|
199
|
+
from.
|
|
200
|
+
|
|
201
|
+
Returns:
|
|
202
|
+
str: JSON string containing filtered message data.
|
|
203
|
+
|
|
204
|
+
Raises:
|
|
205
|
+
SlackApiError: If there is an error during get
|
|
206
|
+
slack channel message.
|
|
207
|
+
"""
|
|
208
|
+
from slack_sdk.errors import SlackApiError
|
|
209
|
+
|
|
210
|
+
try:
|
|
211
|
+
slack_client = self._login_slack()
|
|
212
|
+
result = slack_client.conversations_history(channel=channel_id)
|
|
213
|
+
messages = result["messages"]
|
|
214
|
+
filtered_messages = [
|
|
215
|
+
{key: message[key] for key in ("user", "text", "ts")}
|
|
216
|
+
for message in messages
|
|
217
|
+
if all(key in message for key in ("user", "text", "ts"))
|
|
218
|
+
]
|
|
219
|
+
return json.dumps(filtered_messages, ensure_ascii=False)
|
|
220
|
+
except SlackApiError as e:
|
|
221
|
+
return f"Error retrieving messages: {e.response['error']}"
|
|
222
|
+
|
|
223
|
+
def send_slack_message(
|
|
224
|
+
self,
|
|
225
|
+
message: str,
|
|
226
|
+
channel_id: str,
|
|
227
|
+
user: Optional[str] = None,
|
|
228
|
+
) -> str:
|
|
229
|
+
r"""Send a message to a Slack channel.
|
|
230
|
+
|
|
231
|
+
Args:
|
|
232
|
+
message (str): The message to send.
|
|
233
|
+
channel_id (str): The ID of the Slack channel to send message.
|
|
234
|
+
user (Optional[str]): The user ID of the recipient.
|
|
235
|
+
Defaults to `None`.
|
|
236
|
+
|
|
237
|
+
Returns:
|
|
238
|
+
str: A confirmation message indicating whether the message was sent
|
|
239
|
+
successfully or an error message.
|
|
240
|
+
|
|
241
|
+
Raises:
|
|
242
|
+
SlackApiError: If an error occurs while sending the message.
|
|
243
|
+
"""
|
|
244
|
+
from slack_sdk.errors import SlackApiError
|
|
245
|
+
|
|
246
|
+
try:
|
|
247
|
+
slack_client = self._login_slack()
|
|
248
|
+
if user:
|
|
249
|
+
response = slack_client.chat_postEphemeral(
|
|
250
|
+
channel=channel_id, text=message, user=user
|
|
251
|
+
)
|
|
252
|
+
else:
|
|
253
|
+
response = slack_client.chat_postMessage(
|
|
254
|
+
channel=channel_id, text=message
|
|
255
|
+
)
|
|
256
|
+
return str(response)
|
|
257
|
+
except SlackApiError as e:
|
|
258
|
+
return f"Error creating conversation: {e.response['error']}"
|
|
259
|
+
|
|
260
|
+
def delete_slack_message(
|
|
261
|
+
self,
|
|
262
|
+
time_stamp: str,
|
|
263
|
+
channel_id: str,
|
|
264
|
+
) -> str:
|
|
265
|
+
r"""Delete a message to a Slack channel.
|
|
266
|
+
|
|
267
|
+
Args:
|
|
268
|
+
time_stamp (str): Timestamp of the message to be deleted.
|
|
269
|
+
channel_id (str): The ID of the Slack channel to delete message.
|
|
270
|
+
|
|
271
|
+
Returns:
|
|
272
|
+
str: A confirmation message indicating whether the message
|
|
273
|
+
was delete successfully or an error message.
|
|
274
|
+
|
|
275
|
+
Raises:
|
|
276
|
+
SlackApiError: If an error occurs while sending the message.
|
|
277
|
+
"""
|
|
278
|
+
from slack_sdk.errors import SlackApiError
|
|
279
|
+
|
|
280
|
+
try:
|
|
281
|
+
slack_client = self._login_slack()
|
|
282
|
+
response = slack_client.chat_delete(
|
|
283
|
+
channel=channel_id, ts=time_stamp
|
|
284
|
+
)
|
|
285
|
+
return str(response)
|
|
286
|
+
except SlackApiError as e:
|
|
287
|
+
return f"Error creating conversation: {e.response['error']}"
|
|
288
|
+
|
|
289
|
+
def get_tools(self) -> List[OpenAIFunction]:
|
|
290
|
+
r"""Returns a list of OpenAIFunction objects representing the
|
|
291
|
+
functions in the toolkit.
|
|
292
|
+
|
|
293
|
+
Returns:
|
|
294
|
+
List[OpenAIFunction]: A list of OpenAIFunction objects
|
|
295
|
+
representing the functions in the toolkit.
|
|
296
|
+
"""
|
|
297
|
+
return [
|
|
298
|
+
OpenAIFunction(self.create_slack_channel),
|
|
299
|
+
OpenAIFunction(self.join_slack_channel),
|
|
300
|
+
OpenAIFunction(self.leave_slack_channel),
|
|
301
|
+
OpenAIFunction(self.get_slack_channel_information),
|
|
302
|
+
OpenAIFunction(self.get_slack_channel_message),
|
|
303
|
+
OpenAIFunction(self.send_slack_message),
|
|
304
|
+
OpenAIFunction(self.delete_slack_message),
|
|
305
|
+
]
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
SLACK_FUNCS: List[OpenAIFunction] = SlackToolkit().get_tools()
|