From 6ea5295ce59a2bc14ee174dff7620b903a3053ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Sun, 21 Jan 2024 15:02:40 -0300 Subject: [PATCH] Adding game builder crew --- .gitignore | 1 + game-builder-crew/.env.example | 1 + game-builder-crew/.gitignore | 3 ++ game-builder-crew/README.md | 32 +++++++++++++++++++++ game-builder-crew/agents.py | 41 +++++++++++++++++++++++++++ game-builder-crew/main.py | 49 +++++++++++++++++++++++++++++++++ game-builder-crew/pyprojct.toml | 24 ++++++++++++++++ game-builder-crew/tasks.py | 48 ++++++++++++++++++++++++++++++++ 8 files changed, 199 insertions(+) create mode 100644 .gitignore create mode 100644 game-builder-crew/.env.example create mode 100644 game-builder-crew/.gitignore create mode 100644 game-builder-crew/README.md create mode 100644 game-builder-crew/agents.py create mode 100644 game-builder-crew/main.py create mode 100644 game-builder-crew/pyprojct.toml create mode 100644 game-builder-crew/tasks.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..496ee2ca --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store \ No newline at end of file diff --git a/game-builder-crew/.env.example b/game-builder-crew/.env.example new file mode 100644 index 00000000..beabfcf3 --- /dev/null +++ b/game-builder-crew/.env.example @@ -0,0 +1 @@ +OPENAI_API_KEY=... \ No newline at end of file diff --git a/game-builder-crew/.gitignore b/game-builder-crew/.gitignore new file mode 100644 index 00000000..7ea49ec2 --- /dev/null +++ b/game-builder-crew/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +.env +.DS_Store \ No newline at end of file diff --git a/game-builder-crew/README.md b/game-builder-crew/README.md new file mode 100644 index 00000000..d212f878 --- /dev/null +++ b/game-builder-crew/README.md @@ -0,0 +1,32 @@ +# AI Crew for Game Building +## Introduction +This project is an example using the CrewAI framework to automate the process of coming up with an instagram post. CrewAI orchestrates autonomous AI agents, enabling them to collaborate and execute complex tasks efficiently. + +#### Game Builder +By [@joaomdmoura](https://x.com/joaomdmoura) + +- [CrewAI Framework](#crewai-framework) +- [Running the script](#running-the-script) +- [Details & Explanation](#details--explanation) +- [Using Local Models with Ollama](#using-local-models-with-ollama) +- [License](#license) + +## CrewAI Framework +CrewAI is designed to facilitate the collaboration of role-playing AI agents. In this example, these agents work together to give a complete stock analysis and investment recommendation + +## Running the Script +This example uses GPT-4. + +- **Configure Environment**: Copy ``.env.example` and set up the environment variable +- **Install Dependencies**: Run `poetry install --no-root`. +- **Execute the Script**: Run `python main.py` and input your idea. + +## Details & Explanation +- **Running the Script**: Execute `python main.py`` and input your idea when prompted. The script will leverage the CrewAI framework to process the idea and generate a landing page. +- **Key Components**: + - `./main.py`: Main script file. + - `./tasks.py`: Main file with the tasks prompts. + - `./agents.py`: Main file with the agents creation. + +## License +This project is released under the MIT License. diff --git a/game-builder-crew/agents.py b/game-builder-crew/agents.py new file mode 100644 index 00000000..9bd3e003 --- /dev/null +++ b/game-builder-crew/agents.py @@ -0,0 +1,41 @@ +from textwrap import dedent +from crewai import Agent + +class GameAgents(): + def senior_engineer_agent(self): + return Agent( + role='Senior Software Engineer', + goal='Create software as needed', + backstory=dedent("""\ + You are a Senior Software Engineer at a leading tech think tank. + Your expertise in programming in python. and do your best to + produce perfect code"""), + allow_delegation=False, + verbose=True + ) + + def qa_engineer_agent(self): + return Agent( + role='Software Quality Control Engineer', + goal='create prefect code, by analizing the code that is given for errors', + backstory=dedent("""\ + You are a software engineer that specializes in checking code + for errors. You have an eye for detail and a knack for finding + hidden bugs. + You check for missing imports, variable declarations, mismatched + brackets and syntax errors. + You also check for security vulnerabilities, and logic errors"""), + allow_delegation=False, + verbose=True + ) + + def chief_qa_engineer_agent(self): + return Agent( + role='Chief Software Quality Control Engineer', + goal='Ensure that the code does the job that it is supposed to do', + backstory=dedent("""\ + You feel that programmers always do only half the job, so you are + super dedicate to make high quality code."""), + allow_delegation=True, + verbose=True + ) \ No newline at end of file diff --git a/game-builder-crew/main.py b/game-builder-crew/main.py new file mode 100644 index 00000000..2e4cf43c --- /dev/null +++ b/game-builder-crew/main.py @@ -0,0 +1,49 @@ +from dotenv import load_dotenv +load_dotenv() + +from crewai import Crew + +from tasks import GameTasks +from agents import GameAgents + +tasks = GameTasks() +agents = GameAgents() + +print("## Welcome to the Game Crew") +print('-------------------------------') +game = input("What is the game you would like to build? What will be the mechanics?\n") + +# Create Agents +senior_engineer_agent = agents.senior_engineer_agent() +qa_engineer_agent = agents.qa_engineer_agent() +chief_qa_engineer_agent = agents.chief_qa_engineer_agent() + +# Create Tasks +code_game = tasks.code_task(senior_engineer_agent, game) +review_game = tasks.review_task(qa_engineer_agent, game) +approve_game = tasks.evaluate_task(chief_qa_engineer_agent, game) + +# Create Crew responsible for Copy +crew = Crew( + agents=[ + senior_engineer_agent, + qa_engineer_agent, + chief_qa_engineer_agent + ], + tasks=[ + code_game, + review_game, + approve_game + ], + verbose=True +) + +game = crew.kickoff() + + +# Print results +print("\n\n########################") +print("## Here is the result") +print("########################\n") +print("final code for the game:") +print(game) diff --git a/game-builder-crew/pyprojct.toml b/game-builder-crew/pyprojct.toml new file mode 100644 index 00000000..53730e9c --- /dev/null +++ b/game-builder-crew/pyprojct.toml @@ -0,0 +1,24 @@ +[tool.poetry] +name = "game-crew" +version = "0.1.0" +description = "" +authors = ["Your Name "] + +[tool.poetry.dependencies] +python = ">=3.10.0,<3.12" +crewai = "0.1.24" +python-dotenv = "1.0.0" + +[tool.pyright] +# https://github.com/microsoft/pyright/blob/main/docs/configuration.md +useLibraryCodeForTypes = true +exclude = [".cache"] + +[tool.ruff] +# https://beta.ruff.rs/docs/configuration/ +select = ['E', 'W', 'F', 'I', 'B', 'C4', 'ARG', 'SIM'] +ignore = ['W291', 'W292', 'W293'] + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" \ No newline at end of file diff --git a/game-builder-crew/tasks.py b/game-builder-crew/tasks.py new file mode 100644 index 00000000..c4be40fb --- /dev/null +++ b/game-builder-crew/tasks.py @@ -0,0 +1,48 @@ +from textwrap import dedent +from crewai import Task + +class GameTasks(): + def code_task(self, agent, game): + return Task(description=dedent(f"""You will create a game using python, these are the instructions: + + Instructions + ------------ + {game} + + Your Final answer must be the full python code, only the python code and nothing else. + """), + agent=agent + ) + + def review_task(self, agent, game): + return Task(description=dedent(f"""\ + You are helping create a game using python, these are the instructions: + + Instructions + ------------ + {game} + + Using the code you got, check for errors. Check for logic errors, + syntax errors, missing imports, variable declarations, mismatched brackets, + and security vulnerabilities. + + Your Final answer must be the full python code, only the python code and nothing else. + """), + agent=agent + ) + + def evaluate_task(self, agent, game): + return Task(description=dedent(f"""\ + You are helping create a game using python, these are the instructions: + + Instructions + ------------ + {game} + + You will look over the code to insure that it is complete and + does the job that it is supposed to do. + + Your Final answer must be the full python code, only the python code and nothing else. + """), + agent=agent + ) \ No newline at end of file