From e5dce12e5ba03be619ed8f2da9d69d6287a546cf Mon Sep 17 00:00:00 2001 From: Kye Date: Wed, 15 Nov 2023 17:31:44 -0500 Subject: [PATCH] playground -> swarms in dalle3 tests --- pyproject.toml | 2 +- tests/boss/boss_node.py | 133 ---------------------------------- tests/chunkers/basechunker.py | 83 --------------------- tests/models/dalle3.py | 2 +- 4 files changed, 2 insertions(+), 218 deletions(-) delete mode 100644 tests/boss/boss_node.py delete mode 100644 tests/chunkers/basechunker.py diff --git a/pyproject.toml b/pyproject.toml index 8ae5b4dc7..2c5215309 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms" -version = "2.3.4" +version = "2.3.5" description = "Swarms - Pytorch" license = "MIT" authors = ["Kye Gomez "] diff --git a/tests/boss/boss_node.py b/tests/boss/boss_node.py deleted file mode 100644 index d4547a5ac..000000000 --- a/tests/boss/boss_node.py +++ /dev/null @@ -1,133 +0,0 @@ -import pytest -from unittest.mock import Mock, patch -from swarms.tools.agent_tools import * -from swarms.boss.boss_node import BossNodeInitializer, BossNode - - -# For initializing BossNodeInitializer in multiple tests -@pytest.fixture -def mock_boss_node_initializer(): - llm = Mock() - vectorstore = Mock() - agent_executor = Mock() - max_iterations = 5 - - boss_node_initializer = BossNodeInitializer( - llm, vectorstore, agent_executor, max_iterations - ) - - return boss_node_initializer - - -# Test BossNodeInitializer class __init__ method -def test_boss_node_initializer_init(mock_boss_node_initializer): - with patch("swarms.tools.agent_tools.BabyAGI.from_llm") as mock_from_llm: - assert isinstance(mock_boss_node_initializer, BossNodeInitializer) - mock_from_llm.assert_called_once() - - -# Test initialize_vectorstore method of BossNodeInitializer class -def test_boss_node_initializer_initialize_vectorstore(mock_boss_node_initializer): - with patch("swarms.tools.agent_tools.OpenAIEmbeddings") as mock_embeddings, patch( - "swarms.tools.agent_tools.FAISS" - ) as mock_faiss: - result = mock_boss_node_initializer.initialize_vectorstore() - mock_embeddings.assert_called_once() - mock_faiss.assert_called_once() - assert result is not None - - -# Test initialize_llm method of BossNodeInitializer class -def test_boss_node_initializer_initialize_llm(mock_boss_node_initializer): - with patch("swarms.tools.agent_tools.OpenAI") as mock_llm: - result = mock_boss_node_initializer.initialize_llm(mock_llm) - mock_llm.assert_called_once() - assert result is not None - - -# Test create_task method of BossNodeInitializer class -@pytest.mark.parametrize("objective", ["valid objective", ""]) -def test_boss_node_initializer_create_task(objective, mock_boss_node_initializer): - if objective == "": - with pytest.raises(ValueError): - mock_boss_node_initializer.create_task(objective) - else: - assert mock_boss_node_initializer.create_task(objective) == { - "objective": objective - } - - -# Test run method of BossNodeInitializer class -@pytest.mark.parametrize("task", ["valid task", ""]) -def test_boss_node_initializer_run(task, mock_boss_node_initializer): - with patch.object(mock_boss_node_initializer, "baby_agi"): - if task == "": - with pytest.raises(ValueError): - mock_boss_node_initializer.run(task) - else: - try: - mock_boss_node_initializer.run(task) - mock_boss_node_initializer.baby_agi.assert_called_once_with(task) - except Exception: - pytest.fail("Unexpected Error!") - - -# Test BossNode function -@pytest.mark.parametrize( - "api_key, objective, llm_class, max_iterations", - [ - ("valid_key", "valid_objective", OpenAI, 5), - ("", "valid_objective", OpenAI, 5), - ("valid_key", "", OpenAI, 5), - ("valid_key", "valid_objective", "", 5), - ("valid_key", "valid_objective", OpenAI, 0), - ], -) -def test_boss_node(api_key, objective, llm_class, max_iterations): - with patch("os.getenv") as mock_getenv, patch( - "swarms.tools.agent_tools.PromptTemplate.from_template" - ) as mock_from_template, patch( - "swarms.tools.agent_tools.LLMChain" - ) as mock_llm_chain, patch( - "swarms.tools.agent_tools.ZeroShotAgent.create_prompt" - ) as mock_create_prompt, patch( - "swarms.tools.agent_tools.ZeroShotAgent" - ) as mock_zero_shot_agent, patch( - "swarms.tools.agent_tools.AgentExecutor.from_agent_and_tools" - ) as mock_from_agent_and_tools, patch( - "swarms.tools.agent_tools.BossNodeInitializer" - ) as mock_boss_node_initializer, patch.object( - mock_boss_node_initializer, "create_task" - ) as mock_create_task, patch.object( - mock_boss_node_initializer, "run" - ) as mock_run: - if api_key == "" or objective == "" or llm_class == "" or max_iterations <= 0: - with pytest.raises(ValueError): - BossNode( - objective, - api_key, - vectorstore=None, - worker_node=None, - llm_class=llm_class, - max_iterations=max_iterations, - verbose=False, - ) - else: - mock_getenv.return_value = "valid_key" - BossNode( - objective, - api_key, - vectorstore=None, - worker_node=None, - llm_class=llm_class, - max_iterations=max_iterations, - verbose=False, - ) - mock_from_template.assert_called_once() - mock_llm_chain.assert_called_once() - mock_create_prompt.assert_called_once() - mock_zero_shot_agent.assert_called_once() - mock_from_agent_and_tools.assert_called_once() - mock_boss_node_initializer.assert_called_once() - mock_create_task.assert_called_once() - mock_run.assert_called_once() diff --git a/tests/chunkers/basechunker.py b/tests/chunkers/basechunker.py deleted file mode 100644 index 4fd92da1a..000000000 --- a/tests/chunkers/basechunker.py +++ /dev/null @@ -1,83 +0,0 @@ -import pytest -from swarms.chunkers.base import ( - BaseChunker, - TextArtifact, - ChunkSeparator, - OpenAITokenizer, -) # adjust the import paths accordingly - - -# 1. Test Initialization -def test_chunker_initialization(): - chunker = BaseChunker() - assert isinstance(chunker, BaseChunker) - assert chunker.max_tokens == chunker.tokenizer.max_tokens - - -def test_default_separators(): - chunker = BaseChunker() - assert chunker.separators == BaseChunker.DEFAULT_SEPARATORS - - -def test_default_tokenizer(): - chunker = BaseChunker() - assert isinstance(chunker.tokenizer, OpenAITokenizer) - - -# 2. Test Basic Chunking -@pytest.mark.parametrize( - "input_text, expected_output", - [ - ("This is a test.", [TextArtifact("This is a test.")]), - ("Hello World!", [TextArtifact("Hello World!")]), - # Add more simple cases - ], -) -def test_basic_chunk(input_text, expected_output): - chunker = BaseChunker() - result = chunker.chunk(input_text) - assert result == expected_output - - -# 3. Test Chunking with Different Separators -def test_custom_separators(): - custom_separator = ChunkSeparator(";") - chunker = BaseChunker(separators=[custom_separator]) - input_text = "Hello;World!" - expected_output = [TextArtifact("Hello;"), TextArtifact("World!")] - result = chunker.chunk(input_text) - assert result == expected_output - - -# 4. Test Recursive Chunking -def test_recursive_chunking(): - chunker = BaseChunker(max_tokens=5) - input_text = "This is a more complex text." - expected_output = [ - TextArtifact("This"), - TextArtifact("is a"), - TextArtifact("more"), - TextArtifact("complex"), - TextArtifact("text."), - ] - result = chunker.chunk(input_text) - assert result == expected_output - - -# 5. Test Edge Cases and Special Scenarios -def test_empty_text(): - chunker = BaseChunker() - result = chunker.chunk("") - assert result == [] - - -def test_whitespace_text(): - chunker = BaseChunker() - result = chunker.chunk(" ") - assert result == [TextArtifact(" ")] - - -def test_single_word(): - chunker = BaseChunker() - result = chunker.chunk("Hello") - assert result == [TextArtifact("Hello")] diff --git a/tests/models/dalle3.py b/tests/models/dalle3.py index f9a2f8cfc..a23d077e8 100644 --- a/tests/models/dalle3.py +++ b/tests/models/dalle3.py @@ -6,7 +6,7 @@ from PIL import Image from termcolor import colored -from playground.models.dalle3 import Dalle3 +from swarms.models.dalle3 import Dalle3 # Mocking the OpenAI client to avoid making actual API calls during testing