camel-ai 0.1.5.3__tar.gz → 0.1.5.4__tar.gz
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_ai-0.1.5.3 → camel_ai-0.1.5.4}/PKG-INFO +7 -7
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/README.md +2 -2
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/agents/knowledge_graph_agent.py +4 -1
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/embeddings/base.py +10 -9
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/embeddings/openai_embedding.py +25 -12
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/embeddings/sentence_transformers_embeddings.py +28 -14
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/retrievers/auto_retriever.py +2 -2
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/storages/graph_storages/graph_element.py +9 -1
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/types/enums.py +14 -19
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/pyproject.toml +6 -6
- camel_ai-0.1.5.3/camel/bots/__init__.py +0 -20
- camel_ai-0.1.5.3/camel/bots/discord_bot.py +0 -103
- camel_ai-0.1.5.3/camel/bots/telegram_bot.py +0 -84
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/agents/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/agents/base.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/agents/chat_agent.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/agents/critic_agent.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/agents/deductive_reasoner_agent.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/agents/embodied_agent.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/agents/role_assignment_agent.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/agents/search_agent.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/agents/task_agent.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/agents/tool_agents/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/agents/tool_agents/base.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/agents/tool_agents/hugging_face_tool_agent.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/configs/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/configs/anthropic_config.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/configs/base_config.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/configs/litellm_config.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/configs/openai_config.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/embeddings/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/embeddings/vlm_embedding.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/google_maps_function.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/math_functions.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_function.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/biztoc/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/biztoc/ai-plugin.json +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/biztoc/openapi.yaml +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/coursera/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/coursera/openapi.yaml +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/create_qr_code/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/create_qr_code/openapi.yaml +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/klarna/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/klarna/openapi.yaml +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/nasa_apod/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/nasa_apod/openapi.yaml +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/outschool/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/outschool/ai-plugin.json +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/outschool/openapi.yaml +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/outschool/paths/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/outschool/paths/get_classes.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/outschool/paths/search_teachers.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/security_config.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/speak/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/speak/openapi.yaml +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/web_scraper/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/web_scraper/ai-plugin.json +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/web_scraper/openapi.yaml +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/web_scraper/paths/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/open_api_specs/web_scraper/paths/scraper.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/openai_function.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/retrieval_functions.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/search_functions.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/slack_functions.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/twitter_function.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/functions/weather_functions.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/generators.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/human.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/interpreters/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/interpreters/base.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/interpreters/internal_python_interpreter.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/interpreters/interpreter_error.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/interpreters/subprocess_interpreter.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/loaders/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/loaders/base_io.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/loaders/unstructured_io.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/memories/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/memories/agent_memories.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/memories/base.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/memories/blocks/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/memories/blocks/chat_history_block.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/memories/blocks/vectordb_block.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/memories/context_creators/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/memories/context_creators/score_based.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/memories/records.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/messages/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/messages/base.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/messages/func_message.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/models/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/models/anthropic_model.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/models/base_model.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/models/litellm_model.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/models/model_factory.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/models/nemotron_model.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/models/ollama_model.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/models/open_source_model.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/models/openai_audio_models.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/models/openai_model.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/models/stub_model.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/models/zhipuai_model.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/prompts/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/prompts/ai_society.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/prompts/base.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/prompts/code.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/prompts/descripte_video_prompt.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/prompts/evaluation.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/prompts/generate_text_embedding_data.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/prompts/misalignment.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/prompts/object_recognition.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/prompts/prompt_templates.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/prompts/role_description_prompt_template.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/prompts/solution_extraction.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/prompts/task_prompt_template.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/prompts/translation.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/responses/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/responses/agent_responses.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/retrievers/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/retrievers/base.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/retrievers/bm25_retriever.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/retrievers/cohere_rerank_retriever.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/retrievers/vector_retriever.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/societies/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/societies/babyagi_playing.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/societies/role_playing.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/storages/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/storages/graph_storages/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/storages/graph_storages/base.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/storages/graph_storages/neo4j_graph.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/storages/key_value_storages/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/storages/key_value_storages/base.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/storages/key_value_storages/in_memory.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/storages/key_value_storages/json.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/storages/vectordb_storages/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/storages/vectordb_storages/base.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/storages/vectordb_storages/milvus.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/storages/vectordb_storages/qdrant.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/terminators/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/terminators/base.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/terminators/response_terminator.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/terminators/token_limit_terminator.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/toolkits/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/toolkits/base.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/toolkits/github_toolkit.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/types/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/types/openai_types.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/utils/__init__.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/utils/commons.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/utils/constants.py +0 -0
- {camel_ai-0.1.5.3 → camel_ai-0.1.5.4}/camel/utils/token_counting.py +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: camel-ai
|
|
3
|
-
Version: 0.1.5.
|
|
3
|
+
Version: 0.1.5.4
|
|
4
4
|
Summary: Communicative Agents for AI Society Study
|
|
5
5
|
Home-page: https://www.camel-ai.org/
|
|
6
6
|
License: Apache-2.0
|
|
7
7
|
Keywords: communicative-ai,ai-societies,artificial-intelligence,deep-learning,multi-agent-systems,cooperative-ai,natural-language-processing,large-language-models
|
|
8
8
|
Author: CAMEL-AI.org
|
|
9
|
-
Requires-Python: >=3.
|
|
9
|
+
Requires-Python: >=3.9.0,<3.12
|
|
10
10
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.9
|
|
@@ -23,7 +23,7 @@ Provides-Extra: tools
|
|
|
23
23
|
Provides-Extra: vector-databases
|
|
24
24
|
Requires-Dist: PyMuPDF (>=1.22.5,<2.0.0) ; extra == "tools" or extra == "all"
|
|
25
25
|
Requires-Dist: accelerate (>=0,<1) ; extra == "huggingface-agent" or extra == "all"
|
|
26
|
-
Requires-Dist: anthropic (>=0.
|
|
26
|
+
Requires-Dist: anthropic (>=0.29.0,<0.30.0)
|
|
27
27
|
Requires-Dist: beautifulsoup4 (>=4,<5) ; extra == "tools" or extra == "all"
|
|
28
28
|
Requires-Dist: cohere (>=4.56,<5.0) ; extra == "retrievers" or extra == "all"
|
|
29
29
|
Requires-Dist: colorama (>=0,<1)
|
|
@@ -35,7 +35,7 @@ Requires-Dist: docstring-parser (>=0.15,<0.16)
|
|
|
35
35
|
Requires-Dist: docx2txt (>=0.8,<0.9) ; extra == "tools" or extra == "all"
|
|
36
36
|
Requires-Dist: duckduckgo-search (>=6.1.0,<7.0.0) ; extra == "tools" or extra == "all"
|
|
37
37
|
Requires-Dist: googlemaps (>=4.10.0,<5.0.0) ; extra == "tools" or extra == "all"
|
|
38
|
-
Requires-Dist: imageio (>=2.34.
|
|
38
|
+
Requires-Dist: imageio[pyav] (>=2.34.2,<3.0.0) ; extra == "tools" or extra == "all"
|
|
39
39
|
Requires-Dist: jsonschema (>=4,<5)
|
|
40
40
|
Requires-Dist: litellm (>=1.38.1,<2.0.0) ; extra == "model-platforms" or extra == "all"
|
|
41
41
|
Requires-Dist: mock (>=5,<6) ; extra == "test"
|
|
@@ -60,7 +60,7 @@ Requires-Dist: pytest-asyncio (>=0.23.0,<0.24.0) ; extra == "test"
|
|
|
60
60
|
Requires-Dist: qdrant-client (>=1.9.0,<2.0.0) ; extra == "vector-databases" or extra == "all"
|
|
61
61
|
Requires-Dist: rank-bm25 (>=0.2.2,<0.3.0) ; extra == "retrievers" or extra == "all"
|
|
62
62
|
Requires-Dist: requests_oauthlib (>=1.3.1,<2.0.0) ; extra == "tools" or extra == "all"
|
|
63
|
-
Requires-Dist: sentence-transformers (>=
|
|
63
|
+
Requires-Dist: sentence-transformers (>=3.0.1,<4.0.0) ; extra == "encoders" or extra == "all"
|
|
64
64
|
Requires-Dist: sentencepiece (>=0,<1) ; extra == "huggingface-agent" or extra == "all"
|
|
65
65
|
Requires-Dist: slack-sdk (>=3.27.2,<4.0.0) ; extra == "tools" or extra == "all"
|
|
66
66
|
Requires-Dist: soundfile (>=0,<1) ; extra == "huggingface-agent" or extra == "all"
|
|
@@ -180,13 +180,13 @@ exit
|
|
|
180
180
|
Install `CAMEL` from source with conda and pip:
|
|
181
181
|
```sh
|
|
182
182
|
# Create a conda virtual environment
|
|
183
|
-
conda create --name camel python=3.
|
|
183
|
+
conda create --name camel python=3.9
|
|
184
184
|
|
|
185
185
|
# Activate CAMEL conda environment
|
|
186
186
|
conda activate camel
|
|
187
187
|
|
|
188
188
|
# Clone github repo
|
|
189
|
-
git clone -b v0.1.5.
|
|
189
|
+
git clone -b v0.1.5.4 https://github.com/camel-ai/camel.git
|
|
190
190
|
|
|
191
191
|
# Change directory into project directory
|
|
192
192
|
cd camel
|
|
@@ -104,13 +104,13 @@ exit
|
|
|
104
104
|
Install `CAMEL` from source with conda and pip:
|
|
105
105
|
```sh
|
|
106
106
|
# Create a conda virtual environment
|
|
107
|
-
conda create --name camel python=3.
|
|
107
|
+
conda create --name camel python=3.9
|
|
108
108
|
|
|
109
109
|
# Activate CAMEL conda environment
|
|
110
110
|
conda activate camel
|
|
111
111
|
|
|
112
112
|
# Clone github repo
|
|
113
|
-
git clone -b v0.1.5.
|
|
113
|
+
git clone -b v0.1.5.4 https://github.com/camel-ai/camel.git
|
|
114
114
|
|
|
115
115
|
# Change directory into project directory
|
|
116
116
|
cd camel
|
|
@@ -13,7 +13,10 @@
|
|
|
13
13
|
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
14
|
from typing import Optional, Union
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
try:
|
|
17
|
+
from unstructured.documents.elements import Element
|
|
18
|
+
except ImportError:
|
|
19
|
+
Element = None
|
|
17
20
|
|
|
18
21
|
from camel.agents import ChatAgent
|
|
19
22
|
from camel.messages import BaseMessage
|
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
# See the License for the specific language governing permissions and
|
|
12
12
|
# limitations under the License.
|
|
13
13
|
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
14
16
|
from abc import ABC, abstractmethod
|
|
15
|
-
from typing import Any, Generic,
|
|
17
|
+
from typing import Any, Generic, TypeVar
|
|
16
18
|
|
|
17
19
|
T = TypeVar('T')
|
|
18
20
|
|
|
@@ -23,19 +25,18 @@ class BaseEmbedding(ABC, Generic[T]):
|
|
|
23
25
|
@abstractmethod
|
|
24
26
|
def embed_list(
|
|
25
27
|
self,
|
|
26
|
-
objs:
|
|
28
|
+
objs: list[T],
|
|
27
29
|
**kwargs: Any,
|
|
28
|
-
) ->
|
|
30
|
+
) -> list[list[float]]:
|
|
29
31
|
r"""Generates embeddings for the given texts.
|
|
30
32
|
|
|
31
33
|
Args:
|
|
32
|
-
objs (
|
|
34
|
+
objs (list[T]): The objects for which to generate the embeddings.
|
|
33
35
|
**kwargs (Any): Extra kwargs passed to the embedding API.
|
|
34
36
|
|
|
35
37
|
Returns:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
numpy matrix with embeddings.
|
|
38
|
+
list[list[float]]: A list that represents the
|
|
39
|
+
generated embedding as a list of floating-point numbers.
|
|
39
40
|
"""
|
|
40
41
|
pass
|
|
41
42
|
|
|
@@ -43,7 +44,7 @@ class BaseEmbedding(ABC, Generic[T]):
|
|
|
43
44
|
self,
|
|
44
45
|
obj: T,
|
|
45
46
|
**kwargs: Any,
|
|
46
|
-
) ->
|
|
47
|
+
) -> list[float]:
|
|
47
48
|
r"""Generates an embedding for the given text.
|
|
48
49
|
|
|
49
50
|
Args:
|
|
@@ -51,7 +52,7 @@ class BaseEmbedding(ABC, Generic[T]):
|
|
|
51
52
|
**kwargs (Any): Extra kwargs passed to the embedding API.
|
|
52
53
|
|
|
53
54
|
Returns:
|
|
54
|
-
|
|
55
|
+
list[float]: A list of floating-point numbers representing the
|
|
55
56
|
generated embedding.
|
|
56
57
|
"""
|
|
57
58
|
return self.embed_list([obj], **kwargs)[0]
|
|
@@ -11,10 +11,12 @@
|
|
|
11
11
|
# See the License for the specific language governing permissions and
|
|
12
12
|
# limitations under the License.
|
|
13
13
|
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
14
16
|
import os
|
|
15
|
-
from typing import Any
|
|
17
|
+
from typing import Any
|
|
16
18
|
|
|
17
|
-
from openai import OpenAI
|
|
19
|
+
from openai import NOT_GIVEN, NotGiven, OpenAI
|
|
18
20
|
|
|
19
21
|
from camel.embeddings.base import BaseEmbedding
|
|
20
22
|
from camel.types import EmbeddingModelType
|
|
@@ -25,10 +27,13 @@ class OpenAIEmbedding(BaseEmbedding[str]):
|
|
|
25
27
|
r"""Provides text embedding functionalities using OpenAI's models.
|
|
26
28
|
|
|
27
29
|
Args:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
model_type (EmbeddingModelType, optional): The model type to be
|
|
31
|
+
used for text embeddings.
|
|
32
|
+
(default: :obj:`TEXT_EMBEDDING_3_SMALL`)
|
|
33
|
+
api_key (str, optional): The API key for authenticating with the
|
|
31
34
|
OpenAI service. (default: :obj:`None`)
|
|
35
|
+
dimensions (int, optional): The text embedding output dimensions.
|
|
36
|
+
(default: :obj:`NOT_GIVEN`)
|
|
32
37
|
|
|
33
38
|
Raises:
|
|
34
39
|
RuntimeError: If an unsupported model type is specified.
|
|
@@ -36,36 +41,44 @@ class OpenAIEmbedding(BaseEmbedding[str]):
|
|
|
36
41
|
|
|
37
42
|
def __init__(
|
|
38
43
|
self,
|
|
39
|
-
model_type: EmbeddingModelType =
|
|
40
|
-
|
|
44
|
+
model_type: EmbeddingModelType = (
|
|
45
|
+
EmbeddingModelType.TEXT_EMBEDDING_3_SMALL
|
|
46
|
+
),
|
|
47
|
+
api_key: str | None = None,
|
|
48
|
+
dimensions: int | NotGiven = NOT_GIVEN,
|
|
41
49
|
) -> None:
|
|
42
50
|
if not model_type.is_openai:
|
|
43
51
|
raise ValueError("Invalid OpenAI embedding model type.")
|
|
44
52
|
self.model_type = model_type
|
|
45
|
-
|
|
53
|
+
if dimensions == NOT_GIVEN:
|
|
54
|
+
self.output_dim = model_type.output_dim
|
|
55
|
+
else:
|
|
56
|
+
assert isinstance(dimensions, int)
|
|
57
|
+
self.output_dim = dimensions
|
|
46
58
|
self._api_key = api_key or os.environ.get("OPENAI_API_KEY")
|
|
47
59
|
self.client = OpenAI(timeout=60, max_retries=3, api_key=self._api_key)
|
|
48
60
|
|
|
49
61
|
@model_api_key_required
|
|
50
62
|
def embed_list(
|
|
51
63
|
self,
|
|
52
|
-
objs:
|
|
64
|
+
objs: list[str],
|
|
53
65
|
**kwargs: Any,
|
|
54
|
-
) ->
|
|
66
|
+
) -> list[list[float]]:
|
|
55
67
|
r"""Generates embeddings for the given texts.
|
|
56
68
|
|
|
57
69
|
Args:
|
|
58
|
-
objs (
|
|
70
|
+
objs (list[str]): The texts for which to generate the embeddings.
|
|
59
71
|
**kwargs (Any): Extra kwargs passed to the embedding API.
|
|
60
72
|
|
|
61
73
|
Returns:
|
|
62
|
-
|
|
74
|
+
list[list[float]]: A list that represents the generated embedding
|
|
63
75
|
as a list of floating-point numbers.
|
|
64
76
|
"""
|
|
65
77
|
# TODO: count tokens
|
|
66
78
|
response = self.client.embeddings.create(
|
|
67
79
|
input=objs,
|
|
68
80
|
model=self.model_type.value,
|
|
81
|
+
dimensions=self.output_dim,
|
|
69
82
|
**kwargs,
|
|
70
83
|
)
|
|
71
84
|
return [data.embedding for data in response.data]
|
|
@@ -11,51 +11,63 @@
|
|
|
11
11
|
# See the License for the specific language governing permissions and
|
|
12
12
|
# limitations under the License.
|
|
13
13
|
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
|
-
from
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from numpy import ndarray
|
|
15
19
|
|
|
16
20
|
from camel.embeddings.base import BaseEmbedding
|
|
17
21
|
|
|
18
22
|
|
|
19
23
|
class SentenceTransformerEncoder(BaseEmbedding[str]):
|
|
20
|
-
r"""This class provides functionalities to generate
|
|
21
|
-
using
|
|
24
|
+
r"""This class provides functionalities to generate text
|
|
25
|
+
embeddings using `Sentence Transformers`.
|
|
22
26
|
|
|
23
27
|
References:
|
|
24
28
|
https://www.sbert.net/
|
|
25
29
|
"""
|
|
26
30
|
|
|
27
|
-
def __init__(
|
|
31
|
+
def __init__(
|
|
32
|
+
self,
|
|
33
|
+
model_name: str = "intfloat/e5-large-v2",
|
|
34
|
+
**kwargs,
|
|
35
|
+
):
|
|
28
36
|
r"""Initializes the: obj: `SentenceTransformerEmbedding` class
|
|
29
37
|
with the specified transformer model.
|
|
30
38
|
|
|
31
39
|
Args:
|
|
32
40
|
model_name (str, optional): The name of the model to use.
|
|
33
|
-
|
|
41
|
+
(default: :obj:`intfloat/e5-large-v2`)
|
|
42
|
+
**kwargs (optional): Additional arguments of
|
|
43
|
+
:class:`SentenceTransformer`, such as :obj:`prompts` etc.
|
|
34
44
|
"""
|
|
35
45
|
from sentence_transformers import SentenceTransformer
|
|
36
46
|
|
|
37
|
-
self.model = SentenceTransformer(model_name)
|
|
47
|
+
self.model = SentenceTransformer(model_name, **kwargs)
|
|
38
48
|
|
|
39
49
|
def embed_list(
|
|
40
50
|
self,
|
|
41
|
-
objs:
|
|
51
|
+
objs: list[str],
|
|
42
52
|
**kwargs: Any,
|
|
43
|
-
) ->
|
|
53
|
+
) -> list[list[float]]:
|
|
44
54
|
r"""Generates embeddings for the given texts using the model.
|
|
45
55
|
|
|
46
56
|
Args:
|
|
47
|
-
objs (
|
|
48
|
-
|
|
57
|
+
objs (list[str]): The texts for which to generate the
|
|
58
|
+
embeddings.
|
|
49
59
|
|
|
50
60
|
Returns:
|
|
51
|
-
|
|
61
|
+
list[list[float]]: A list that represents the generated embedding
|
|
52
62
|
as a list of floating-point numbers.
|
|
53
63
|
"""
|
|
54
64
|
if not objs:
|
|
55
65
|
raise ValueError("Input text list is empty")
|
|
56
|
-
|
|
66
|
+
embeddings = self.model.encode(
|
|
57
67
|
objs, normalize_embeddings=True, **kwargs
|
|
58
|
-
)
|
|
68
|
+
)
|
|
69
|
+
assert isinstance(embeddings, ndarray)
|
|
70
|
+
return embeddings.tolist()
|
|
59
71
|
|
|
60
72
|
def get_output_dim(self) -> int:
|
|
61
73
|
r"""Returns the output dimension of the embeddings.
|
|
@@ -63,4 +75,6 @@ class SentenceTransformerEncoder(BaseEmbedding[str]):
|
|
|
63
75
|
Returns:
|
|
64
76
|
int: The dimensionality of the embeddings.
|
|
65
77
|
"""
|
|
66
|
-
|
|
78
|
+
output_dim = self.model.get_sentence_embedding_dimension()
|
|
79
|
+
assert isinstance(output_dim, int)
|
|
80
|
+
return output_dim
|
|
@@ -159,11 +159,11 @@ class AutoRetriever:
|
|
|
159
159
|
) -> str:
|
|
160
160
|
r"""Retrieves the last modified date and time of a given file. This
|
|
161
161
|
function takes vector storage instance as input and returns the last
|
|
162
|
-
modified date from the
|
|
162
|
+
modified date from the metadata.
|
|
163
163
|
|
|
164
164
|
Args:
|
|
165
165
|
vector_storage_instance (BaseVectorStorage): The vector storage
|
|
166
|
-
where modified date is to be retrieved from
|
|
166
|
+
where modified date is to be retrieved from metadata.
|
|
167
167
|
|
|
168
168
|
Returns:
|
|
169
169
|
str: The last modified date from vector storage.
|
|
@@ -16,7 +16,10 @@ from __future__ import annotations
|
|
|
16
16
|
from dataclasses import dataclass, field
|
|
17
17
|
from typing import List, Union
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
try:
|
|
20
|
+
from unstructured.documents.elements import Element
|
|
21
|
+
except ImportError:
|
|
22
|
+
Element = None
|
|
20
23
|
|
|
21
24
|
|
|
22
25
|
@dataclass
|
|
@@ -72,3 +75,8 @@ class GraphElement:
|
|
|
72
75
|
nodes: List[Node]
|
|
73
76
|
relationships: List[Relationship]
|
|
74
77
|
source: Element
|
|
78
|
+
|
|
79
|
+
def __post_init__(self):
|
|
80
|
+
if Element is None:
|
|
81
|
+
raise ImportError("""The 'unstructured' package is required to use
|
|
82
|
+
the 'source' attribute.""")
|
|
@@ -49,6 +49,7 @@ class ModelType(Enum):
|
|
|
49
49
|
CLAUDE_3_OPUS = "claude-3-opus-20240229"
|
|
50
50
|
CLAUDE_3_SONNET = "claude-3-sonnet-20240229"
|
|
51
51
|
CLAUDE_3_HAIKU = "claude-3-haiku-20240307"
|
|
52
|
+
CLAUDE_3_5_SONNET = "claude-3-5-sonnet-20240620"
|
|
52
53
|
|
|
53
54
|
# Nvidia models
|
|
54
55
|
NEMOTRON_4_REWARD = "nvidia/nemotron-4-340b-reward"
|
|
@@ -104,6 +105,7 @@ class ModelType(Enum):
|
|
|
104
105
|
ModelType.CLAUDE_3_OPUS,
|
|
105
106
|
ModelType.CLAUDE_3_SONNET,
|
|
106
107
|
ModelType.CLAUDE_3_HAIKU,
|
|
108
|
+
ModelType.CLAUDE_3_5_SONNET,
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
@property
|
|
@@ -155,6 +157,7 @@ class ModelType(Enum):
|
|
|
155
157
|
ModelType.CLAUDE_3_OPUS,
|
|
156
158
|
ModelType.CLAUDE_3_SONNET,
|
|
157
159
|
ModelType.CLAUDE_3_HAIKU,
|
|
160
|
+
ModelType.CLAUDE_3_5_SONNET,
|
|
158
161
|
}:
|
|
159
162
|
return 200_000
|
|
160
163
|
elif self is ModelType.NEMOTRON_4_REWARD:
|
|
@@ -186,35 +189,27 @@ class ModelType(Enum):
|
|
|
186
189
|
|
|
187
190
|
|
|
188
191
|
class EmbeddingModelType(Enum):
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
CURIE_1 = "text-embedding-curie-001"
|
|
193
|
-
DAVINCI_1 = "text-embedding-davinci-001"
|
|
192
|
+
TEXT_EMBEDDING_ADA_2 = "text-embedding-ada-002"
|
|
193
|
+
TEXT_EMBEDDING_3_SMALL = "text-embedding-3-small"
|
|
194
|
+
TEXT_EMBEDDING_3_LARGE = "text-embedding-3-large"
|
|
194
195
|
|
|
195
196
|
@property
|
|
196
197
|
def is_openai(self) -> bool:
|
|
197
198
|
r"""Returns whether this type of models is an OpenAI-released model."""
|
|
198
199
|
return self in {
|
|
199
|
-
EmbeddingModelType.
|
|
200
|
-
EmbeddingModelType.
|
|
201
|
-
EmbeddingModelType.
|
|
202
|
-
EmbeddingModelType.CURIE_1,
|
|
203
|
-
EmbeddingModelType.DAVINCI_1,
|
|
200
|
+
EmbeddingModelType.TEXT_EMBEDDING_ADA_2,
|
|
201
|
+
EmbeddingModelType.TEXT_EMBEDDING_3_SMALL,
|
|
202
|
+
EmbeddingModelType.TEXT_EMBEDDING_3_LARGE,
|
|
204
203
|
}
|
|
205
204
|
|
|
206
205
|
@property
|
|
207
206
|
def output_dim(self) -> int:
|
|
208
|
-
if self is EmbeddingModelType.
|
|
207
|
+
if self is EmbeddingModelType.TEXT_EMBEDDING_ADA_2:
|
|
209
208
|
return 1536
|
|
210
|
-
elif self is EmbeddingModelType.
|
|
211
|
-
return
|
|
212
|
-
elif self is EmbeddingModelType.
|
|
213
|
-
return
|
|
214
|
-
elif self is EmbeddingModelType.CURIE_1:
|
|
215
|
-
return 4096
|
|
216
|
-
elif self is EmbeddingModelType.DAVINCI_1:
|
|
217
|
-
return 12288
|
|
209
|
+
elif self is EmbeddingModelType.TEXT_EMBEDDING_3_SMALL:
|
|
210
|
+
return 1536
|
|
211
|
+
elif self is EmbeddingModelType.TEXT_EMBEDDING_3_LARGE:
|
|
212
|
+
return 3072
|
|
218
213
|
else:
|
|
219
214
|
raise ValueError(f"Unknown model type {self}.")
|
|
220
215
|
|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
4
4
|
|
|
5
5
|
[tool.poetry]
|
|
6
6
|
name = "camel-ai"
|
|
7
|
-
version = "0.1.5.
|
|
7
|
+
version = "0.1.5.4"
|
|
8
8
|
authors = ["CAMEL-AI.org"]
|
|
9
9
|
description = "Communicative Agents for AI Society Study"
|
|
10
10
|
readme = "README.md"
|
|
@@ -27,7 +27,7 @@ repository = "https://github.com/camel-ai/camel"
|
|
|
27
27
|
documentation = "https://docs.camel-ai.org"
|
|
28
28
|
|
|
29
29
|
[tool.poetry.dependencies]
|
|
30
|
-
python = ">=3.
|
|
30
|
+
python = ">=3.9.0,<3.12"
|
|
31
31
|
numpy = "^1"
|
|
32
32
|
openai = "^1.2.3"
|
|
33
33
|
tiktoken = "^0.7.0"
|
|
@@ -35,10 +35,11 @@ colorama = "^0"
|
|
|
35
35
|
jsonschema = "^4"
|
|
36
36
|
protobuf = "^4"
|
|
37
37
|
pathlib = "^1.0.1"
|
|
38
|
-
anthropic = "^0.
|
|
38
|
+
anthropic = "^0.29.0"
|
|
39
39
|
docstring-parser = "^0.15"
|
|
40
40
|
pydantic = ">=1.9,<3"
|
|
41
41
|
curl_cffi = "0.6.2"
|
|
42
|
+
pillow ="^10.2.0"
|
|
42
43
|
|
|
43
44
|
# model-platforms
|
|
44
45
|
litellm = { version = "^1.38.1", optional = true }
|
|
@@ -67,16 +68,15 @@ requests_oauthlib = { version = "^1.3.1", optional = true }
|
|
|
67
68
|
prance = { version = "^23.6.21.0", optional = true }
|
|
68
69
|
openapi-spec-validator = { version = "^0.7.1", optional = true }
|
|
69
70
|
unstructured = { extras = ["all-docs"], version = "^0.10.30", optional = true }
|
|
70
|
-
pillow = { version = "^10.2.0", optional = true }
|
|
71
71
|
slack-sdk = { version = "^3.27.2", optional = true }
|
|
72
72
|
pydub = { version = "^0.25.1", optional = true }
|
|
73
73
|
pygithub = { version = "^2.3.0", optional = true }
|
|
74
|
-
imageio = { version = "^2.34.
|
|
74
|
+
imageio = {extras = ["pyav"], version = "^2.34.2"}
|
|
75
75
|
pyTelegramBotAPI = { version = "^4.18.0", optional = true }
|
|
76
76
|
"discord.py" = { version = "^2.3.2", optional = true }
|
|
77
77
|
|
|
78
78
|
# encoders
|
|
79
|
-
sentence-transformers = { version = "^
|
|
79
|
+
sentence-transformers = { version = "^3.0.1", optional = true }
|
|
80
80
|
|
|
81
81
|
# vector-databases
|
|
82
82
|
qdrant-client = { version = "^1.9.0", optional = true }
|
|
@@ -1,20 +0,0 @@
|
|
|
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 .discord_bot import DiscordBot
|
|
15
|
-
from .telegram_bot import TelegramBot
|
|
16
|
-
|
|
17
|
-
__all__ = [
|
|
18
|
-
'DiscordBot',
|
|
19
|
-
'TelegramBot',
|
|
20
|
-
]
|
|
@@ -1,103 +0,0 @@
|
|
|
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 os
|
|
15
|
-
from typing import TYPE_CHECKING, List, Optional
|
|
16
|
-
|
|
17
|
-
from camel.agents import ChatAgent
|
|
18
|
-
from camel.messages import BaseMessage
|
|
19
|
-
|
|
20
|
-
if TYPE_CHECKING:
|
|
21
|
-
from discord import Message
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class DiscordBot:
|
|
25
|
-
r"""Represents a Discord bot that is powered by an agent.
|
|
26
|
-
|
|
27
|
-
Attributes:
|
|
28
|
-
chat_agent (ChatAgent): Chat agent that will power the bot.
|
|
29
|
-
channel_ids (List[int], optional): The channel IDs that the bot will
|
|
30
|
-
listen to.
|
|
31
|
-
discord_token (str, optional): The bot token.
|
|
32
|
-
"""
|
|
33
|
-
|
|
34
|
-
def __init__(
|
|
35
|
-
self,
|
|
36
|
-
chat_agent: ChatAgent,
|
|
37
|
-
channel_ids: Optional[List[int]] = None,
|
|
38
|
-
discord_token: Optional[str] = None,
|
|
39
|
-
) -> None:
|
|
40
|
-
self.chat_agent = chat_agent
|
|
41
|
-
self.token = discord_token or os.getenv('DISCORD_TOKEN')
|
|
42
|
-
self.channel_ids = channel_ids
|
|
43
|
-
|
|
44
|
-
if not self.token:
|
|
45
|
-
raise ValueError(
|
|
46
|
-
"`DISCORD_TOKEN` not found in environment variables. Get it"
|
|
47
|
-
" here: `https://discord.com/developers/applications`."
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
try:
|
|
51
|
-
import discord
|
|
52
|
-
except ImportError:
|
|
53
|
-
raise ImportError(
|
|
54
|
-
"Please install `discord` first. You can install it by running"
|
|
55
|
-
" `python3 -m pip install -U discord.py`."
|
|
56
|
-
)
|
|
57
|
-
intents = discord.Intents.default()
|
|
58
|
-
intents.message_content = True
|
|
59
|
-
self.client = discord.Client(intents=intents)
|
|
60
|
-
|
|
61
|
-
# Register event handlers
|
|
62
|
-
self.client.event(self.on_ready)
|
|
63
|
-
self.client.event(self.on_message)
|
|
64
|
-
|
|
65
|
-
def run(self) -> None:
|
|
66
|
-
r"""Start the Discord bot using its token.
|
|
67
|
-
|
|
68
|
-
This method starts the Discord bot by running the client with the
|
|
69
|
-
provided token.
|
|
70
|
-
"""
|
|
71
|
-
self.client.run(self.token) # type: ignore[arg-type]
|
|
72
|
-
|
|
73
|
-
async def on_ready(self) -> None:
|
|
74
|
-
r"""This method is called when the bot has successfully connected to
|
|
75
|
-
the Discord server.
|
|
76
|
-
|
|
77
|
-
It prints a message indicating that the bot has logged in and displays
|
|
78
|
-
the username of the bot.
|
|
79
|
-
"""
|
|
80
|
-
print(f'We have logged in as {self.client.user}')
|
|
81
|
-
|
|
82
|
-
async def on_message(self, message: 'Message') -> None:
|
|
83
|
-
r"""Event handler for when a message is received.
|
|
84
|
-
|
|
85
|
-
Args:
|
|
86
|
-
message (discord.Message): The message object received.
|
|
87
|
-
"""
|
|
88
|
-
if message.author == self.client.user:
|
|
89
|
-
return
|
|
90
|
-
|
|
91
|
-
if self.channel_ids and message.channel.id not in self.channel_ids:
|
|
92
|
-
return
|
|
93
|
-
|
|
94
|
-
if not self.client.user or not self.client.user.mentioned_in(message):
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
self.chat_agent.reset()
|
|
98
|
-
|
|
99
|
-
user_msg = BaseMessage.make_user_message(
|
|
100
|
-
role_name="User", content=message.content
|
|
101
|
-
)
|
|
102
|
-
assistant_response = self.chat_agent.step(user_msg)
|
|
103
|
-
await message.channel.send(assistant_response.msg.content)
|