diff --git a/gemini.py b/playground/models/gemini.py similarity index 52% rename from gemini.py rename to playground/models/gemini.py index 99b3f49c..1184d8a8 100644 --- a/gemini.py +++ b/playground/models/gemini.py @@ -1,12 +1,18 @@ +import os +from dotenv import load_dotenv from swarms.models.gemini import Gemini +load_dotenv() + +api_key = os.environ["GEMINI_API_KEY"] + # Initialize the model -model = Gemini() +model = Gemini(gemini_api_key=api_key) # Establish the prompt and image task = "What is your name" img = "images/github-banner-swarms.png" # Run the model -out = model.run("What is your name?", img) +out = model.run("What is your name?") print(out) diff --git a/pyproject.toml b/pyproject.toml index 76a1e13b..3d906765 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms" -version = "2.8.5" +version = "2.8.6" description = "Swarms - Pytorch" license = "MIT" authors = ["Kye Gomez "] diff --git a/swarms/swarms/utils.py b/swarms/swarms/utils.py new file mode 100644 index 00000000..73da08df --- /dev/null +++ b/swarms/swarms/utils.py @@ -0,0 +1,68 @@ +from typing import Dict, Any, List +from swarms.structs.agent import Agent + + +# Helper functions for manager/corporate agents +def parse_tasks( + task: str = None, +) -> Dict[str, Any]: + """Parse tasks + + Args: + task (str, optional): _description_. Defaults to None. + + Returns: + Dict[str, Any]: _description_ + """ + tasks = {} + for line in task.split("\n"): + if line.startswith("") and line.endwith( + "" + ): + agent_id, task = line[10:-11].split("><") + tasks[agent_id] = task + return tasks + + +def find_agent_by_id( + agent_id: str = None, agents: List[Agent] = None, *args, **kwargs +) -> Agent: + """Find agent by id + + Args: + agent_id (str, optional): _description_. Defaults to None. + agents (List[Agent], optional): _description_. Defaults to None. + + Returns: + Agent: _description_ + """ + for agent in agents: + if agent.id == agent_id: + return agent + return None + + +def distribute_tasks( + task: str = None, agents: List[Agent] = None, *args, **kwargs +): + """Distribute tasks to agents + + Args: + task (str, optional): _description_. Defaults to None. + agents (List[Agent], optional): _description_. Defaults to None. + """ + # Parse the task to extract tasks and agent id + tasks = parse_tasks(task) + + # Distribute tasks to agents + for agent_id, task in tasks.item(): + assigned_agent = find_agent_by_id(agent_id, agents) + if assigned_agent: + print(f"Assigning task {task} to agent {agent_id}") + output = assigned_agent.run(task, *args, **kwargs) + print(f"Output from agent {agent_id}: {output}") + else: + print( + f"No agent found with ID {agent_id}. Task '{task}' is" + " not assigned." + ) diff --git a/swarms/telemetry/__init__.py b/swarms/telemetry/__init__.py index fdac5bf5..82d84f37 100644 --- a/swarms/telemetry/__init__.py +++ b/swarms/telemetry/__init__.py @@ -1,5 +1,5 @@ from swarms.telemetry.log_all import log_all_calls, log_calls -from swarms.telemetry.posthog_utils import log_activity_posthog +# from swarms.telemetry.posthog_utils import log_activity_posthog from swarms.telemetry.user_utils import ( generate_user_id, get_machine_id, @@ -11,7 +11,7 @@ from swarms.telemetry.user_utils import ( __all__ = [ "log_all_calls", "log_calls", - "log_activity_posthog", + # "log_activity_posthog", "generate_user_id", "get_machine_id", "get_system_info", diff --git a/swarms/telemetry/posthog_utils.py b/swarms/telemetry/posthog_utils.py index 9cf9c649..a6a520b5 100644 --- a/swarms/telemetry/posthog_utils.py +++ b/swarms/telemetry/posthog_utils.py @@ -10,8 +10,8 @@ load_dotenv() # # Initialize Posthog client -api_key = os.getenv("POSTHOG_API_KEY") -host = os.getenv("POSTHOG_HOST") +api_key = os.getenv("POSTHOG_API_KEY") or None +host = os.getenv("POSTHOG_HOST") or None posthog = Posthog(api_key, host=host) posthog.debug = True diff --git a/tests/telemetry/test_posthog_utils.py b/tests/telemetry/test_posthog_utils.py index 1a35296a..0364cb3a 100644 --- a/tests/telemetry/test_posthog_utils.py +++ b/tests/telemetry/test_posthog_utils.py @@ -13,12 +13,14 @@ from swarms.telemetry.posthog_utils import ( def mock_posthog(): return Mock() + # Mock environment variables @pytest.fixture def mock_env(monkeypatch): monkeypatch.setenv("POSTHOG_API_KEY", "test_api_key") monkeypatch.setenv("POSTHOG_HOST", "test_host") + # Test the log_activity_posthog decorator def test_log_activity_posthog(mock_posthog, mock_env): event_name = "test_event" @@ -37,6 +39,7 @@ def test_log_activity_posthog(mock_posthog, mock_env): "test_user_id", event_name, event_properties ) + # Test a scenario where environment variables are not set def test_missing_env_variables(monkeypatch): # Unset environment variables @@ -51,6 +54,7 @@ def test_missing_env_variables(monkeypatch): # Ensure that calling the test function does not raise errors test_function() + # Test the Posthog client initialization def test_posthog_client_initialization(mock_env): assert posthog.api_key == "test_api_key"