From c35cf3472275c624aa45a2ae8b564cd1f03da946 Mon Sep 17 00:00:00 2001 From: Didier Durand Date: Tue, 1 Apr 2025 08:45:29 +0200 Subject: [PATCH] run module for Mistral models --- examples/run_mistral.py | 135 ++++++++++++++++++++++++++++++++++++++++ owl/webapp.py | 1 + 2 files changed, 136 insertions(+) create mode 100644 examples/run_mistral.py diff --git a/examples/run_mistral.py b/examples/run_mistral.py new file mode 100644 index 0000000..03e203a --- /dev/null +++ b/examples/run_mistral.py @@ -0,0 +1,135 @@ +import sys +import pathlib +from dotenv import load_dotenv +from camel.models import ModelFactory +from camel.toolkits import ( + AudioAnalysisToolkit, + CodeExecutionToolkit, + ExcelToolkit, + ImageAnalysisToolkit, + SearchToolkit, + VideoAnalysisToolkit, + BrowserToolkit, + FileWriteToolkit, +) +from camel.types import ModelPlatformType, ModelType +from camel.logger import set_log_level +from camel.societies import RolePlaying + +from owl.utils import run_society, DocumentProcessingToolkit + +base_dir = pathlib.Path(__file__).parent.parent +env_path = base_dir / "owl" / ".env" +load_dotenv(dotenv_path=str(env_path)) + +set_log_level(level="DEBUG") + + +def construct_society(question: str) -> RolePlaying: + r"""Construct a society of agents based on Mistral model(s). + + 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=ModelType.MISTRAL_LARGE, + model_config_dict={"temperature": 0}, + ), + "assistant": ModelFactory.create( + model_platform=ModelPlatformType.MISTRAL, + model_type=ModelType.MISTRAL_LARGE, + model_config_dict={"temperature": 0}, + ), + "browsing": ModelFactory.create( + model_platform=ModelPlatformType.MISTRAL, + model_type=ModelType.MISTRAL_LARGE, + model_config_dict={"temperature": 0}, + ), + "planning": ModelFactory.create( + model_platform=ModelPlatformType.MISTRAL, + model_type=ModelType.MISTRAL_LARGE, + model_config_dict={"temperature": 0}, + ), + "video": ModelFactory.create( + model_platform=ModelPlatformType.MISTRAL, + model_type=ModelType.MISTRAL_PIXTRAL_12B, + model_config_dict={"temperature": 0}, + ), + "image": ModelFactory.create( + model_platform=ModelPlatformType.MISTRAL, + model_type=ModelType.MISTRAL_PIXTRAL_12B, + model_config_dict={"temperature": 0}, + ), + "document": ModelFactory.create( + model_platform=ModelPlatformType.MISTRAL, + model_type=ModelType.MISTRAL_LARGE, + model_config_dict={"temperature": 0}, + ), + } + + # Configure toolkits + tools = [ + *BrowserToolkit( + headless=True, + web_agent_model=models["browsing"], + planning_agent_model=models["planning"], + ).get_tools(), + *VideoAnalysisToolkit(model=models["video"]).get_tools(), + *AudioAnalysisToolkit().get_tools(), + *CodeExecutionToolkit(sandbox="subprocess", verbose=True).get_tools(), + *ImageAnalysisToolkit(model=models["image"]).get_tools(), + SearchToolkit().search_duckduckgo, + SearchToolkit().search_google, + SearchToolkit().search_wiki, + *ExcelToolkit().get_tools(), + *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 = "Navigate to Amazon.com and identify one product that is attractive to coders. Please provide me with the product name and price. No need to verify your answer." + + # 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() \ No newline at end of file diff --git a/owl/webapp.py b/owl/webapp.py index 603aeea..95ad656 100644 --- a/owl/webapp.py +++ b/owl/webapp.py @@ -246,6 +246,7 @@ MODULE_DESCRIPTIONS = { "run_mini": "Using OpenAI model with minimal configuration to process tasks", "run_gemini": "Using Gemini model to process tasks", "run_deepseek_zh": "Using deepseek model to process Chinese tasks", + "run_mistral": "Using Mistral models to process tasks", "run_openai_compatible_model": "Using openai compatible model to process tasks", "run_ollama": "Using local ollama model to process tasks", "run_qwen_mini_zh": "Using qwen model with minimal configuration to process tasks",