Skip to content

Commit

Permalink
cookbook refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Apr 16, 2024
1 parent 7fd91cd commit f4fe1ca
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 147 deletions.
12 changes: 7 additions & 5 deletions cookbook/assistants/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ python cookbook/assistants/web_search.py
python cookbook/assistants/python_assistant.py
```

## Assistants with Knowledge
## Run PgVector

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

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

or
- OR run using the docker run command

```shell
docker run -d \
Expand All @@ -75,6 +75,8 @@ docker run -d \
phidata/pgvector:16
```

## Assistants with Knowledge

- Install libraries

```shell
Expand All @@ -93,7 +95,7 @@ python cookbook/assistants/rag_assistant.py
python cookbook/assistants/auto_assistant.py
```

## Assistants with Memory, Knowledge and Tools
## Assistants with Storage, Knowledge & Tools

- PDF Assistant

Expand Down
37 changes: 28 additions & 9 deletions cookbook/examples/autonomous/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
## Autonomous Assistant
# Autonomous Assistant

> Fork and clone the repository if needed.
1. Start pgvector
### 1. Create a virtual environment

```shell
phi start cookbook/examples/auto/resources.py -y
python3 -m venv ~/.venvs/aienv
source ~/.venvs/aienv/bin/activate
```

2. Install libraries
### 2. Install libraries

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

3. Run Autonomous Assistant
### 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
python cookbook/examples/auto/assistant.py
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. Stop pgvector
### 4. Run Autonomous Assistant

```shell
phi stop cookbook/examples/auto/resources.py -y
python cookbook/examples/autonomous/assistant.py
```
10 changes: 6 additions & 4 deletions cookbook/examples/autonomous/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.pgvector import PgVector2

from resources import vector_db # type: ignore

knowledge_base = PDFUrlKnowledgeBase(
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=PgVector2(collection="recipes", db_url=vector_db.get_db_connection_local()),
vector_db=PgVector2(collection="recipes", db_url="postgresql+psycopg://ai:ai@localhost:5532/ai"),
)
knowledge_base.load(recreate=False)

assistant = Assistant(
knowledge_base=knowledge_base,
use_tools=True,
# Show tool calls in the response
show_tool_calls=True,
# Enable the assistant to search the knowledge base
search_knowledge=True,
# Enable the assistant to read the chat history
read_chat_history=True,
)

assistant.print_response("How do I make pad thai?", markdown=True)
Expand Down
12 changes: 0 additions & 12 deletions cookbook/examples/autonomous/resources.py

This file was deleted.

32 changes: 22 additions & 10 deletions cookbook/examples/local_rag/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,28 @@ source ~/.venvs/aienv/bin/activate
pip install -r cookbook/examples/local_rag/requirements.txt
```

### 4. Run pgvector
### 4. 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
phi start cookbook/examples/local_rag/resources.py -y
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
```

### 5. Run Streamlit application
Expand Down Expand Up @@ -65,12 +83,6 @@ Run CLI with a different model
python cookbook/examples/local_rag/cli.py --model gemma:7b
```

### 7. Turn off pgvector

```shell
phi stop cookbook/examples/local_rag/resources.py -y
```

### 8. Message me on [discord](https://discord.gg/4MtYHHrgA8) if you have any questions
### 7. Message me on [discord](https://discord.gg/4MtYHHrgA8) if you have any questions

### 9. Star ⭐️ the project if you like it.
### 8. Star ⭐️ the project if you like it.
12 changes: 0 additions & 12 deletions cookbook/examples/local_rag/resources.py

This file was deleted.

40 changes: 25 additions & 15 deletions cookbook/examples/pdf/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## PDF Assistant with knowledge and storage
# PDF Assistant with knowledge and storage

> Note: Fork and clone this repository if needed
Expand All @@ -8,28 +8,44 @@ Lets create a PDF Assistant that can answer questions from a PDF. We'll use `PgV

**Storage:** provides long term memory for Assistants (uses a database).

1. Create a virtual environment
### 1. Create a virtual environment

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

2. Install libraries
### 2. Install libraries

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

3. Run PgVector
### 3. Run PgVector

- Install [docker desktop](https://docs.docker.com/desktop/install/mac-install/) for running PgVector in a container.
> 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
phi start cookbook/examples/pdf/resources.py -y
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 PDF Assistant
### 4. Run PDF Assistant

```shell
python cookbook/examples/pdf/assistant.py
Expand All @@ -52,11 +68,5 @@ What was my last message?
- Run the `assistant.py` file with the `--new` flag to start a new run.

```shell
python pdf_assistant.py --new
```

5. Stop PgVector

```shell
phi stop cookbook/examples/pdf/resources.py -y
python cookbook/examples/pdf/assistant.py --new
```
12 changes: 0 additions & 12 deletions cookbook/examples/pdf/resources.py

This file was deleted.

37 changes: 28 additions & 9 deletions cookbook/examples/rag/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
## RAG Assistant
# RAG Assistant

> Fork and clone the repository if needed.
1. Start pgvector
### 1. Create a virtual environment

```shell
phi start cookbook/examples/rag/resources.py -y
python3 -m venv ~/.venvs/aienv
source ~/.venvs/aienv/bin/activate
```

2. Install libraries
### 2. Install libraries

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

3. Run RAG Assistant
### 3. Run PgVector

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

```shell
python cookbook/examples/rag/assistant.py
./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. Stop pgvector
### 4. Run RAG Assistant

```shell
phi stop cookbook/examples/rag/resources.py -y
python cookbook/examples/rag/assistant.py
```
12 changes: 0 additions & 12 deletions cookbook/examples/rag/resources.py

This file was deleted.

8 changes: 4 additions & 4 deletions cookbook/integrations/lancedb/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
## Lancedb Assistant
# Lancedb Assistant

1. Create a virtual environment
### 1. Create a virtual environment
```shell
python3 -m venv ~/.venvs/aienv
source ~/.venvs/aienv/bin/activate
```

2. Install libraries
### 2. Install libraries
```shell
pip install -U lancedb pypdf pandas openai phidata
```

3. Run Assistant
### 3. Run Assistant
```shell
python cookbook/integrations/lancedb/assistant.py
```
Loading

0 comments on commit f4fe1ca

Please sign in to comment.