Adding game builder crew

This commit is contained in:
João Moura
2024-01-21 15:02:40 -03:00
parent 7b3d68d9ee
commit 6ea5295ce5
8 changed files with 199 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.DS_Store

View File

@@ -0,0 +1 @@
OPENAI_API_KEY=...

3
game-builder-crew/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
__pycache__
.env
.DS_Store

View File

@@ -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.

View File

@@ -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
)

49
game-builder-crew/main.py Normal file
View File

@@ -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)

View File

@@ -0,0 +1,24 @@
[tool.poetry]
name = "game-crew"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
[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"

View File

@@ -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
)