camel-ai 0.2.3a1__py3-none-any.whl → 0.2.3a2__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 +93 -69
- camel/agents/knowledge_graph_agent.py +4 -6
- camel/bots/__init__.py +16 -2
- camel/bots/discord_app.py +138 -0
- camel/bots/slack/__init__.py +30 -0
- camel/bots/slack/models.py +158 -0
- camel/bots/slack/slack_app.py +255 -0
- camel/configs/__init__.py +1 -2
- camel/configs/anthropic_config.py +2 -5
- camel/configs/base_config.py +6 -6
- camel/configs/groq_config.py +2 -3
- camel/configs/ollama_config.py +1 -2
- camel/configs/openai_config.py +2 -23
- camel/configs/samba_config.py +2 -2
- camel/configs/togetherai_config.py +1 -1
- camel/configs/vllm_config.py +1 -1
- camel/configs/zhipuai_config.py +2 -3
- camel/embeddings/openai_embedding.py +2 -2
- camel/loaders/__init__.py +2 -0
- camel/loaders/chunkr_reader.py +163 -0
- camel/loaders/firecrawl_reader.py +3 -3
- camel/loaders/unstructured_io.py +35 -33
- camel/messages/__init__.py +1 -0
- camel/models/__init__.py +2 -4
- camel/models/anthropic_model.py +32 -26
- camel/models/azure_openai_model.py +39 -36
- camel/models/base_model.py +31 -20
- camel/models/gemini_model.py +37 -29
- camel/models/groq_model.py +29 -23
- camel/models/litellm_model.py +44 -61
- camel/models/mistral_model.py +32 -29
- camel/models/model_factory.py +66 -76
- camel/models/nemotron_model.py +33 -23
- camel/models/ollama_model.py +42 -47
- camel/models/{openai_compatibility_model.py → openai_compatible_model.py} +31 -49
- camel/models/openai_model.py +48 -29
- camel/models/reka_model.py +30 -28
- camel/models/samba_model.py +82 -177
- camel/models/stub_model.py +2 -2
- camel/models/togetherai_model.py +37 -43
- camel/models/vllm_model.py +43 -50
- camel/models/zhipuai_model.py +33 -27
- camel/retrievers/auto_retriever.py +28 -10
- camel/retrievers/vector_retriever.py +58 -47
- camel/societies/babyagi_playing.py +6 -3
- camel/societies/role_playing.py +5 -3
- camel/storages/graph_storages/graph_element.py +3 -5
- camel/storages/key_value_storages/json.py +6 -1
- camel/toolkits/__init__.py +20 -7
- camel/toolkits/arxiv_toolkit.py +155 -0
- camel/toolkits/ask_news_toolkit.py +653 -0
- camel/toolkits/base.py +2 -3
- camel/toolkits/code_execution.py +6 -7
- camel/toolkits/dalle_toolkit.py +6 -6
- camel/toolkits/{openai_function.py → function_tool.py} +34 -11
- camel/toolkits/github_toolkit.py +9 -10
- camel/toolkits/google_maps_toolkit.py +7 -7
- camel/toolkits/google_scholar_toolkit.py +146 -0
- camel/toolkits/linkedin_toolkit.py +7 -7
- camel/toolkits/math_toolkit.py +8 -8
- camel/toolkits/open_api_toolkit.py +5 -5
- camel/toolkits/reddit_toolkit.py +7 -7
- camel/toolkits/retrieval_toolkit.py +5 -5
- camel/toolkits/search_toolkit.py +9 -9
- camel/toolkits/slack_toolkit.py +11 -11
- camel/toolkits/twitter_toolkit.py +378 -452
- camel/toolkits/weather_toolkit.py +6 -6
- camel/toolkits/whatsapp_toolkit.py +177 -0
- camel/types/__init__.py +6 -1
- camel/types/enums.py +40 -85
- camel/types/openai_types.py +3 -0
- camel/types/unified_model_type.py +104 -0
- camel/utils/__init__.py +0 -2
- camel/utils/async_func.py +7 -7
- camel/utils/commons.py +32 -3
- camel/utils/token_counting.py +30 -212
- camel/workforce/role_playing_worker.py +1 -1
- camel/workforce/single_agent_worker.py +1 -1
- camel/workforce/task_channel.py +4 -3
- camel/workforce/workforce.py +4 -4
- camel_ai-0.2.3a2.dist-info/LICENSE +201 -0
- {camel_ai-0.2.3a1.dist-info → camel_ai-0.2.3a2.dist-info}/METADATA +27 -56
- {camel_ai-0.2.3a1.dist-info → camel_ai-0.2.3a2.dist-info}/RECORD +85 -76
- {camel_ai-0.2.3a1.dist-info → camel_ai-0.2.3a2.dist-info}/WHEEL +1 -1
- camel/bots/discord_bot.py +0 -206
- camel/models/open_source_model.py +0 -170
|
@@ -0,0 +1,158 @@
|
|
|
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
|
+
from typing import Optional
|
|
15
|
+
|
|
16
|
+
from pydantic import BaseModel
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class SlackAuthProfile(BaseModel):
|
|
20
|
+
r"""Represents the authorization profile within a Slack event.
|
|
21
|
+
|
|
22
|
+
Events will contain a single, compact authorizations field that shows one
|
|
23
|
+
installation of your app that the event is visible to.
|
|
24
|
+
In other words, lists of authorizations will be truncated to one element.
|
|
25
|
+
|
|
26
|
+
If there's more than one installing party that your app is keeping track
|
|
27
|
+
of, it's best not to rely on the single party listed in authorizations to
|
|
28
|
+
be any particular one.
|
|
29
|
+
|
|
30
|
+
To get a full list of who can see events, call the apps.event.
|
|
31
|
+
authorizations.list method after obtaining an app-level token. Read more on
|
|
32
|
+
the changes here; they have taken effect for existing apps as of
|
|
33
|
+
February 24, 2021.
|
|
34
|
+
|
|
35
|
+
References:
|
|
36
|
+
|
|
37
|
+
- https://api.slack.com/apis/events-api#authorizations
|
|
38
|
+
- https://api.slack.com/changelog/2020-09-15-events-api-truncate-authed-users#no_context
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
enterprise_id: Optional[str] = None
|
|
42
|
+
"""The ID of the enterprise associated with the authorization."""
|
|
43
|
+
|
|
44
|
+
team_id: str
|
|
45
|
+
"""The ID of the team associated with the authorization."""
|
|
46
|
+
|
|
47
|
+
user_id: str
|
|
48
|
+
"""The ID of the user associated with the authorization."""
|
|
49
|
+
|
|
50
|
+
is_bot: bool
|
|
51
|
+
"""Whether the authorized user is a bot."""
|
|
52
|
+
|
|
53
|
+
is_enterprise_install: bool
|
|
54
|
+
"""Whether the authorization is for an enterprise installation."""
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class SlackEventProfile(BaseModel):
|
|
58
|
+
r"""Represents the detailed profile of a Slack event, including user,
|
|
59
|
+
message, and context data.
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
user: str
|
|
63
|
+
"""The ID of the user associated with the event."""
|
|
64
|
+
|
|
65
|
+
type: str
|
|
66
|
+
"""The type of the event (e.g., 'message')."""
|
|
67
|
+
|
|
68
|
+
ts: str
|
|
69
|
+
"""A timestamp representing when the event was triggered."""
|
|
70
|
+
|
|
71
|
+
thread_ts: Optional[str] = None
|
|
72
|
+
"""The timestamp of the parent message in a thread."""
|
|
73
|
+
|
|
74
|
+
client_msg_id: str
|
|
75
|
+
"""A unique ID generated by the client for the message (if available)."""
|
|
76
|
+
|
|
77
|
+
text: str
|
|
78
|
+
"""The message content text."""
|
|
79
|
+
|
|
80
|
+
team: str
|
|
81
|
+
"""The ID of the team that the event is associated with."""
|
|
82
|
+
|
|
83
|
+
blocks: list
|
|
84
|
+
"""The list of message blocks, providing structured information."""
|
|
85
|
+
|
|
86
|
+
channel: str
|
|
87
|
+
"""The ID of the Slack channel where the event happened."""
|
|
88
|
+
|
|
89
|
+
event_ts: str
|
|
90
|
+
"""The event-specific timestamp when it occurred."""
|
|
91
|
+
|
|
92
|
+
channel_type: Optional[str]
|
|
93
|
+
"""The type of Slack channel (e.g., 'channel', 'im')."""
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class SlackEventBody(BaseModel):
|
|
97
|
+
r"""Represents the entire body of a Slack event, including the event
|
|
98
|
+
profile, authorization, and context.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
token: str
|
|
102
|
+
"""The token to verify the source of the event."""
|
|
103
|
+
|
|
104
|
+
team_id: str
|
|
105
|
+
"""The ID of the team where the event is happening."""
|
|
106
|
+
|
|
107
|
+
context_team_id: Optional[str]
|
|
108
|
+
"""The team ID for the shared channel context, if applicable."""
|
|
109
|
+
|
|
110
|
+
context_enterprise_id: Optional[str] = None
|
|
111
|
+
"""The enterprise ID for the shared channel context, if applicable."""
|
|
112
|
+
|
|
113
|
+
api_app_id: str
|
|
114
|
+
"""The unique identifier for the Slack app that received the event."""
|
|
115
|
+
|
|
116
|
+
event: SlackEventProfile
|
|
117
|
+
"""A detailed profile of the event"""
|
|
118
|
+
|
|
119
|
+
type: str
|
|
120
|
+
"""The overall type of event received (e.g., 'event_callback')."""
|
|
121
|
+
|
|
122
|
+
event_id: str
|
|
123
|
+
"""A unique identifier assigned to this event by Slack."""
|
|
124
|
+
|
|
125
|
+
event_time: int
|
|
126
|
+
"""The timestamp (in seconds) representing when the event was triggered."""
|
|
127
|
+
|
|
128
|
+
authorizations: Optional[list[SlackAuthProfile]] = None
|
|
129
|
+
"""An optional list of authorizations that describe which installation can
|
|
130
|
+
see the event."""
|
|
131
|
+
|
|
132
|
+
is_ext_shared_channel: bool
|
|
133
|
+
"""Indicates if the event is part of a shared channel between different
|
|
134
|
+
organizations."""
|
|
135
|
+
|
|
136
|
+
event_context: str
|
|
137
|
+
"""A unique string representing the context of the event."""
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class SlackAppMentionEventProfile(SlackEventProfile):
|
|
141
|
+
r"""Represents the detailed profile of a Slack event where the app was
|
|
142
|
+
mentioned in a message.
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
channel_type: Optional[str] = None
|
|
146
|
+
"""The type of Slack channel. it's None for app mentions."""
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class SlackAppMentionEventBody(SlackEventBody):
|
|
150
|
+
r"""Represents the entire body of a Slack event where the app was mentioned
|
|
151
|
+
in a message.
|
|
152
|
+
"""
|
|
153
|
+
|
|
154
|
+
context_team_id: Optional[str] = None
|
|
155
|
+
"""A detailed profile of the event. it's None for app mentions."""
|
|
156
|
+
|
|
157
|
+
event: SlackAppMentionEventProfile
|
|
158
|
+
"""A detailed profile of the event"""
|
|
@@ -0,0 +1,255 @@
|
|
|
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
|
+
import logging
|
|
15
|
+
import os
|
|
16
|
+
from typing import TYPE_CHECKING, Any, Dict, Optional
|
|
17
|
+
|
|
18
|
+
from slack_sdk.oauth.installation_store.async_installation_store import (
|
|
19
|
+
AsyncInstallationStore,
|
|
20
|
+
)
|
|
21
|
+
from starlette import requests, responses
|
|
22
|
+
|
|
23
|
+
from camel.bots.slack.models import (
|
|
24
|
+
SlackAppMentionEventBody,
|
|
25
|
+
SlackAppMentionEventProfile,
|
|
26
|
+
SlackEventBody,
|
|
27
|
+
SlackEventProfile,
|
|
28
|
+
)
|
|
29
|
+
from camel.utils import dependencies_required
|
|
30
|
+
|
|
31
|
+
if TYPE_CHECKING:
|
|
32
|
+
from slack_bolt.context.async_context import AsyncBoltContext
|
|
33
|
+
from slack_bolt.context.say.async_say import AsyncSay
|
|
34
|
+
from slack_sdk.web.async_client import AsyncWebClient
|
|
35
|
+
|
|
36
|
+
logging.basicConfig(level=logging.INFO)
|
|
37
|
+
logger = logging.getLogger(__name__)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class SlackApp:
|
|
41
|
+
r"""Represents a Slack app that is powered by a Slack Bolt `AsyncApp`.
|
|
42
|
+
|
|
43
|
+
This class is responsible for initializing and managing the Slack
|
|
44
|
+
application by setting up event handlers, running the app server, and
|
|
45
|
+
handling events such as messages and mentions from Slack.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
token (Optional[str]): Slack API token for authentication.
|
|
49
|
+
scopes (Optional[str]): Slack app scopes for permissions.
|
|
50
|
+
signing_secret (Optional[str]): Signing secret for verifying Slack
|
|
51
|
+
requests.
|
|
52
|
+
client_id (Optional[str]): Slack app client ID.
|
|
53
|
+
client_secret (Optional[str]): Slack app client secret.
|
|
54
|
+
redirect_uri_path (str): The URI path for OAuth redirect, defaults to
|
|
55
|
+
"/slack/oauth_redirect".
|
|
56
|
+
installation_store (Optional[AsyncInstallationStore]): The installation
|
|
57
|
+
store for handling OAuth installations.
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
@dependencies_required('slack_bolt')
|
|
61
|
+
def __init__(
|
|
62
|
+
self,
|
|
63
|
+
token: Optional[str] = None,
|
|
64
|
+
scopes: Optional[str] = None,
|
|
65
|
+
signing_secret: Optional[str] = None,
|
|
66
|
+
client_id: Optional[str] = None,
|
|
67
|
+
client_secret: Optional[str] = None,
|
|
68
|
+
redirect_uri_path: str = "/slack/oauth_redirect",
|
|
69
|
+
installation_store: Optional[AsyncInstallationStore] = None,
|
|
70
|
+
) -> None:
|
|
71
|
+
r"""Initializes the SlackApp instance by setting up the Slack Bolt app
|
|
72
|
+
and configuring event handlers and OAuth settings.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
token (Optional[str]): The Slack API token.
|
|
76
|
+
scopes (Optional[str]): The scopes for Slack app permissions.
|
|
77
|
+
signing_secret (Optional[str]): The signing secret for verifying
|
|
78
|
+
requests.
|
|
79
|
+
client_id (Optional[str]): The Slack app client ID.
|
|
80
|
+
client_secret (Optional[str]): The Slack app client secret.
|
|
81
|
+
redirect_uri_path (str): The URI path for handling OAuth redirects
|
|
82
|
+
(default is "/slack/oauth_redirect").
|
|
83
|
+
installation_store (Optional[AsyncInstallationStore]): An optional
|
|
84
|
+
installation store for OAuth installations.
|
|
85
|
+
"""
|
|
86
|
+
from slack_bolt.adapter.starlette.async_handler import (
|
|
87
|
+
AsyncSlackRequestHandler,
|
|
88
|
+
)
|
|
89
|
+
from slack_bolt.app.async_app import AsyncApp
|
|
90
|
+
from slack_bolt.oauth.async_oauth_settings import AsyncOAuthSettings
|
|
91
|
+
|
|
92
|
+
self.token: Optional[str] = token or os.getenv("SLACK_TOKEN")
|
|
93
|
+
self.scopes: Optional[str] = scopes or os.getenv("SLACK_SCOPES")
|
|
94
|
+
self.signing_secret: Optional[str] = signing_secret or os.getenv(
|
|
95
|
+
"SLACK_SIGNING_SECRET"
|
|
96
|
+
)
|
|
97
|
+
self.client_id: Optional[str] = client_id or os.getenv(
|
|
98
|
+
"SLACK_CLIENT_ID"
|
|
99
|
+
)
|
|
100
|
+
self.client_secret: Optional[str] = client_secret or os.getenv(
|
|
101
|
+
"SLACK_CLIENT_SECRET"
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
if not all([self.token, self.scopes, self.signing_secret]):
|
|
105
|
+
raise ValueError(
|
|
106
|
+
"`SLACK_TOKEN`, `SLACK_SCOPES`, and `SLACK_SIGNING_SECRET` "
|
|
107
|
+
"environment variables must be set. Get it here: "
|
|
108
|
+
"`https://api.slack.com/apps`."
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
# Setup OAuth settings if client ID and secret are provided
|
|
112
|
+
if self.client_id and self.client_secret:
|
|
113
|
+
self._app = AsyncApp(
|
|
114
|
+
oauth_settings=AsyncOAuthSettings(
|
|
115
|
+
client_id=self.client_id,
|
|
116
|
+
client_secret=self.client_secret,
|
|
117
|
+
scopes=self.scopes,
|
|
118
|
+
redirect_uri_path=redirect_uri_path,
|
|
119
|
+
),
|
|
120
|
+
logger=logger,
|
|
121
|
+
signing_secret=self.signing_secret,
|
|
122
|
+
installation_store=installation_store,
|
|
123
|
+
token=self.token,
|
|
124
|
+
)
|
|
125
|
+
else:
|
|
126
|
+
# Initialize Slack Bolt AsyncApp with settings
|
|
127
|
+
self._app = AsyncApp(
|
|
128
|
+
logger=logger,
|
|
129
|
+
signing_secret=self.signing_secret,
|
|
130
|
+
installation_store=installation_store,
|
|
131
|
+
token=self.token,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
self._handler = AsyncSlackRequestHandler(self._app)
|
|
135
|
+
self.setup_handlers()
|
|
136
|
+
|
|
137
|
+
def setup_handlers(self) -> None:
|
|
138
|
+
r"""Sets up the event handlers for Slack events, such as `app_mention`
|
|
139
|
+
and `message`.
|
|
140
|
+
|
|
141
|
+
This method registers the `app_mention` and `on_message` event handlers
|
|
142
|
+
with the Slack Bolt app to respond to Slack events.
|
|
143
|
+
"""
|
|
144
|
+
self._app.event("app_mention")(self.app_mention)
|
|
145
|
+
self._app.event("message")(self.on_message)
|
|
146
|
+
|
|
147
|
+
def run(
|
|
148
|
+
self,
|
|
149
|
+
port: int = 3000,
|
|
150
|
+
path: str = "/slack/events",
|
|
151
|
+
host: Optional[str] = None,
|
|
152
|
+
) -> None:
|
|
153
|
+
r"""Starts the Slack Bolt app server to listen for incoming Slack
|
|
154
|
+
events.
|
|
155
|
+
|
|
156
|
+
Args:
|
|
157
|
+
port (int): The port on which the server should run (default is
|
|
158
|
+
3000).
|
|
159
|
+
path (str): The endpoint path for receiving Slack events (default
|
|
160
|
+
is "/slack/events").
|
|
161
|
+
host (Optional[str]): The hostname to bind the server (default is
|
|
162
|
+
None).
|
|
163
|
+
"""
|
|
164
|
+
self._app.start(port=port, path=path, host=host)
|
|
165
|
+
|
|
166
|
+
async def handle_request(
|
|
167
|
+
self, request: requests.Request
|
|
168
|
+
) -> responses.Response:
|
|
169
|
+
r"""Handles incoming requests from Slack through the request handler.
|
|
170
|
+
|
|
171
|
+
Args:
|
|
172
|
+
request (Request): A Starlette request object representing the
|
|
173
|
+
incoming request.
|
|
174
|
+
|
|
175
|
+
Returns:
|
|
176
|
+
The response generated by the Slack Bolt handler.
|
|
177
|
+
"""
|
|
178
|
+
return await self._handler.handle(request)
|
|
179
|
+
|
|
180
|
+
async def app_mention(
|
|
181
|
+
self,
|
|
182
|
+
context: "AsyncBoltContext",
|
|
183
|
+
client: "AsyncWebClient",
|
|
184
|
+
event: Dict[str, Any],
|
|
185
|
+
body: Dict[str, Any],
|
|
186
|
+
say: "AsyncSay",
|
|
187
|
+
) -> None:
|
|
188
|
+
r"""Event handler for `app_mention` events.
|
|
189
|
+
|
|
190
|
+
This method is triggered when someone mentions the app in Slack.
|
|
191
|
+
|
|
192
|
+
Args:
|
|
193
|
+
context (AsyncBoltContext): The Slack Bolt context for the event.
|
|
194
|
+
client (AsyncWebClient): The Slack Web API client.
|
|
195
|
+
event (Dict[str, Any]): The event data for the app mention.
|
|
196
|
+
body (Dict[str, Any]): The full request body from Slack.
|
|
197
|
+
say (AsyncSay): A function to send a response back to the channel.
|
|
198
|
+
"""
|
|
199
|
+
event_profile = SlackAppMentionEventProfile(**event)
|
|
200
|
+
event_body = SlackAppMentionEventBody(**body)
|
|
201
|
+
|
|
202
|
+
logger.info(f"app_mention, context: {context}")
|
|
203
|
+
logger.info(f"app_mention, client: {client}")
|
|
204
|
+
logger.info(f"app_mention, event_profile: {event_profile}")
|
|
205
|
+
logger.info(f"app_mention, event_body: {event_body}")
|
|
206
|
+
logger.info(f"app_mention, say: {say}")
|
|
207
|
+
|
|
208
|
+
async def on_message(
|
|
209
|
+
self,
|
|
210
|
+
context: "AsyncBoltContext",
|
|
211
|
+
client: "AsyncWebClient",
|
|
212
|
+
event: Dict[str, Any],
|
|
213
|
+
body: Dict[str, Any],
|
|
214
|
+
say: "AsyncSay",
|
|
215
|
+
) -> None:
|
|
216
|
+
r"""Event handler for `message` events.
|
|
217
|
+
|
|
218
|
+
This method is triggered when the app receives a message in Slack.
|
|
219
|
+
|
|
220
|
+
Args:
|
|
221
|
+
context (AsyncBoltContext): The Slack Bolt context for the event.
|
|
222
|
+
client (AsyncWebClient): The Slack Web API client.
|
|
223
|
+
event (Dict[str, Any]): The event data for the message.
|
|
224
|
+
body (Dict[str, Any]): The full request body from Slack.
|
|
225
|
+
say (AsyncSay): A function to send a response back to the channel.
|
|
226
|
+
"""
|
|
227
|
+
await context.ack()
|
|
228
|
+
|
|
229
|
+
event_profile = SlackEventProfile(**event)
|
|
230
|
+
event_body = SlackEventBody(**body)
|
|
231
|
+
|
|
232
|
+
logger.info(f"on_message, context: {context}")
|
|
233
|
+
logger.info(f"on_message, client: {client}")
|
|
234
|
+
logger.info(f"on_message, event_profile: {event_profile}")
|
|
235
|
+
logger.info(f"on_message, event_body: {event_body}")
|
|
236
|
+
logger.info(f"on_message, say: {say}")
|
|
237
|
+
|
|
238
|
+
logger.info(f"Received message: {event_profile.text}")
|
|
239
|
+
|
|
240
|
+
def mention_me(
|
|
241
|
+
self, context: "AsyncBoltContext", body: SlackEventBody
|
|
242
|
+
) -> bool:
|
|
243
|
+
r"""Check if the bot is mentioned in the message.
|
|
244
|
+
|
|
245
|
+
Args:
|
|
246
|
+
context (AsyncBoltContext): The Slack Bolt context for the event.
|
|
247
|
+
body (SlackEventBody): The body of the Slack event.
|
|
248
|
+
|
|
249
|
+
Returns:
|
|
250
|
+
bool: True if the bot is mentioned in the message, False otherwise.
|
|
251
|
+
"""
|
|
252
|
+
message = body.event.text
|
|
253
|
+
bot_user_id = context.bot_user_id
|
|
254
|
+
mention = f"<@{bot_user_id}>"
|
|
255
|
+
return mention in message
|
camel/configs/__init__.py
CHANGED
|
@@ -18,7 +18,7 @@ from .groq_config import GROQ_API_PARAMS, GroqConfig
|
|
|
18
18
|
from .litellm_config import LITELLM_API_PARAMS, LiteLLMConfig
|
|
19
19
|
from .mistral_config import MISTRAL_API_PARAMS, MistralConfig
|
|
20
20
|
from .ollama_config import OLLAMA_API_PARAMS, OllamaConfig
|
|
21
|
-
from .openai_config import OPENAI_API_PARAMS, ChatGPTConfig
|
|
21
|
+
from .openai_config import OPENAI_API_PARAMS, ChatGPTConfig
|
|
22
22
|
from .reka_config import REKA_API_PARAMS, RekaConfig
|
|
23
23
|
from .samba_config import (
|
|
24
24
|
SAMBA_CLOUD_API_PARAMS,
|
|
@@ -40,7 +40,6 @@ __all__ = [
|
|
|
40
40
|
'ANTHROPIC_API_PARAMS',
|
|
41
41
|
'GROQ_API_PARAMS',
|
|
42
42
|
'GroqConfig',
|
|
43
|
-
'OpenSourceConfig',
|
|
44
43
|
'LiteLLMConfig',
|
|
45
44
|
'LITELLM_API_PARAMS',
|
|
46
45
|
'OllamaConfig',
|
|
@@ -15,9 +15,8 @@ from __future__ import annotations
|
|
|
15
15
|
|
|
16
16
|
from typing import List, Union
|
|
17
17
|
|
|
18
|
-
from anthropic import NOT_GIVEN, NotGiven
|
|
19
|
-
|
|
20
18
|
from camel.configs.base_config import BaseConfig
|
|
19
|
+
from camel.types import NOT_GIVEN, NotGiven
|
|
21
20
|
|
|
22
21
|
|
|
23
22
|
class AnthropicConfig(BaseConfig):
|
|
@@ -55,9 +54,7 @@ class AnthropicConfig(BaseConfig):
|
|
|
55
54
|
(default: :obj:`5`)
|
|
56
55
|
metadata: An object describing metadata about the request.
|
|
57
56
|
stream (bool, optional): Whether to incrementally stream the response
|
|
58
|
-
|
|
59
|
-
(default: :obj:`False`)
|
|
60
|
-
|
|
57
|
+
using server-sent events. (default: :obj:`False`)
|
|
61
58
|
"""
|
|
62
59
|
|
|
63
60
|
max_tokens: int = 256
|
camel/configs/base_config.py
CHANGED
|
@@ -39,13 +39,13 @@ class BaseConfig(ABC, BaseModel):
|
|
|
39
39
|
@classmethod
|
|
40
40
|
def fields_type_checking(cls, tools):
|
|
41
41
|
if tools is not None:
|
|
42
|
-
from camel.toolkits import
|
|
42
|
+
from camel.toolkits import FunctionTool
|
|
43
43
|
|
|
44
44
|
for tool in tools:
|
|
45
|
-
if not isinstance(tool,
|
|
45
|
+
if not isinstance(tool, FunctionTool):
|
|
46
46
|
raise ValueError(
|
|
47
47
|
f"The tool {tool} should "
|
|
48
|
-
"be an instance of `
|
|
48
|
+
"be an instance of `FunctionTool`."
|
|
49
49
|
)
|
|
50
50
|
return tools
|
|
51
51
|
|
|
@@ -54,14 +54,14 @@ class BaseConfig(ABC, BaseModel):
|
|
|
54
54
|
|
|
55
55
|
tools_schema = None
|
|
56
56
|
if self.tools:
|
|
57
|
-
from camel.toolkits import
|
|
57
|
+
from camel.toolkits import FunctionTool
|
|
58
58
|
|
|
59
59
|
tools_schema = []
|
|
60
60
|
for tool in self.tools:
|
|
61
|
-
if not isinstance(tool,
|
|
61
|
+
if not isinstance(tool, FunctionTool):
|
|
62
62
|
raise ValueError(
|
|
63
63
|
f"The tool {tool} should "
|
|
64
|
-
"be an instance of `
|
|
64
|
+
"be an instance of `FunctionTool`."
|
|
65
65
|
)
|
|
66
66
|
tools_schema.append(tool.get_openai_tool_schema())
|
|
67
67
|
config_dict["tools"] = tools_schema
|
camel/configs/groq_config.py
CHANGED
|
@@ -15,9 +15,8 @@ from __future__ import annotations
|
|
|
15
15
|
|
|
16
16
|
from typing import Optional, Sequence, Union
|
|
17
17
|
|
|
18
|
-
from openai._types import NOT_GIVEN, NotGiven
|
|
19
|
-
|
|
20
18
|
from camel.configs.base_config import BaseConfig
|
|
19
|
+
from camel.types import NOT_GIVEN, NotGiven
|
|
21
20
|
|
|
22
21
|
|
|
23
22
|
class GroqConfig(BaseConfig):
|
|
@@ -73,7 +72,7 @@ class GroqConfig(BaseConfig):
|
|
|
73
72
|
user (str, optional): A unique identifier representing your end-user,
|
|
74
73
|
which can help OpenAI to monitor and detect abuse.
|
|
75
74
|
(default: :obj:`""`)
|
|
76
|
-
tools (list[
|
|
75
|
+
tools (list[FunctionTool], optional): A list of tools the model may
|
|
77
76
|
call. Currently, only functions are supported as a tool. Use this
|
|
78
77
|
to provide a list of functions the model may generate JSON inputs
|
|
79
78
|
for. A max of 128 functions are supported.
|
camel/configs/ollama_config.py
CHANGED
|
@@ -15,9 +15,8 @@ from __future__ import annotations
|
|
|
15
15
|
|
|
16
16
|
from typing import Sequence, Union
|
|
17
17
|
|
|
18
|
-
from openai._types import NOT_GIVEN, NotGiven
|
|
19
|
-
|
|
20
18
|
from camel.configs.base_config import BaseConfig
|
|
19
|
+
from camel.types import NOT_GIVEN, NotGiven
|
|
21
20
|
|
|
22
21
|
|
|
23
22
|
class OllamaConfig(BaseConfig):
|
camel/configs/openai_config.py
CHANGED
|
@@ -15,10 +15,10 @@ from __future__ import annotations
|
|
|
15
15
|
|
|
16
16
|
from typing import Optional, Sequence, Union
|
|
17
17
|
|
|
18
|
-
from openai._types import NOT_GIVEN, NotGiven
|
|
19
18
|
from pydantic import Field
|
|
20
19
|
|
|
21
20
|
from camel.configs.base_config import BaseConfig
|
|
21
|
+
from camel.types import NOT_GIVEN, NotGiven
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
class ChatGPTConfig(BaseConfig):
|
|
@@ -81,7 +81,7 @@ class ChatGPTConfig(BaseConfig):
|
|
|
81
81
|
user (str, optional): A unique identifier representing your end-user,
|
|
82
82
|
which can help OpenAI to monitor and detect abuse.
|
|
83
83
|
(default: :obj:`""`)
|
|
84
|
-
tools (list[
|
|
84
|
+
tools (list[FunctionTool], optional): A list of tools the model may
|
|
85
85
|
call. Currently, only functions are supported as a tool. Use this
|
|
86
86
|
to provide a list of functions the model may generate JSON inputs
|
|
87
87
|
for. A max of 128 functions are supported.
|
|
@@ -112,24 +112,3 @@ class ChatGPTConfig(BaseConfig):
|
|
|
112
112
|
|
|
113
113
|
|
|
114
114
|
OPENAI_API_PARAMS = {param for param in ChatGPTConfig.model_fields.keys()}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
class OpenSourceConfig(BaseConfig):
|
|
118
|
-
r"""Defines parameters for setting up open-source models and includes
|
|
119
|
-
parameters to be passed to chat completion function of OpenAI API.
|
|
120
|
-
|
|
121
|
-
Args:
|
|
122
|
-
model_path (str): The path to a local folder containing the model
|
|
123
|
-
files or the model card in HuggingFace hub.
|
|
124
|
-
server_url (str): The URL to the server running the model inference
|
|
125
|
-
which will be used as the API base of OpenAI API.
|
|
126
|
-
api_params (ChatGPTConfig): An instance of :obj:ChatGPTConfig to
|
|
127
|
-
contain the arguments to be passed to OpenAI API.
|
|
128
|
-
"""
|
|
129
|
-
|
|
130
|
-
# Maybe the param needs to be renamed.
|
|
131
|
-
# Warning: Field "model_path" has conflict with protected namespace
|
|
132
|
-
# "model_".
|
|
133
|
-
model_path: str
|
|
134
|
-
server_url: str
|
|
135
|
-
api_params: ChatGPTConfig = Field(default_factory=ChatGPTConfig)
|
camel/configs/samba_config.py
CHANGED
|
@@ -15,10 +15,10 @@ from __future__ import annotations
|
|
|
15
15
|
|
|
16
16
|
from typing import Any, Dict, Optional, Sequence, Union
|
|
17
17
|
|
|
18
|
-
from openai._types import NOT_GIVEN, NotGiven
|
|
19
18
|
from pydantic import Field
|
|
20
19
|
|
|
21
20
|
from camel.configs.base_config import BaseConfig
|
|
21
|
+
from camel.types import NOT_GIVEN, NotGiven
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
class SambaFastAPIConfig(BaseConfig):
|
|
@@ -172,7 +172,7 @@ class SambaCloudAPIConfig(BaseConfig):
|
|
|
172
172
|
user (str, optional): A unique identifier representing your end-user,
|
|
173
173
|
which can help OpenAI to monitor and detect abuse.
|
|
174
174
|
(default: :obj:`""`)
|
|
175
|
-
tools (list[
|
|
175
|
+
tools (list[FunctionTool], optional): A list of tools the model may
|
|
176
176
|
call. Currently, only functions are supported as a tool. Use this
|
|
177
177
|
to provide a list of functions the model may generate JSON inputs
|
|
178
178
|
for. A max of 128 functions are supported.
|
|
@@ -15,10 +15,10 @@ from __future__ import annotations
|
|
|
15
15
|
|
|
16
16
|
from typing import Any, Sequence, Union
|
|
17
17
|
|
|
18
|
-
from openai._types import NOT_GIVEN, NotGiven
|
|
19
18
|
from pydantic import Field
|
|
20
19
|
|
|
21
20
|
from camel.configs.base_config import BaseConfig
|
|
21
|
+
from camel.types import NOT_GIVEN, NotGiven
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
class TogetherAIConfig(BaseConfig):
|
camel/configs/vllm_config.py
CHANGED
|
@@ -15,10 +15,10 @@ from __future__ import annotations
|
|
|
15
15
|
|
|
16
16
|
from typing import Sequence, Union
|
|
17
17
|
|
|
18
|
-
from openai._types import NOT_GIVEN, NotGiven
|
|
19
18
|
from pydantic import Field
|
|
20
19
|
|
|
21
20
|
from camel.configs.base_config import BaseConfig
|
|
21
|
+
from camel.types import NOT_GIVEN, NotGiven
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
# flake8: noqa: E501
|
camel/configs/zhipuai_config.py
CHANGED
|
@@ -15,9 +15,8 @@ from __future__ import annotations
|
|
|
15
15
|
|
|
16
16
|
from typing import Optional, Sequence, Union
|
|
17
17
|
|
|
18
|
-
from openai._types import NOT_GIVEN, NotGiven
|
|
19
|
-
|
|
20
18
|
from camel.configs.base_config import BaseConfig
|
|
19
|
+
from camel.types import NOT_GIVEN, NotGiven
|
|
21
20
|
|
|
22
21
|
|
|
23
22
|
class ZhipuAIConfig(BaseConfig):
|
|
@@ -45,7 +44,7 @@ class ZhipuAIConfig(BaseConfig):
|
|
|
45
44
|
in the chat completion. The total length of input tokens and
|
|
46
45
|
generated tokens is limited by the model's context length.
|
|
47
46
|
(default: :obj:`None`)
|
|
48
|
-
tools (list[
|
|
47
|
+
tools (list[FunctionTool], optional): A list of tools the model may
|
|
49
48
|
call. Currently, only functions are supported as a tool. Use this
|
|
50
49
|
to provide a list of functions the model may generate JSON inputs
|
|
51
50
|
for. A max of 128 functions are supported.
|
|
@@ -16,10 +16,10 @@ from __future__ import annotations
|
|
|
16
16
|
import os
|
|
17
17
|
from typing import Any
|
|
18
18
|
|
|
19
|
-
from openai import
|
|
19
|
+
from openai import OpenAI
|
|
20
20
|
|
|
21
21
|
from camel.embeddings.base import BaseEmbedding
|
|
22
|
-
from camel.types import EmbeddingModelType
|
|
22
|
+
from camel.types import NOT_GIVEN, EmbeddingModelType, NotGiven
|
|
23
23
|
from camel.utils import api_keys_required
|
|
24
24
|
|
|
25
25
|
|
camel/loaders/__init__.py
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
14
|
|
|
15
15
|
from .base_io import File
|
|
16
|
+
from .chunkr_reader import ChunkrReader
|
|
16
17
|
from .firecrawl_reader import Firecrawl
|
|
17
18
|
from .jina_url_reader import JinaURLReader
|
|
18
19
|
from .unstructured_io import UnstructuredIO
|
|
@@ -22,4 +23,5 @@ __all__ = [
|
|
|
22
23
|
'UnstructuredIO',
|
|
23
24
|
'JinaURLReader',
|
|
24
25
|
'Firecrawl',
|
|
26
|
+
'ChunkrReader',
|
|
25
27
|
]
|