Skip to content

Commit

Permalink
add main function in single_llama_index example and update run_integr…
Browse files Browse the repository at this point in the history
…ation_tests
  • Loading branch information
User committed May 3, 2024
1 parent 2c1d4bc commit 077a743
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 72 deletions.
71 changes: 39 additions & 32 deletions examples/single_llama_index.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,56 @@
import logging

from dotenv import load_dotenv
from langchain_community.tools import DuckDuckGoSearchRun


from motleycrew import MotleyCrew, Task
from motleycrew.agent.llama_index import ReActLlamaIndexMotleyAgent
from motleycrew.caсhing import enable_cache, disable_cache
from motleycrew.common.utils import configure_logging


def main():
"""Main function of running the example."""
search_tool = DuckDuckGoSearchRun()

logging.basicConfig(level=logging.INFO)
# TODO: add LlamaIndex native tools
researcher = ReActLlamaIndexMotleyAgent(
goal="Uncover cutting-edge developments in AI and data science",
tools=[search_tool],
verbose=True,
)

load_dotenv()
enable_cache()

search_tool = DuckDuckGoSearchRun()
crew = MotleyCrew()

# TODO: add LlamaIndex native tools
researcher = ReActLlamaIndexMotleyAgent(
goal="Uncover cutting-edge developments in AI and data science",
tools=[search_tool],
verbose=True,
)
# Create tasks for your agents
task1 = Task(
crew=crew,
name="produce comprehensive analysis report on AI advancements",
description="""Conduct a comprehensive analysis of the latest advancements in AI in 2024.
Identify key trends, breakthrough technologies, and potential industry impacts.
Your final answer MUST be a full analysis report""",
agent=researcher,
documents=["paper1.pdf", "paper2.pdf"],
)

# Instantiate your crew with a sequential process
result = crew.run(
agents=[researcher],
verbose=2, # You can set it to 1 or 2 to different logging levels
)

crew = MotleyCrew()
# Get your crew to work!
outputs = list(result._done)[0].outputs
print(outputs)
print("######################")

# Create tasks for your agents
task1 = Task(
crew=crew,
name="produce comprehensive analysis report on AI advancements",
description="""Conduct a comprehensive analysis of the latest advancements in AI in 2024.
Identify key trends, breakthrough technologies, and potential industry impacts.
Your final answer MUST be a full analysis report""",
agent=researcher,
documents=["paper1.pdf", "paper2.pdf"],
)
return outputs[0].response

# Instantiate your crew with a sequential process
result = crew.run(
agents=[researcher],
verbose=2, # You can set it to 1 or 2 to different logging levels
)

# Get your crew to work!
print(list(result._done)[0].outputs)
if __name__ == '__main__':
configure_logging(verbose=True)

print("######################")
disable_cache()
load_dotenv()
enable_cache()
main()
disable_cache()
53 changes: 13 additions & 40 deletions tests/run_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
set_cache_location,
set_strong_cache,
)
from langchain_community.tools import DuckDuckGoSearchRun
from motleycrew import MotleyCrew, Task
from motleycrew.agent.llama_index import ReActLlamaIndexMotleyAgent
from examples.single_llama_index import main as single_llama_index_main

CACHE_DIR = "tests/cache"
DATA_DIR = "tests/data"
Expand All @@ -27,45 +25,20 @@
class IntegrationTestException(Exception):
"""Integration tests exception"""

def __init__(self, function_name: str, *args, **kwargs):
def __init__(self, test_name: str, *args, **kwargs):
super(IntegrationTestException, self).__init__(*args, **kwargs)
self.function_name = function_name
self.test_name = test_name

def __str__(self):
super_str = super(IntegrationTestException, self).__str__()
return "{} {}: {}".format(self.__class__, self.function_name, super_str)
return "{} {}: {}".format(self.__class__, self.test_name, super_str)


def single_llama_index_test():
"""Test example single_llama_index"""

function_name = inspect.stack()[0][3]
search_tool = DuckDuckGoSearchRun()
researcher = ReActLlamaIndexMotleyAgent(
goal="Uncover cutting-edge developments in AI and data science",
tools=[search_tool],
verbose=True,
)
crew = MotleyCrew()
# Create tasks for your agents
task1 = Task(
crew=crew,
name="produce comprehensive analysis report on AI advancements",
description="""Conduct a comprehensive analysis of the latest advancements in AI in 2024.
Identify key trends, breakthrough technologies, and potential industry impacts.
Your final answer MUST be a full analysis report""",
agent=researcher,
documents=["paper1.pdf", "paper2.pdf"],
)

# Instantiate your crew with a sequential process
result = crew.run(
agents=[researcher],
verbose=2, # You can set it to 1 or 2 to different logging levels
)

content = list(result._done)[0].outputs[0].response
excepted_content = read_content(function_name)
test_name = inspect.stack()[0][3]
content = single_llama_index_main()
excepted_content = read_content(test_name)
comparison_results(content, excepted_content)


Expand All @@ -82,22 +55,22 @@ def comparison_results(result: str, excepted_result: str) -> list:
return diff


def build_excepted_content_file_path(function_name: str, extension: str = "txt") -> str:
def build_excepted_content_file_path(test_name: str, extension: str = "txt") -> str:
"""Building data file path"""
return os.path.join(DATA_DIR, "{}.{}".format(function_name, extension))
return os.path.join(DATA_DIR, "{}.{}".format(test_name, extension))


def write_content(function_name: str, content: str, extension: str = "txt") -> bool:
def write_content(test_name: str, content: str, extension: str = "txt") -> bool:
"""Writing data to file"""
file_path = build_excepted_content_file_path(function_name, extension)
file_path = build_excepted_content_file_path(test_name, extension)
with open(file_path, "w") as f_o:
f_o.write(content)
return True


def read_content(function_name: str, extension: str = "txt") -> str:
def read_content(test_name: str, extension: str = "txt") -> str:
"""Reading data from file"""
file_path = build_excepted_content_file_path(function_name, extension)
file_path = build_excepted_content_file_path(test_name, extension)
with open(file_path, "r") as f_o:
return f_o.read()

Expand Down

0 comments on commit 077a743

Please sign in to comment.