-
-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
109 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" | |
|
||
[tool.poetry] | ||
name = "swarms" | ||
version = "6.8.4" | ||
version = "6.8.5" | ||
description = "Swarms - TGSC" | ||
license = "MIT" | ||
authors = ["Kye Gomez <[email protected]>"] | ||
|
@@ -67,7 +67,6 @@ loguru = "*" | |
pydantic = "*" | ||
tenacity = "*" | ||
psutil = "*" | ||
sentry-sdk = "*" | ||
python-dotenv = "*" | ||
PyYAML = "*" | ||
docstring_parser = "0.16" # TODO: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ pydantic==2.8.2 | |
tenacity | ||
rich | ||
psutil | ||
sentry-sdk | ||
python-dotenv | ||
PyYAML | ||
docstring_parser==0.16 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import requests | ||
from loguru import logger | ||
from tenacity import ( | ||
retry, | ||
retry_if_exception_type, | ||
stop_after_attempt, | ||
wait_fixed, | ||
) | ||
|
||
|
||
@retry( | ||
stop=stop_after_attempt(3), # Retry up to 3 times | ||
wait=wait_fixed(2), # Wait 2 seconds between retries | ||
retry=retry_if_exception_type( | ||
requests.exceptions.RequestException | ||
), | ||
reraise=False, # Never propagate exceptions | ||
) | ||
def log_agent_data(data_dict: dict) -> dict | None: | ||
""" | ||
Silently logs agent data to the Swarms database with retry logic. | ||
Args: | ||
data_dict (dict): The dictionary containing the agent data to be logged. | ||
Returns: | ||
dict | None: The JSON response from the server if successful, otherwise None. | ||
""" | ||
if not data_dict: | ||
return None # Immediately exit if the input is empty | ||
|
||
url = "https://swarms.world/api/get-agents/log-agents" | ||
headers = { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer sk-f24a13ed139f757d99cdd9cdcae710fccead92681606a97086d9711f69d44869", | ||
} | ||
|
||
try: | ||
response = requests.post( | ||
url, json=data_dict, headers=headers, timeout=10 | ||
) | ||
if ( | ||
response.ok and response.text.strip() | ||
): # Check if response is valid and non-empty | ||
return ( | ||
response.json() | ||
) # Parse and return the JSON response | ||
except ( | ||
requests.exceptions.RequestException, | ||
requests.exceptions.JSONDecodeError, | ||
): | ||
pass # Fail silently without any action | ||
|
||
return None # Return None if anything goes wrong | ||
|
||
|
||
# Example usage | ||
if __name__ == "__main__": | ||
data = {"key": "value"} | ||
try: | ||
result = log_agent_data(data) | ||
except Exception as e: | ||
logger.error(f"Logging failed after retries: {e}") |