mirror of
https://github.com/crewAIInc/crewAI-examples.git
synced 2026-01-10 22:38:00 -05:00
Adding game builder crew
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.DS_Store
|
||||
1
game-builder-crew/.env.example
Normal file
1
game-builder-crew/.env.example
Normal file
@@ -0,0 +1 @@
|
||||
OPENAI_API_KEY=...
|
||||
3
game-builder-crew/.gitignore
vendored
Normal file
3
game-builder-crew/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
__pycache__
|
||||
.env
|
||||
.DS_Store
|
||||
32
game-builder-crew/README.md
Normal file
32
game-builder-crew/README.md
Normal 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.
|
||||
41
game-builder-crew/agents.py
Normal file
41
game-builder-crew/agents.py
Normal 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
49
game-builder-crew/main.py
Normal 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)
|
||||
24
game-builder-crew/pyprojct.toml
Normal file
24
game-builder-crew/pyprojct.toml
Normal 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"
|
||||
48
game-builder-crew/tasks.py
Normal file
48
game-builder-crew/tasks.py
Normal 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
|
||||
)
|
||||
Reference in New Issue
Block a user