pull/233/head
Kye 1 year ago
parent d08a2cb0a9
commit b1bf3efe70

@ -1,65 +0,0 @@
import pytest
import os
import shutil
from swarms.agents.idea_to_image_agent import Idea2Image
openai_key = os.getenv("OPENAI_API_KEY")
dalle_cookie = os.getenv("BING_COOKIE")
# Constants for testing
TEST_PROMPT = "Happy fish."
TEST_OUTPUT_FOLDER = "test_images/"
OPENAI_API_KEY = openai_key
DALLE_COOKIE = dalle_cookie
@pytest.fixture(scope="module")
def idea2image_instance():
# Create an instance of the Idea2Image class
idea2image = Idea2Image(
image=TEST_PROMPT,
openai_api_key=OPENAI_API_KEY,
cookie=DALLE_COOKIE,
output_folder=TEST_OUTPUT_FOLDER,
)
yield idea2image
# Clean up the test output folder after testing
if os.path.exists(TEST_OUTPUT_FOLDER):
shutil.rmtree(TEST_OUTPUT_FOLDER)
def test_idea2image_instance(idea2image_instance):
# Check if the instance is created successfully
assert isinstance(idea2image_instance, Idea2Image)
def test_llm_prompt(idea2image_instance):
# Test the llm_prompt method
prompt = idea2image_instance.llm_prompt()
assert isinstance(prompt, str)
def test_generate_image(idea2image_instance):
# Test the generate_image method
idea2image_instance.generate_image()
# Check if the output folder is created
assert os.path.exists(TEST_OUTPUT_FOLDER)
# Check if files are downloaded (assuming DALLE-3 responds with URLs)
files = os.listdir(TEST_OUTPUT_FOLDER)
assert len(files) > 0
def test_invalid_openai_api_key():
# Test with an invalid OpenAI API key
with pytest.raises(Exception) as exc_info:
Idea2Image(
image=TEST_PROMPT,
openai_api_key="invalid_api_key",
cookie=DALLE_COOKIE,
output_folder=TEST_OUTPUT_FOLDER,
)
assert "Failed to initialize OpenAIChat" in str(exc_info.value)
if __name__ == "__main__":
pytest.main()

@ -1,40 +0,0 @@
import pytest
from langchain.base_language import BaseLanguageModel
from swarms.agents.omni_modal_agent import (
OmniModalAgent, # Replace `your_module_name` with the appropriate module name
)
# Mock objects or set up fixtures for dependent classes or external methods
@pytest.fixture
def mock_llm():
# For this mock, we are assuming the BaseLanguageModel has a method named "process"
class MockLLM(BaseLanguageModel):
def process(self, input):
return "mock response"
return MockLLM()
@pytest.fixture
def omni_agent(mock_llm):
return OmniModalAgent(mock_llm)
def test_omnimodalagent_initialization(omni_agent):
assert omni_agent.llm is not None, "LLM initialization failed"
assert len(omni_agent.tools) > 0, "Tools initialization failed"
def test_omnimodalagent_run(omni_agent):
input_string = "Hello, how are you?"
response = omni_agent.run(input_string)
assert response is not None, "Response generation failed"
assert isinstance(response, str), "Response should be a string"
def test_task_executor_initialization(omni_agent):
assert (
omni_agent.task_executor is not None
), "TaskExecutor initialization failed"
Loading…
Cancel
Save