Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/phidatahq/phidata
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Nov 13, 2024
2 parents c9f4132 + e7d585b commit 5a1f3d4
Show file tree
Hide file tree
Showing 22 changed files with 722 additions and 199 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/stale-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Close Stale Issues

on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
close_stale_issues:
runs-on: ubuntu-latest
permissions:
issues: write

steps:
- name: Close stale issues
uses: actions/stale@v5
with:
stale-issue-message: >
This issue has been marked as stale because it has been inactive
for more than 14 days. Please update this issue or it will be
automatically closed.
days-before-issue-stale: 14
days-before-issue-close: 0
stale-issue-label: stale

# Disable PR processing
days-before-pr-stale: -1
days-before-pr-close: -1

# Only process issues, not PRs
only-issue-labels: "*"
69 changes: 0 additions & 69 deletions cookbook/agents/zoom.py

This file was deleted.

1 change: 0 additions & 1 deletion cookbook/agents_101/.gitignore

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
app = Playground(agents=[finance_agent, web_agent, agent_team]).get_app()

if __name__ == "__main__":
serve_playground_app("agent_ui:app", reload=True)
serve_playground_app("04_agent_ui:app", reload=True)
14 changes: 7 additions & 7 deletions cookbook/agents_101/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ export OPENAI_API_KEY=***
pip install -U openai duckduckgo-search duckdb yfinance lancedb tantivy pypdf sqlalchemy 'fastapi[standard]' phidata
```

### 4. Web Search Agent
### 4. Run the Web Search Agent

```shell
python cookbook/agents_101/web_search.py
python cookbook/agents_101/01_web_search.py
```

### 5. Finance Agent
### 5. Run the Finance Agent

```shell
python cookbook/agents_101/finance_agent.py
python cookbook/agents_101/02_finance_agent.py
```

### 6. RAG Agent
### 6. Run the RAG Agent

```shell
python cookbook/agents_101/rag_agent.py
python cookbook/agents_101/03_rag_agent.py
```

### 7. Test in Agent UI
Expand All @@ -50,5 +50,5 @@ phi auth
Run the Agent UI

```shell
python cookbook/agents_101/agent_ui.py
python cookbook/agents_101/04_agent_ui.py
```
72 changes: 72 additions & 0 deletions cookbook/knowledge/combined_kb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from pathlib import Path

from phi.agent import Agent
from phi.knowledge.csv import CSVKnowledgeBase
from phi.knowledge.pdf import PDFKnowledgeBase, PDFUrlKnowledgeBase
from phi.knowledge.website import WebsiteKnowledgeBase
from phi.knowledge.combined import CombinedKnowledgeBase
from phi.vectordb.pgvector import PgVector

db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

# Create CSV knowledge base
csv_kb = CSVKnowledgeBase(
path=Path("data/csvs"),
vector_db=PgVector(
table_name="csv_documents",
db_url=db_url,
),
)

# Create PDF URL knowledge base
pdf_url_kb = PDFUrlKnowledgeBase(
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=PgVector(
table_name="pdf_documents",
db_url=db_url,
),
)

# Create Website knowledge base
website_kb = WebsiteKnowledgeBase(
urls=["https://docs.phidata.com/introduction"],
max_links=10,
vector_db=PgVector(
table_name="website_documents",
db_url=db_url,
),
)

# Create Local PDF knowledge base
local_pdf_kb = PDFKnowledgeBase(
path="data/pdfs",
vector_db=PgVector(
table_name="pdf_documents",
db_url=db_url,
),
)

# Combine knowledge bases
knowledge_base = CombinedKnowledgeBase(
sources=[
csv_kb,
pdf_url_kb,
website_kb,
local_pdf_kb,
],
vector_db=PgVector(
table_name="combined_documents",
db_url=db_url,
),
)

# Initialize the Agent with the combined knowledge base
agent = Agent(
knowledge_base=knowledge_base,
add_references_to_prompt=True,
)

knowledge_base.load(recreate=False)

# Use the agent
agent.print_response("Ask me about something from the knowledge base", markdown=True)
28 changes: 28 additions & 0 deletions cookbook/knowledge/csv_kb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from pathlib import Path

from phi.agent import Agent
from phi.knowledge.csv import CSVKnowledgeBase
from phi.vectordb.pgvector import PgVector

db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"


knowledge_base = CSVKnowledgeBase(
path=Path("data/csvs"),
vector_db=PgVector(
table_name="csv_documents",
db_url=db_url,
),
num_documents=5, # Number of documents to return on search
)
# Load the knowledge base
knowledge_base.load(recreate=False)

# Initialize the Agent with the knowledge_base
agent = Agent(
knowledge_base=knowledge_base,
add_references_to_prompt=True,
)

# Use the agent
agent.print_response("Ask me about something from the knowledge base", markdown=True)
27 changes: 27 additions & 0 deletions cookbook/knowledge/docx_kb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from pathlib import Path

from phi.agent import Agent
from phi.vectordb.pgvector import PgVector
from phi.knowledge.docx import DocxKnowledgeBase

db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

# Create a knowledge base with the DOCX files from the data/docs directory
knowledge_base = DocxKnowledgeBase(
path=Path("data/docs"),
vector_db=PgVector(
table_name="docx_documents",
db_url=db_url,
),
)
# Load the knowledge base
knowledge_base.load(recreate=False)

# Create an agent with the knowledge base
agent = Agent(
knowledge_base=knowledge_base,
add_references_to_prompt=True,
)

# Ask the agent about the knowledge base
agent.print_response("Ask me about something from the knowledge base", markdown=True)
4 changes: 2 additions & 2 deletions cookbook/knowledge/json_kb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Initialize the JSONKnowledgeBase
knowledge_base = JSONKnowledgeBase(
path=Path("data/docs"), # Table name: ai.json_documents
path=Path("data/json"), # Table name: ai.json_documents
vector_db=PgVector(
table_name="json_documents",
db_url=db_url,
Expand All @@ -18,7 +18,7 @@
# Load the knowledge base
knowledge_base.load(recreate=False)

# Initialize the Assistant with the knowledge_base
# Initialize the Agent with the knowledge_base
agent = Agent(
knowledge_base=knowledge_base,
add_references_to_prompt=True,
Expand Down
File renamed without changes.
72 changes: 72 additions & 0 deletions cookbook/rag/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Agentic RAG

**RAG:** is a technique that allows an Agent to search for information to improve its responses. This directory contains a series of cookbooks that demonstrate how to build a RAG for the Agent.

> Note: Fork and clone this repository if needed
### 1. Create a virtual environment

```shell
python3 -m venv ~/.venvs/aienv
source ~/.venvs/aienv/bin/activate
```

### 2. Install libraries

```shell
pip install -U openai sqlalchemy "psycopg[binary]" pgvector lancedb tantivy pypdf sqlalchemy "fastapi[standard]" phidata
```

### 3. Run PgVector

> Install [docker desktop](https://docs.docker.com/desktop/install/mac-install/) first.
- Run using a helper script

```shell
./cookbook/run_pgvector.sh
```

- OR run using the docker run command

```shell
docker run -d \
-e POSTGRES_DB=ai \
-e POSTGRES_USER=ai \
-e POSTGRES_PASSWORD=ai \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-v pgvolume:/var/lib/postgresql/data \
-p 5532:5432 \
--name pgvector \
phidata/pgvector:16
```

### 4. Run the Traditional RAG with PgVector

```shell
python cookbook/rag/01_traditional_rag_pgvector.py
```

### 5. Run the Agentic RAG with PgVector

```shell
python cookbook/rag/02_agentic_rag_pgvector.py
```

### 6. Run the Traditional RAG with LanceDB

```shell
python cookbook/rag/03_traditional_rag_lancedb.py
```

### 7. Run the Agentic RAG with LanceDB

```shell
python cookbook/rag/04_agentic_rag_lancedb.py
```

### 8. Run the Agentic RAG on Agent UI

```shell
python cookbook/rag/05_agentic_rag_agent_ui.py
```
Loading

0 comments on commit 5a1f3d4

Please sign in to comment.