-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 #215 from mplachta/knowledge-example
Knowledge example
- Loading branch information
Showing
12 changed files
with
4,945 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
__pycache__/ |
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,48 @@ | ||
# PDF Knowledge Example | ||
|
||
This project demonstrates how to create a Crew of AI agents and tasks using crewAI. It uses a PDF knowledge source to answer user questions based on the content of the PDF. The PDF is loaded from a file and the knowledge source is initialized with it. The project also includes a custom task that uses the knowledge source to answer user questions. You can modify the question in the `main.py` file. | ||
|
||
## Installation | ||
|
||
Ensure you have Python >=3.10 <=3.13 installed on your system. This project uses [UV](https://docs.astral.sh/uv/) for dependency management and package handling, offering a seamless setup and execution experience. | ||
|
||
First, if you haven't already, install uv: | ||
|
||
```bash | ||
pip install uv | ||
``` | ||
|
||
Next, navigate to your project directory and install the dependencies: | ||
|
||
(Optional) Lock the dependencies and install them by using the CLI command: | ||
```bash | ||
crewai install | ||
``` | ||
### Customizing | ||
|
||
**Add your `OPENAI_API_KEY` into the `.env` file** | ||
|
||
- Modify `src/meta_quest_knowledge/config/agents.yaml` to define your agents | ||
- Modify `src/meta_quest_knowledge/config/tasks.yaml` to define your tasks | ||
- Modify `src/meta_quest_knowledge/crew.py` to add your own logic, tools and specific args | ||
- Modify `src/meta_quest_knowledge/main.py` to add custom inputs for your agents and tasks | ||
|
||
## Running the Project | ||
|
||
To kickstart your crew of AI agents and begin task execution, run this from the root folder of your project: | ||
|
||
```bash | ||
$ crewai run | ||
``` | ||
|
||
This command initializes the Crew, assembling the agents and assigning them tasks as defined in your configuration. | ||
|
||
## Additional Knowledge Sources | ||
|
||
Explore [Knowledge](https://docs.crewai.com/concepts/knowledge) documentation for more information on how to use different knowledge sources. | ||
You can select from multiple different knowledge sources such as: | ||
* Text files | ||
* PDFs | ||
* CSV & Excel files | ||
* JSON files | ||
* Sources supported by [docling](https://github.com/DS4SD/docling) |
Binary file not shown.
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,4 @@ | ||
User name is John Doe. | ||
User is an AI Engineer. | ||
User is interested in AI Agents. | ||
User is based in San Francisco, California. |
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,20 @@ | ||
[project] | ||
name = "Meta Quest Knowledge" | ||
version = "0.1.0" | ||
description = "Knowledge Example using crewAI" | ||
authors = [{ name = "Mike Plachta", email = "[email protected]" }] | ||
requires-python = ">=3.10,<=3.13" | ||
dependencies = [ | ||
"crewai[tools]>=0.95.0,<1.0.0", | ||
] | ||
|
||
[project.scripts] | ||
meta_quest_knowledge = "meta_quest_knowledge.main:run" | ||
run_crew = "meta_quest_knowledge.main:run" | ||
train = "meta_quest_knowledge.main:train" | ||
replay = "meta_quest_knowledge.main:replay" | ||
test = "meta_quest_knowledge.main:test" | ||
|
||
[build-system] | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" |
Empty file.
10 changes: 10 additions & 0 deletions
10
meta_quest_knowledge/src/meta_quest_knowledge/config/agents.yaml
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,10 @@ | ||
meta_quest_expert: | ||
role: > | ||
Meta Quest Expert | ||
goal: > | ||
Provide the best possible answers to questions about Meta Quest | ||
backstory: > | ||
You're a seasoned expert in the world of Meta Quest. You're known for your | ||
ability to provide the best possible answers to questions about this | ||
cutting-edge technology, ensuring that your audience is well-informed and | ||
satisfied with the latest advancements in the field. |
9 changes: 9 additions & 0 deletions
9
meta_quest_knowledge/src/meta_quest_knowledge/config/tasks.yaml
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,9 @@ | ||
answer_question_task: | ||
description: > | ||
Answer the user question with the most relevant information from the context and available knowledge sources. | ||
Question: {question} | ||
Do not answer questions that are not related to the context or knowledge sources. | ||
expected_output: > | ||
Best answer to the user question | ||
agent: meta_quest_expert |
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,42 @@ | ||
from crewai import Agent, Crew, Process, Task | ||
from crewai.project import CrewBase, agent, crew, task | ||
from crewai.knowledge.source.pdf_knowledge_source import PDFKnowledgeSource | ||
|
||
# Knowledge sources | ||
pdf_source = PDFKnowledgeSource( | ||
file_paths=["meta_quest_manual.pdf"] | ||
) | ||
|
||
@CrewBase | ||
class MetaQuestKnowledge(): | ||
"""MetaQuestKnowledge crew""" | ||
|
||
agents_config = 'config/agents.yaml' | ||
tasks_config = 'config/tasks.yaml' | ||
|
||
@agent | ||
def meta_quest_expert(self) -> Agent: | ||
return Agent( | ||
config=self.agents_config['meta_quest_expert'], | ||
verbose=True | ||
) | ||
|
||
@task | ||
def answer_question_task(self) -> Task: | ||
return Task( | ||
config=self.tasks_config['answer_question_task'], | ||
) | ||
|
||
@crew | ||
def crew(self) -> Crew: | ||
"""Creates the MetaQuestKnowledge crew""" | ||
|
||
return Crew( | ||
agents=self.agents, # Automatically created by the @agent decorator | ||
tasks=self.tasks, # Automatically created by the @task decorator | ||
process=Process.sequential, | ||
verbose=True, | ||
knowledge_sources=[ | ||
pdf_source | ||
] | ||
) |
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,58 @@ | ||
#!/usr/bin/env python | ||
import sys | ||
import warnings | ||
|
||
from meta_quest_knowledge.crew import MetaQuestKnowledge | ||
|
||
warnings.filterwarnings("ignore", category=SyntaxWarning, module="pysbd") | ||
|
||
# This main file is intended to be a way for you to run your | ||
# crew locally, so refrain from adding unnecessary logic into this file. | ||
# Replace with inputs you want to test with, it will automatically | ||
# interpolate any tasks and agents information | ||
|
||
def run(): | ||
""" | ||
Run the crew. | ||
""" | ||
inputs = { | ||
'question': 'How often should I take breaks?', | ||
} | ||
MetaQuestKnowledge().crew().kickoff(inputs=inputs) | ||
|
||
|
||
def train(): | ||
""" | ||
Train the crew for a given number of iterations. | ||
""" | ||
inputs = { | ||
'question': 'How often should I take breaks?', | ||
} | ||
try: | ||
MetaQuestKnowledge().crew().train(n_iterations=int(sys.argv[1]), filename=sys.argv[2], inputs=inputs) | ||
|
||
except Exception as e: | ||
raise Exception(f"An error occurred while training the crew: {e}") | ||
|
||
def replay(): | ||
""" | ||
Replay the crew execution from a specific task. | ||
""" | ||
try: | ||
MetaQuestKnowledge().crew().replay(task_id=sys.argv[1]) | ||
|
||
except Exception as e: | ||
raise Exception(f"An error occurred while replaying the crew: {e}") | ||
|
||
def test(): | ||
""" | ||
Test the crew execution and returns the results. | ||
""" | ||
inputs = { | ||
'question': 'How often should I take breaks?', | ||
} | ||
try: | ||
MetaQuestKnowledge().crew().test(n_iterations=int(sys.argv[1]), openai_model_name=sys.argv[2], inputs=inputs) | ||
|
||
except Exception as e: | ||
raise Exception(f"An error occurred while replaying the crew: {e}") |
Empty file.
Oops, something went wrong.