From 834b9c559917460eed4293f5d3c7498f57d34857 Mon Sep 17 00:00:00 2001 From: Kye Gomez Date: Tue, 28 Jan 2025 13:27:49 -0500 Subject: [PATCH] [DOCS] [TESTS] [LAZY LOADING] --- ca_to_name.py | 96 -------------------- docs/guides/financial_analysis_swarm_mm.md | 6 +- docs/guides/healthcare_blog.md | 2 +- docs/index.md | 2 +- docs/mkdocs.yml | 2 +- docs/swarms_platform/index.md | 4 +- pyproject.toml | 2 +- swarms/utils/auto_download_check_packages.py | 4 + swarms/utils/litellm_tokenizer.py | 15 ++- tests/utils/test_auto_check_download.py | 65 +++++++++++++ 10 files changed, 91 insertions(+), 107 deletions(-) delete mode 100644 ca_to_name.py create mode 100644 tests/utils/test_auto_check_download.py diff --git a/ca_to_name.py b/ca_to_name.py deleted file mode 100644 index 8a9f3a3cd..000000000 --- a/ca_to_name.py +++ /dev/null @@ -1,96 +0,0 @@ -import base64 -import requests -from struct import unpack - - -class SolanaTokenInfoFetcher: - def __init__(self, rpc_url="https://api.mainnet-beta.solana.com"): - """ - Initializes the token info fetcher. - - Args: - rpc_url (str): The Solana RPC URL. - """ - self.rpc_url = rpc_url - - def make_rpc_request(self, method, params): - """ - Makes an RPC request to the Solana JSON RPC API. - - Args: - method (str): The RPC method to call. - params (list): The parameters for the method. - - Returns: - dict: The JSON response from the RPC call. - """ - headers = {"Content-Type": "application/json"} - payload = { - "jsonrpc": "2.0", - "id": 1, - "method": method, - "params": params, - } - try: - response = requests.post(self.rpc_url, json=payload, headers=headers) - response.raise_for_status() - return response.json() - except requests.exceptions.RequestException as e: - print(f"Error making RPC request: {e}") - return None - - def get_token_info(self, mint_address): - """ - Fetches token metadata (name, symbol) from the token mint account. - - Args: - mint_address (str): The token mint address. - - Returns: - dict: A dictionary containing the token name and symbol. - """ - params = [ - mint_address, - {"encoding": "base64"} - ] - response = self.make_rpc_request("getAccountInfo", params) - - if not response or "result" not in response or not response["result"]["value"]: - print(f"Failed to fetch data for mint address: {mint_address}") - return None - - # Decode the account data - account_data = response["result"]["value"]["data"][0] - decoded_data = base64.b64decode(account_data) - - # Extract token name and symbol - try: - token_name = decoded_data[0:32].decode("utf-8").rstrip("\x00") - token_symbol = decoded_data[32:44].decode("utf-8").rstrip("\x00") - decimals = unpack(" 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU - - # Initialize the token info fetcher - fetcher = SolanaTokenInfoFetcher() - - # Fetch and display token information - token_info = fetcher.get_token_info(mint_address) - - if token_info: - print(f"Token Name: {token_info['name']}") - print(f"Token Symbol: {token_info['symbol']}") - print(f"Decimals: {token_info['decimals']}") - else: - print("Failed to fetch token information.") diff --git a/docs/guides/financial_analysis_swarm_mm.md b/docs/guides/financial_analysis_swarm_mm.md index ea83b7d08..4448cbb22 100644 --- a/docs/guides/financial_analysis_swarm_mm.md +++ b/docs/guides/financial_analysis_swarm_mm.md @@ -7,7 +7,7 @@ Before we dive into the code, let's briefly introduce the Swarms framework. Swar For more information and to contribute to the project, visit the [Swarms GitHub repository](https://github.com/kyegomez/swarms). We highly recommend exploring the documentation for a deeper understanding of Swarms' capabilities. Additional resources: -- [Swarms Discord](https://discord.com/servers/agora-999382051935506503) for community discussions +- [Swarms Discord](https://discord.gg/swarms) for community discussions - [Swarms Twitter](https://x.com/swarms_corp) for updates - [Swarms Spotify](https://open.spotify.com/show/2HLiswhmUaMdjHC8AUHcCF?si=c831ef10c5ef4994) for podcasts - [Swarms Blog](https://medium.com/@kyeg) for in-depth articles @@ -460,7 +460,7 @@ This system provides a powerful foundation for financial analysis, but there's a Remember, the Swarms framework is a powerful and flexible tool that can be adapted to a wide range of complex tasks beyond just financial analysis. We encourage you to explore the [Swarms GitHub repository](https://github.com/kyegomez/swarms) for more examples and inspiration. -For more in-depth discussions and community support, consider joining the [Swarms Discord](https://discord.com/servers/agora-999382051935506503). You can also stay updated with the latest developments by following [Swarms on Twitter](https://x.com/swarms_corp). +For more in-depth discussions and community support, consider joining the [Swarms Discord](https://discord.gg/swarms). You can also stay updated with the latest developments by following [Swarms on Twitter](https://x.com/swarms_corp). If you're interested in learning more about AI and its applications in various fields, check out the [Swarms Spotify podcast](https://open.spotify.com/show/2HLiswhmUaMdjHC8AUHcCF?si=c831ef10c5ef4994) and the [Swarms Blog](https://medium.com/@kyeg) for insightful articles and discussions. @@ -474,7 +474,7 @@ By leveraging the power of multi-agent AI systems, you're well-equipped to navig * [Swarms Github](https://github.com/kyegomez/swarms) -* [Swarms Discord](https://discord.com/servers/agora-999382051935506503) +* [Swarms Discord](https://discord.gg/swarms) * [Swarms Twitter](https://x.com/swarms_corp) * [Swarms Spotify](https://open.spotify.com/show/2HLiswhmUaMdjHC8AUHcCF?si=c831ef10c5ef4994) * [Swarms Blog](https://medium.com/@kyeg) diff --git a/docs/guides/healthcare_blog.md b/docs/guides/healthcare_blog.md index 22d5d0532..306b8046f 100644 --- a/docs/guides/healthcare_blog.md +++ b/docs/guides/healthcare_blog.md @@ -261,7 +261,7 @@ The table below summarizes the estimated savings for each use case: - [book a call](https://cal.com/swarms) -- Swarms Discord: https://discord.com/servers/agora-999382051935506503 +- Swarms Discord: https://discord.gg/swarms - Swarms Twitter: https://x.com/swarms_corp diff --git a/docs/index.md b/docs/index.md index 86b6473c6..ca805029c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -39,7 +39,7 @@ Here you'll find references about the Swarms framework, marketplace, community, ## Community | Section | Links | |----------------------|--------------------------------------------------------------------------------------------| -| Community | [Discord](https://discord.com/servers/agora-999382051935506503) | +| Community | [Discord](https://discord.gg/swarms) | | Blog | [Blog](https://medium.com/@kyeg) | | Event Calendar | [LUMA](https://lu.ma/swarms_calendar) | | Twitter | [Twitter](https://x.com/swarms_corp) | diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 201930365..d80e8f309 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -50,7 +50,7 @@ extra: - icon: fontawesome/brands/twitter link: https://x.com/swarms_corp - icon: fontawesome/brands/discord - link: https://discord.com/servers/agora-999382051935506503 + link: https://discord.gg/swarms analytics: provider: google diff --git a/docs/swarms_platform/index.md b/docs/swarms_platform/index.md index 4347c6399..2ece299a9 100644 --- a/docs/swarms_platform/index.md +++ b/docs/swarms_platform/index.md @@ -113,9 +113,9 @@ To further enhance your understanding and usage of the Swarms Platform, explore ### Links - [API Documentation](https://docs.swarms.world) -- [Community Forums](https://discord.com/servers/agora-999382051935506503) +- [Community Forums](https://discord.gg/swarms) - [Tutorials and Guides](https://docs.swarms.world)) -- [Support](https://discord.com/servers/agora-999382051935506503) +- [Support](https://discord.gg/swarms) ## Conclusion diff --git a/pyproject.toml b/pyproject.toml index b70fe5453..c2802359b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms" -version = "6.9.8" +version = "6.9.9" description = "Swarms - TGSC" license = "MIT" authors = ["Kye Gomez "] diff --git a/swarms/utils/auto_download_check_packages.py b/swarms/utils/auto_download_check_packages.py index 555967a37..9ede5ca60 100644 --- a/swarms/utils/auto_download_check_packages.py +++ b/swarms/utils/auto_download_check_packages.py @@ -144,3 +144,7 @@ def auto_check_and_download_package( success = False return success + + +if __name__ == "__main__": + print(auto_check_and_download_package("torch")) diff --git a/swarms/utils/litellm_tokenizer.py b/swarms/utils/litellm_tokenizer.py index 1ccec6f93..1db46aee7 100644 --- a/swarms/utils/litellm_tokenizer.py +++ b/swarms/utils/litellm_tokenizer.py @@ -1,6 +1,17 @@ -from litellm import encode - +import subprocess def count_tokens(text: str, model: str = "gpt-4o") -> int: """Count the number of tokens in the given text.""" + try: + from litellm import encode + except ImportError: + subprocess.run(["pip", "install", "litellm"]) + from litellm import encode + + return len(encode(model=model, text=text)) + + + +# if __name__ == "__main__": +# print(count_tokens("Hello, how are you?")) diff --git a/tests/utils/test_auto_check_download.py b/tests/utils/test_auto_check_download.py new file mode 100644 index 000000000..0a4ad157d --- /dev/null +++ b/tests/utils/test_auto_check_download.py @@ -0,0 +1,65 @@ +from swarms.utils.auto_download_check_packages import auto_check_and_download_package, check_and_install_package + +def test_check_and_install_package_pip(): + result = check_and_install_package("numpy", package_manager="pip") + print(f"Test result for 'numpy' installation using pip: {result}") + assert result, "Failed to install or verify 'numpy' using pip" + +def test_check_and_install_package_conda(): + result = check_and_install_package("numpy", package_manager="conda") + print(f"Test result for 'numpy' installation using conda: {result}") + assert result, "Failed to install or verify 'numpy' using conda" + +def test_check_and_install_specific_version(): + result = check_and_install_package("numpy", package_manager="pip", version="1.21.0") + print(f"Test result for specific version of 'numpy' installation using pip: {result}") + assert result, "Failed to install or verify specific version of 'numpy' using pip" + +def test_check_and_install_with_upgrade(): + result = check_and_install_package("numpy", package_manager="pip", upgrade=True) + print(f"Test result for 'numpy' upgrade using pip: {result}") + assert result, "Failed to upgrade 'numpy' using pip" + +def test_auto_check_and_download_single_package(): + result = auto_check_and_download_package("scipy", package_manager="pip") + print(f"Test result for 'scipy' installation using pip: {result}") + assert result, "Failed to install or verify 'scipy' using pip" + +def test_auto_check_and_download_multiple_packages(): + packages = ["scipy", "pandas"] + result = auto_check_and_download_package(packages, package_manager="pip") + print(f"Test result for multiple packages installation using pip: {result}") + assert result, f"Failed to install or verify one or more packages in {packages} using pip" + +def test_auto_check_and_download_multiple_packages_with_versions(): + packages = ["numpy:1.21.0", "pandas:1.3.0"] + result = auto_check_and_download_package(packages, package_manager="pip") + print(f"Test result for multiple packages with versions installation using pip: {result}") + assert result, f"Failed to install or verify one or more packages in {packages} with specific versions using pip" + +# Example of running tests +if __name__ == "__main__": + try: + test_check_and_install_package_pip() + print("test_check_and_install_package_pip passed") + + test_check_and_install_package_conda() + print("test_check_and_install_package_conda passed") + + test_check_and_install_specific_version() + print("test_check_and_install_specific_version passed") + + test_check_and_install_with_upgrade() + print("test_check_and_install_with_upgrade passed") + + test_auto_check_and_download_single_package() + print("test_auto_check_and_download_single_package passed") + + test_auto_check_and_download_multiple_packages() + print("test_auto_check_and_download_multiple_packages passed") + + test_auto_check_and_download_multiple_packages_with_versions() + print("test_auto_check_and_download_multiple_packages_with_versions passed") + + except AssertionError as e: + print(f"Test failed: {str(e)}")