Skip to content

Commit

Permalink
Merge branch 'main' into api_docs_and_cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
whimo committed Jul 9, 2024
2 parents b494539 + 7c28e7c commit 22e4ab3
Show file tree
Hide file tree
Showing 259 changed files with 4,477 additions and 101,238 deletions.
31 changes: 21 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@ on:
release:
types: [published]

permissions:
contents: write

jobs:
build:
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
publish:
runs-on: ubuntu-latest

permissions:
# This permission is used for trusted publishing:
# https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/
#
# Trusted publishing has to also be configured on PyPI for each package:
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
id-token: write

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python
id: setup-python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
python-version: "3.12"

- name: Install poetry
run: pip install -U poetry
Expand All @@ -40,5 +48,8 @@ jobs:
- name: Install dependencies
run: poetry install --no-interaction

- name: Run tests
run: poetry publish --build
- name: Build using poetry
run: poetry build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
8 changes: 5 additions & 3 deletions examples/Advanced output handling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
"source": [
"In case the critic is not satisfied, the `InvalidOutput` exception will be returned to the agent, as if a regular tool was called. If everything is OK, we just return the agent's output.\n",
"\n",
"The MotleyOutputHandler constructor has a `max_iterations` argument. It's the maximum number of times the exception will be returned to the agent. If the agent doesn't provide a valid output after `max_iterations`, a `OutputHandlerMaxIterationsExceeded` exception will be raised. It has `last_call_args` and `last_call_kwargs` attributes that store the arguments that the agent used in the last call. Also, it stores the last exception that was raised in the `last_exception` attribute.\n",
"\n",
"The output schema is inferred automatically from the `handle_output` method signature. You can also specify it directly using the `_args_schema` property (see below)."
]
},
Expand All @@ -104,7 +106,7 @@
"coder = ReActToolCallingAgent(\n",
" name=\"coder\",\n",
" tools=[PythonREPLTool()],\n",
" output_handler=CoderOutputHandler(),\n",
" output_handler=CoderOutputHandler(max_iterations=3),\n",
" verbose=True,\n",
")\n",
"\n",
Expand Down Expand Up @@ -544,7 +546,7 @@
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -558,7 +560,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down
9 changes: 5 additions & 4 deletions examples/Blog with Images.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"id": "16b8ccc4-b34b-47c3-94ee-cbd82ef4c8f2",
"metadata": {},
"source": [
"We use this example of creating a web search-based blog with illustrations to show how to \n\n",
"We use this example of creating a web search-based blog with illustrations to show how to \n",
"\n",
"* instantiate one agent each from Langchain, CrewAI, and LlamaIndex\n",
"* give agents as tools to other agents\n",
"* create tasks and link them using the >> operator"
Expand Down Expand Up @@ -59,7 +60,7 @@
"from motleycrew.storage import MotleyKuzuGraphStore\n",
"from motleycrew import MotleyCrew\n",
"from motleycrew.agents.crewai import CrewAIMotleyAgent\n",
"from motleycrew.agents.langchain.react import ReActMotleyAgent\n",
"from motleycrew.agents.langchain.tool_calling_react import ReActToolCallingAgent\n",
"from motleycrew.agents.llama_index import ReActLlamaIndexMotleyAgent\n",
"from motleycrew.tools.image.dall_e import DallEImageGeneratorTool\n",
"from motleycrew.common import configure_logging\n",
Expand Down Expand Up @@ -113,9 +114,9 @@
"outputs": [],
"source": [
"# You can give agents as tools to other agents\n",
"writer = ReActMotleyAgent(\n",
"writer = ReActToolCallingAgent(\n",
" name=\"AI writer agent\",\n",
" description=\"\"\"Conduct a comprehensive analysis of the latest advancements in AI in 2024.\n",
" prompt_prefix=\"\"\"Conduct a comprehensive analysis of the latest advancements in AI in 2024.\n",
" Identify key trends, breakthrough technologies, and potential industry impacts.\n",
" Your final answer MUST be a full analysis report\"\"\",\n",
" tools=[researcher],\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/Caching and observability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"\n",
"writer = ReActMotleyAgent(\n",
" name=\"writer\",\n",
" description=\"Using the results of a web search, write an article on the latest advancements in AI in 2024.\",\n",
" prompt_prefix=\"Using the results of a web search, write an article on the latest advancements in AI in 2024.\",\n",
" tools=[duckduckgo_search],\n",
")\n",
"\n",
Expand Down
7 changes: 4 additions & 3 deletions examples/Math via python code with a single agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"WORKING_DIR = Path(os.path.realpath(\".\"))\n",
"\n",
"\n",
"try: \n",
"try:\n",
" from motleycrew import MotleyCrew\n",
"except ImportError:\n",
" # if we are running this from source\n",
Expand Down Expand Up @@ -493,15 +493,15 @@
" backstory=\"\"\"You are a high school math teacher with a passion for problem-solving.\n",
"To solve a math problem, you first reason about it, step by step, then generate the code to solve it exactly,\n",
"using sympy, then use the REPL tool to evaluate that code, and then\n",
"use the output to generate a human-readable solution in LaTeX format. \n",
"use the output to generate a human-readable solution in LaTeX format.\n",
"Don't use dashes to indicate bullet points, don't output any backticks, just the LaTeX\"\"\",\n",
" verbose=True,\n",
" delegation=False,\n",
" tools=[repl_tool],\n",
")\n",
"\n",
"problems = [\n",
" \"Problem: If $725x + 727y = 1500$ and $729x+ 731y = 1508$, \"\n",
" \"If $725x + 727y = 1500$ and $729x+ 731y = 1508$, \"\n",
" \"what are the values of $x$, $y$, and $x - y$ ?\",\n",
"]\n",
"\n",
Expand All @@ -511,6 +511,7 @@
" name=\"solve math problem\",\n",
" description=f\"\"\"Create a nice human-readable solution to the following problem:\n",
" {problems[0]}\"\"\",\n",
" additional_params={\"expected_output\": \"human-readable solution in LaTeX format\"},\n",
" agent=solver,\n",
")\n",
"\n",
Expand Down
4 changes: 2 additions & 2 deletions examples/Validating agent output.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -259,7 +259,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down
1 change: 1 addition & 0 deletions examples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Has to be here to make the examples package importable for integration tests
9 changes: 7 additions & 2 deletions examples/aider_code_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@
def main():
crew = MotleyCrew()

git_repo_path = r"../../motleycrew-code-generation-example" # cloned repository path
git_repo_path = (
r"../../motleycrew-code-generation-example" # cloned repository path
)
tests_file = os.path.join(git_repo_path, "test_math_functions.py")
target_files = [tests_file]

aider_tool = AiderTool(fnames=target_files, git_dname=git_repo_path, auto_commits=False)
aider_tool = AiderTool(
fnames=target_files, git_dname=git_repo_path, auto_commits=False
)
shell_tool = ShellTool()

developer = CrewAIMotleyAgent(
Expand All @@ -59,6 +63,7 @@ def main():
f"After go to the directory {git_repo_path} and run created unit tests. "
f"If the tests were executed successfully, return the result of execution, "
f"if not, rewrite the tests and rerun them until they are working.",
additional_params={"expected_output": "result of tests execution"},
agent=developer,
)

Expand Down
6 changes: 0 additions & 6 deletions examples/blog_with_images.nblink

This file was deleted.

78 changes: 78 additions & 0 deletions examples/crewai_output_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from pathlib import Path
import os
import sys

from dotenv import load_dotenv

from motleycrew.agents.crewai import CrewAIMotleyAgent
from motleycrew.common import configure_logging
from motleycrew.tasks import SimpleTask
from motleycrew.common.exceptions import InvalidOutput

from langchain_community.tools import DuckDuckGoSearchRun
from langchain_core.tools import StructuredTool

WORKING_DIR = Path(os.path.realpath(".."))

try:
from motleycrew import MotleyCrew
except ImportError:
# if we are running this from source
motleycrew_location = os.path.realpath(WORKING_DIR / "..")
sys.path.append(motleycrew_location)


def main():
crew = MotleyCrew()

search_tool = DuckDuckGoSearchRun()

def check_output(output: str):
if "medicine" not in output.lower():
raise InvalidOutput(
"Add more information about AI applications in medicine."
)
return {"checked_output": output.lower()}

output_handler = StructuredTool.from_function(
name="output_handler",
description="Output handler",
func=check_output,
)

researcher = CrewAIMotleyAgent(
role="Senior Research Analyst",
goal="Uncover cutting-edge developments in AI and data science, doing web search if necessary",
backstory="""You work at a leading tech think tank.
Your expertise lies in identifying emerging trends.
You have a knack for dissecting complex data and presenting actionable insights.""",
delegation=False,
output_handler=output_handler,
verbose=True,
tools=[search_tool],
)

# Create tasks for agent

analysis_report_task = SimpleTask(
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""",
additional_params={"expected_output": "full analysis report"},
agent=researcher,
)

# Get your crew to work!
result = crew.run()

# Get the outputs of the task
print(analysis_report_task.output)
return analysis_report_task.output


if __name__ == "__main__":
configure_logging(verbose=True)
load_dotenv()
main()
26 changes: 16 additions & 10 deletions examples/delegation_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from motleycrew.storage import MotleyKuzuGraphStore

from motleycrew.agents.crewai import CrewAIMotleyAgent
from motleycrew.agents.langchain.react import ReActMotleyAgent
from motleycrew.agents.langchain.tool_calling_react import ReActToolCallingAgent
from motleycrew.agents.llama_index import ReActLlamaIndexMotleyAgent
from motleycrew.tools.image.dall_e import DallEImageGeneratorTool
from motleycrew.common import configure_logging
Expand All @@ -25,11 +25,15 @@
motleycrew_location = os.path.realpath(WORKING_DIR / "..")
sys.path.append(motleycrew_location)

if "Dropbox" in WORKING_DIR.parts and platform.system() == "Windows":
# On Windows, kuzu has file locking issues with Dropbox
DB_PATH = os.path.realpath(os.path.expanduser("~") + "/Documents/research_db")
if __name__ == '__main__':
if "Dropbox" in WORKING_DIR.parts and platform.system() == "Windows":
# On Windows, kuzu has file locking issues with Dropbox
DB_PATH = os.path.realpath(os.path.expanduser("~") + "/Documents/research_db")
else:
DB_PATH = os.path.realpath(WORKING_DIR / "research_db")

else:
DB_PATH = os.path.realpath(WORKING_DIR / "research_db")
DB_PATH = os.path.realpath(WORKING_DIR / "tests/research_db")


def main():
Expand All @@ -43,25 +47,27 @@ def main():
researcher = CrewAIMotleyAgent(
role="Senior Research Analyst",
goal="Uncover cutting-edge developments in AI and data science, doing web search if necessary",

backstory="""You work at a leading tech think tank.
Your expertise lies in identifying emerging trends.
You have a knack for dissecting complex data and presenting actionable insights.""",
Your expertise lies in identifying emerging trends.
You have a knack for dissecting complex data and presenting actionable insights.""",
verbose=True,
tools=[search_tool],
)

# You can give agents as tools to other agents
writer = ReActMotleyAgent(
writer = ReActToolCallingAgent(
name="AI writer agent",
description="You are an experienced writer with a passion for technology.",
prompt_prefix="You are an experienced writer with a passion for technology.",
description="Experienced writer with a passion for technology.",
tools=[researcher],
verbose=True,
)

# Illustrator
illustrator = ReActLlamaIndexMotleyAgent(
name="Illustrator",
description="Create beautiful and insightful illustrations for a blog post",
prompt_prefix="Create beautiful and insightful illustrations for a blog post",
tools=[DallEImageGeneratorTool(os.path.realpath("./images"))],
)

Expand Down
Loading

0 comments on commit 22e4ab3

Please sign in to comment.