diff --git a/community_usecase/Smart_city_research/main.py b/community_usecase/Smart_city_research/main.py new file mode 100644 index 000000000..1514ab38e --- /dev/null +++ b/community_usecase/Smart_city_research/main.py @@ -0,0 +1,155 @@ +# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. ========= +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. ========= +import sys +import pathlib +from dotenv import load_dotenv +from camel.configs import MistralConfig +from camel.models import ModelFactory +from camel.toolkits import ( + SearchToolkit, + BrowserToolkit, + FileWriteToolkit, + TerminalToolkit, + PyAutoGUIToolkit, + +) +from camel.types import ModelPlatformType, ModelType + +from camel.societies import RolePlaying +import os +from camel.logger import get_logger, set_log_file,set_log_level +from owl.utils import run_society, DocumentProcessingToolkit + +# Set logging +set_log_file("product.log") +logger = get_logger(__name__) +set_log_level(level="DEBUG") + + +# Load environment variables +load_dotenv(os.path.join(os.path.dirname(__file__), '../../owl/.env')) +base_dir = os.path.dirname(os.path.abspath(__file__)) +workspace_dir = os.path.join( + os.path.dirname(os.path.dirname(base_dir)), "workspace" +) + + +def construct_society(question: str) -> RolePlaying: + r"""Construct a society of agents based on the given question. + + Args: + question (str): The task or question to be addressed by the society. + + Returns: + RolePlaying: A configured society of agents ready to address the question. + """ + + # Create models for different components + models = { + "user": ModelFactory.create( + model_platform=ModelPlatformType.MISTRAL, + model_type="pixtral-large-latest", + model_config_dict=MistralConfig(temperature=0.0).as_dict(), + ), + "assistant": ModelFactory.create( + model_platform=ModelPlatformType.MISTRAL, + model_type="pixtral-large-latest", + model_config_dict=MistralConfig(temperature=0.0).as_dict(), + ), + "document": ModelFactory.create( + model_platform=ModelPlatformType.MISTRAL, + model_type="pixtral-large-latest", + model_config_dict=MistralConfig(temperature=0.0).as_dict(), + ), + "browsing": ModelFactory.create( + model_platform=ModelPlatformType.MISTRAL, + model_type="pixtral-large-latest", + model_config_dict=MistralConfig(temperature=0.0).as_dict(), + ), + "planning": ModelFactory.create( + model_platform=ModelPlatformType.MISTRAL, + model_type=ModelType.MISTRAL_LARGE, + model_config_dict=MistralConfig(temperature=0.0).as_dict(), + ), + + + } + + # Configure toolkits + tools = [ + *BrowserToolkit( + headless=False, # Set to True for headless mode (e.g., on remote servers) + web_agent_model=models["browsing"], + planning_agent_model=models["planning"], + ).get_tools(), + *PyAutoGUIToolkit().get_tools(), + *TerminalToolkit(working_dir=workspace_dir).get_tools(), + SearchToolkit().search_duckduckgo, + # SearchToolkit().search_google, # Comment this out if you don't have google search + *DocumentProcessingToolkit(model=models["document"]).get_tools(), + *FileWriteToolkit(output_dir="./").get_tools(), + ] + + # Configure agent roles and parameters + user_agent_kwargs = {"model": models["user"]} + assistant_agent_kwargs = {"model": models["assistant"], "tools": tools} + + # Configure task parameters + task_kwargs = { + "task_prompt": question, + "with_task_specify": False, + } + + # Create and return the society + society = RolePlaying( + **task_kwargs, + user_role_name="user", + user_agent_kwargs=user_agent_kwargs, + assistant_role_name="assistant", + assistant_agent_kwargs=assistant_agent_kwargs, + ) + + return society + + +def main(): + r"""Main function to run the OWL system with an example question.""" + # Default research question + default_task = """ +please help me to make a research on smart city technology. +Fisrtly, please use the duckduckgo search to search the following topic: +What are the current trends in smart city technology? +and then,only browse the most related website urls to get the information. + +secondly, make a pdf for me to present the research results. + +finally, open the pdf and take screenshot for me. +if there are some packages that are not installed, please install them for me. + + +""" + + # Override default task if command line argument is provided + task = sys.argv[1] if len(sys.argv) > 1 else default_task + + # Construct and run the society + society = construct_society(task) + answer, chat_history, token_count = run_society(society) + + # Output the result + print(f"\033[94mAnswer: {answer}\033[0m") + + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml index e072688a3..174e74bef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ keywords = [ "learning-systems" ] dependencies = [ - "camel-ai[owl]==0.2.52", + "camel-ai[owl]==0.2.54", "docx2markdown>=0.1.1", "gradio>=3.50.2", "mcp-simple-arxiv==0.2.2", diff --git a/requirements.txt b/requirements.txt index 4031cba4e..667184334 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -camel-ai[owl]==0.2.52 +camel-ai[owl]==0.2.54 docx2markdown>=0.1.1 gradio>=3.50.2 mcp-simple-arxiv==0.2.2 diff --git a/uv.lock b/uv.lock index 648b072f4..82c750b7c 100644 --- a/uv.lock +++ b/uv.lock @@ -13,6 +13,22 @@ resolution-markers = [ "(python_full_version < '3.11' and platform_machine != 'aarch64' and sys_platform == 'linux') or (python_full_version < '3.11' and sys_platform != 'darwin' and sys_platform != 'linux')", ] +[[package]] +name = "aci-sdk" +version = "1.0.0b1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "griffe" }, + { name = "httpx" }, + { name = "pydantic" }, + { name = "tenacity" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/71/9d/0d956545331ac6760af30a7bc6492083a84b32f16faa89f28ee269a83dac/aci_sdk-1.0.0b1.tar.gz", hash = "sha256:9130bf196c680deda2004d71b091883bc468ea1649d71dbf676b9172c067d4ef", size = 63449 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e2/57/2f1cfb3ee6a84e355a09dd94a4c3c5d1dbe9dbb925950c6903cb8ef2a216/aci_sdk-1.0.0b1-py3-none-any.whl", hash = "sha256:f3d9f3de58c518ecf4fc44ebedf1e4a1e23a30df268782989d1ce8852bd47175", size = 31713 }, +] + [[package]] name = "aiofiles" version = "24.1.0" @@ -257,7 +273,7 @@ wheels = [ [[package]] name = "camel-ai" -version = "0.2.52" +version = "0.2.54" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "colorama" }, @@ -270,13 +286,14 @@ dependencies = [ { name = "pydantic" }, { name = "tiktoken" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/c0/a8/7231d11a72292e97f8e805d80e9c7c9b70df1ce63388bc0fe11352dd8e18/camel_ai-0.2.52.tar.gz", hash = "sha256:b033e737f8e50e35eb2bb6e945b4113483b8aa43ad21c8a432c380c59aefa46d", size = 542315 } +sdist = { url = "https://files.pythonhosted.org/packages/53/87/e3f87c6fa0ee2bf27d62b1d82f0091d34a793b57e79158b9f2b9812e95e6/camel_ai-0.2.54.tar.gz", hash = "sha256:06f53e8312fb5040aa0fe2daf69b54feda6c51dbb12af2a2ea9a575d8c5d454b", size = 549261 } wheels = [ - { url = "https://files.pythonhosted.org/packages/bf/61/27fe54b9b0736acb4328dc66764b675a835b4e14b7498c650f922c2bae3b/camel_ai-0.2.52-py3-none-any.whl", hash = "sha256:cd4e1e7d91d0511e7689f8a6033bb382e54fbf2d57b8133983452cbc77d4f5b8", size = 906573 }, + { url = "https://files.pythonhosted.org/packages/cc/70/25605a9d9dd92f450cd5900f7469902fe4a1bf91455a3b4a84e6b8ad4203/camel_ai-0.2.54-py3-none-any.whl", hash = "sha256:dcb5fa588555f074d51ec3090893940aa258cd3008a698144ddcec57a60d5b9a", size = 916899 }, ] [package.optional-dependencies] owl = [ + { name = "aci-sdk" }, { name = "anthropic" }, { name = "beautifulsoup4" }, { name = "chunkr-ai" }, @@ -1175,6 +1192,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/c0/ba/82a2c3b9868644ee6011da742156247070f30e952f4d33f33857458450f2/greenlet-3.2.1-cp312-cp312-win_amd64.whl", hash = "sha256:7132e024ebeeeabbe661cf8878aac5d2e643975c4feae833142592ec2f03263d", size = 296207 }, ] +[[package]] +name = "griffe" +version = "1.7.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/a9/3e/5aa9a61f7c3c47b0b52a1d930302992229d191bf4bc76447b324b731510a/griffe-1.7.3.tar.gz", hash = "sha256:52ee893c6a3a968b639ace8015bec9d36594961e156e23315c8e8e51401fa50b", size = 395137 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/58/c6/5c20af38c2a57c15d87f7f38bee77d63c1d2a3689f74fefaf35915dd12b2/griffe-1.7.3-py3-none-any.whl", hash = "sha256:c6b3ee30c2f0f17f30bcdef5068d6ab7a2a4f1b8bf1a3e74b56fffd21e1c5f75", size = 129303 }, +] + [[package]] name = "groovy" version = "0.1.2" @@ -2347,7 +2376,7 @@ dependencies = [ [package.metadata] requires-dist = [ - { name = "camel-ai", extras = ["owl"], specifier = "==0.2.52" }, + { name = "camel-ai", extras = ["owl"], specifier = "==0.2.54" }, { name = "docx2markdown", specifier = ">=0.1.1" }, { name = "gradio", specifier = ">=3.50.2" }, { name = "mcp-server-fetch", specifier = "==2025.1.17" }, @@ -3838,6 +3867,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/40/44/4a5f08c96eb108af5cb50b41f76142f0afa346dfa99d5296fe7202a11854/tabulate-0.9.0-py3-none-any.whl", hash = "sha256:024ca478df22e9340661486f85298cff5f6dcdba14f3813e8830015b9ed1948f", size = 35252 }, ] +[[package]] +name = "tenacity" +version = "9.1.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/0a/d4/2b0cd0fe285e14b36db076e78c93766ff1d529d70408bd1d2a5a84f1d929/tenacity-9.1.2.tar.gz", hash = "sha256:1169d376c297e7de388d18b4481760d478b0e99a777cad3a9c86e556f4b697cb", size = 48036 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e5/30/643397144bfbfec6f6ef821f36f33e57d35946c44a2352d3c9f0ae847619/tenacity-9.1.2-py3-none-any.whl", hash = "sha256:f77bf36710d8b73a50b2dd155c97b870017ad21afe6ab300326b0371b3b05138", size = 28248 }, +] + [[package]] name = "tf-playwright-stealth" version = "1.1.2"