-
-
Notifications
You must be signed in to change notification settings - Fork 509
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
91 additions
and
107 deletions.
There are no files selected for viewing
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
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 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.9.8" | ||
version = "6.9.9" | ||
description = "Swarms - TGSC" | ||
license = "MIT" | ||
authors = ["Kye Gomez <[email protected]>"] | ||
|
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 |
---|---|---|
@@ -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?")) |
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,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)}") |