[FEAT][PostHog rmeoval]

pull/299/head
Kye 1 year ago
parent 4428a25ed2
commit a68eeec370

@ -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)

@ -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 <kye@apac.ai>"]

@ -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("<agent_id>") and line.endwith(
"</agent_id>"
):
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."
)

@ -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",

@ -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

@ -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"

Loading…
Cancel
Save