-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from ShoggothAI/scary_refactor
Refactor app logic for graph-based dispatch
- Loading branch information
Showing
85 changed files
with
102,815 additions
and
1,574 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
|
||
|
||
@dataclass | ||
ToolDescription: | ||
name: str | ||
description: str | ||
framework: str | ||
toolkit: Optional[str] = None | ||
|
||
motley.tool.get_descriptions(framework: Optional[str] = None) -> ToolDescription | ||
motleycrew.tool.from_description(d: ToolDescription) -> MotleyTool | ||
motleycrew.tool.init_embeddings(embed_model) -> ToolSearcher | ||
class ToolSearcher: | ||
def match(self, task: str) -> List[MotleyTool]: | ||
pass | ||
|
||
def register_tools(self, ...): | ||
@classmethod | ||
def default(cls) -> ToolSearcher: | ||
pass |
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,56 +1,62 @@ | ||
from dotenv import load_dotenv | ||
|
||
from motleycrew import MotleyCrew, Task | ||
from motleycrew import MotleyCrew, TaskRecipe | ||
from motleycrew.agent.crewai import CrewAIMotleyAgent | ||
from motleycrew.tool.image_generation import DallEImageGeneratorTool | ||
from motleycrew.common.utils import configure_logging | ||
|
||
load_dotenv() | ||
configure_logging(verbose=True) | ||
|
||
image_generator_tool = DallEImageGeneratorTool() | ||
# For saving images locally use the line below | ||
# image_generator_tool = DallEImageGeneratorTool(images_directory="images") | ||
|
||
writer = CrewAIMotleyAgent( | ||
role="Short stories writer", | ||
goal="Write short stories for children", | ||
backstory="You are an accomplished children's writer, known for your funny and interesting short stories.\n" | ||
"Many parents around the world read your books to their children.", | ||
verbose=True, | ||
delegation=True, | ||
) | ||
|
||
illustrator = CrewAIMotleyAgent( | ||
role="Illustrator", | ||
goal="Create beautiful and insightful illustrations", | ||
backstory="You are an expert in creating illustrations for all sorts of concepts and articles. " | ||
"You do it by skillfully prompting a text-to-image model.\n" | ||
"Your final answer MUST be the exact URL or filename of the illustration.", | ||
verbose=True, | ||
delegation=False, | ||
tools=[image_generator_tool], | ||
) | ||
|
||
# Create tasks for your agents | ||
crew = MotleyCrew() | ||
write_task = Task( | ||
crew=crew, | ||
name="write a short story about a cat", | ||
description="Creatively write a short story of about 4 paragraphs " | ||
"about a house cat that was smarter than its owners. \n" | ||
"Write it in a cool and simple language, " | ||
"making it intriguing yet suitable for children's comprehension.\n" | ||
"You must include a fun illustration.\n" | ||
"Your final answer MUST be the full story with the illustration URL or filename attached.", | ||
agent=writer, | ||
) | ||
|
||
|
||
# Get your crew to work! | ||
result = crew.run( | ||
agents=[illustrator, writer], | ||
verbose=2, # You can set it to 1 or 2 to different logging levels | ||
) | ||
|
||
print(write_task.outputs) | ||
|
||
def main(): | ||
"""Main function of running the example.""" | ||
image_generator_tool = DallEImageGeneratorTool() | ||
# For saving images locally use the line below | ||
# image_generator_tool = DallEImageGeneratorTool(images_directory="images") | ||
|
||
illustrator = CrewAIMotleyAgent( | ||
role="Illustrator", | ||
goal="Create beautiful and insightful illustrations", | ||
backstory="You are an expert in creating illustrations for all sorts of concepts and articles. " | ||
"You do it by skillfully prompting a text-to-image model.\n" | ||
"Your final answer MUST be the exact URL or filename of the illustration.", | ||
verbose=True, | ||
delegation=False, | ||
tools=[image_generator_tool], | ||
) | ||
|
||
writer = CrewAIMotleyAgent( | ||
role="Short stories writer", | ||
goal="Write short stories for children", | ||
backstory="You are an accomplished children's writer, known for your funny and interesting short stories.\n" | ||
"Many parents around the world read your books to their children.", | ||
verbose=True, | ||
delegation=True, | ||
tools=[illustrator], | ||
) | ||
|
||
# Create tasks for your agents | ||
crew = MotleyCrew() | ||
write_task = crew.create_simple_task( | ||
name="write a short story about a cat", | ||
description="Creatively write a short story of about 4 paragraphs " | ||
"about a house cat that was smarter than its owners. \n" | ||
"Write it in a cool and simple language, " | ||
"making it intriguing yet suitable for children's comprehension.\n" | ||
"You must include a fun illustration.\n" | ||
"Your final answer MUST be the full story with the illustration URL or filename attached.", | ||
agent=writer, | ||
) | ||
|
||
# Get your crew to work! | ||
crew.run( | ||
verbose=2, # You can set it to 1 or 2 to different logging levels | ||
) | ||
|
||
print(write_task.output) | ||
return write_task.output | ||
|
||
|
||
if __name__ == "__main__": | ||
configure_logging(verbose=True) | ||
|
||
load_dotenv() | ||
main() |
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,53 +1,60 @@ | ||
from dotenv import load_dotenv | ||
|
||
from motleycrew import MotleyCrew, Task | ||
from motleycrew import MotleyCrew, TaskRecipe | ||
from motleycrew.agent.crewai import CrewAIMotleyAgent | ||
from motleycrew.tool.python_repl import create_repl_tool | ||
|
||
load_dotenv() | ||
|
||
repl_tool = create_repl_tool() | ||
|
||
# Define your agents with roles and goals | ||
solver1 = CrewAIMotleyAgent( | ||
role="High School Math Teacher", | ||
goal="Generate great solutions to math problems", | ||
backstory="""You are a high school math teacher with a passion for problem-solving. | ||
To solve a math problem, you first reason about it, step by step, then generate the code to solve it exactly, | ||
using sympy, then use the REPL tool to evaluate that code, and then | ||
use the output to generate a human-readable solution.""", | ||
verbose=True, | ||
delegation=False, | ||
tools=[repl_tool], | ||
) | ||
|
||
solver = solver1 | ||
|
||
problems = [ | ||
"Problem: If $725x + 727y = 1500$ and $729x+ 731y = 1508$, what are the values of $x$, $y$, and $x - y$ ?", | ||
"Drei Personen erhalten zusammen Fr. 2450. Die erste Person erh\u00e4lt Fr. 70 mehr als die zweite, aber Fr. 60 weniger als die dritte.\nWie viel erh\u00e4lt jede Person? ", | ||
"Find all numbers $a$ for which the graph of $y=x^2+a$ and the graph of $y=ax$ intersect. Express your answer in interval notation.", | ||
] | ||
|
||
# Create tasks for your agents | ||
crew = MotleyCrew() | ||
task1 = Task( | ||
crew=crew, | ||
name="solve math problem", | ||
description=f"""Create a nice human-readable solution to the following problem: | ||
{problems[1]} | ||
IN THE SAME LANGUAGE AS THE PROBLEM""", | ||
agent=solver, | ||
) | ||
|
||
|
||
# Instantiate your crew with a sequential process | ||
result = crew.run( | ||
agents=[solver], | ||
verbose=True, # You can set it to 1 or 2 to different logging levels | ||
) | ||
|
||
# Get your crew to work! | ||
print(list(result._done)[0].outputs) | ||
|
||
print("######################") | ||
from motleycrew.common.utils import configure_logging | ||
|
||
|
||
def main(): | ||
"""Main function of running the example.""" | ||
repl_tool = create_repl_tool() | ||
|
||
# Define your agents with roles and goals | ||
solver1 = CrewAIMotleyAgent( | ||
role="High School Math Teacher", | ||
goal="Generate great solutions to math problems", | ||
backstory="""You are a high school math teacher with a passion for problem-solving. | ||
To solve a math problem, you first reason about it, step by step, then generate the code to solve it exactly, | ||
using sympy, then use the REPL tool to evaluate that code, and then | ||
use the output to generate a human-readable solution.""", | ||
verbose=True, | ||
delegation=False, | ||
tools=[repl_tool], | ||
) | ||
|
||
solver = solver1 | ||
|
||
problems = [ | ||
"Problem: If $725x + 727y = 1500$ and $729x+ 731y = 1508$, " | ||
"what are the values of $x$, $y$, and $x - y$ ?", | ||
"Drei Personen erhalten zusammen Fr. 2450. Die erste Person erh\u00e4lt Fr. 70 mehr als " | ||
"die zweite, aber Fr. 60 weniger als die dritte.\nWie viel erh\u00e4lt jede Person? ", | ||
"Find all numbers $a$ for which the graph of $y=x^2+a$ and the graph of $y=ax$ intersect. " | ||
"Express your answer in interval notation.", | ||
] | ||
|
||
# Create tasks for your agents | ||
crew = MotleyCrew() | ||
task = crew.create_simple_task( | ||
name="solve math problem", | ||
description=f"""Create a nice human-readable solution to the following problem: | ||
{problems[1]} | ||
IN THE SAME LANGUAGE AS THE PROBLEM""", | ||
agent=solver, | ||
) | ||
|
||
# Get your crew to work! | ||
crew.run( | ||
verbose=2, # You can set it to 1 or 2 to different logging levels | ||
) | ||
|
||
print(task.output) | ||
return task.output | ||
|
||
|
||
if __name__ == "__main__": | ||
configure_logging(verbose=True) | ||
|
||
load_dotenv() | ||
main() |
Oops, something went wrong.