Skip to content

Commit

Permalink
update-llm-cookbooks-phi-654
Browse files Browse the repository at this point in the history
  • Loading branch information
ysolanky committed Apr 17, 2024
1 parent 85aa2e7 commit d3ff406
Show file tree
Hide file tree
Showing 46 changed files with 188 additions and 147 deletions.
6 changes: 3 additions & 3 deletions cookbook/llms/anyscale/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ source ~/.venvs/aienv/bin/activate
2. Install libraries

```shell
pip install -U phidata openai
pip install -U openai phidata
```

3. Export `ANYSCALE_API_KEY`

```text
export ANYSCALE_API_KEY=<anyscale-api-key>
```shell
export ANYSCALE_API_KEY=***
```

4. Test Anyscale Assistant
Expand Down
2 changes: 1 addition & 1 deletion cookbook/llms/anyscale/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
llm=Anyscale(model="mistralai/Mixtral-8x7B-Instruct-v0.1"),
description="You help people with their health and fitness goals.",
)
assistant.print_response("Share a 2 sentence quick healthy breakfast recipe.", markdown=True)
assistant.print_response("Share a 2 sentence quick and healthy breakfast recipe.", markdown=True)
4 changes: 2 additions & 2 deletions cookbook/llms/anyscale/assistant_stream_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from phi.llm.anyscale import Anyscale

assistant = Assistant(
llm=Anyscale(),
llm=Anyscale(model="mistralai/Mixtral-8x7B-Instruct-v0.1"),
description="You help people with their health and fitness goals.",
)
assistant.print_response("Share a quick healthy breakfast recipe.", stream=False, markdown=True)
assistant.print_response("Share a 2 sentence quick and healthy breakfast recipe.", markdown=True, stream=False)
8 changes: 4 additions & 4 deletions cookbook/llms/azure_openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ pip install -U phidata openai
3. Export Azure Credentials (`AZURE_OPENAI_API_KEY` and `AZURE_OPENAI_ENDPOINT` are required)

```shell
export AZURE_OPENAI_API_KEY=<azure-api-key>
export AZURE_OPENAI_ENDPOINT=<azure-endpoint>
export AZURE_OPENAI_API_KEY=***
export AZURE_OPENAI_ENDPOINT=***
# Optional:
# export AZURE_OPENAI_API_VERSION=<openai-api-version>
# export AZURE_DEPLOYMENT=<azure_deployment>
# export AZURE_OPENAI_API_VERSION=***
# export AZURE_DEPLOYMENT=***
```

4. Test Azure Assistant
Expand Down
4 changes: 2 additions & 2 deletions cookbook/llms/azure_openai/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from phi.llm.azure import AzureOpenAIChat

assistant = Assistant(
llm=AzureOpenAIChat(model="gpt-35-turbo"), # model="deployment_name"
llm=AzureOpenAIChat(model="gpt-35-turbo"),
description="You help people with their health and fitness goals.",
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True)
assistant.print_response("Share a 2 sentence quick and healthy breakfast recipe.", markdown=True)
4 changes: 2 additions & 2 deletions cookbook/llms/azure_openai/assistant_stream_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from phi.llm.azure import AzureOpenAIChat

assistant = Assistant(
llm=AzureOpenAIChat(model="gpt-35-turbo"), # model="deployment_name"
llm=AzureOpenAIChat(model="gpt-35-turbo"),
description="You help people with their health and fitness goals.",
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False)
assistant.print_response("Share a 2 sentence quick and healthy breakfast recipe.", markdown=True, stream=False)
6 changes: 0 additions & 6 deletions cookbook/llms/claude/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ python cookbook/llms/claude/assistant_stream_off.py

### 5. Run Assistant with Tools

- Web search

```shell
python cookbook/llms/claude/web_search.py
```

- YFinance

```shell
Expand Down
6 changes: 4 additions & 2 deletions cookbook/llms/claude/assistant.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from phi.assistant import Assistant
from phi.tools.duckduckgo import DuckDuckGo
from phi.llm.anthropic import Claude

assistant = Assistant(
llm=Claude(model="claude-3-opus-20240229"),
description="You help people with their health and fitness goals.",
tools=[DuckDuckGo()],
show_tool_calls=True,
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True)
assistant.print_response("Whats happening in France?", markdown=True)
6 changes: 4 additions & 2 deletions cookbook/llms/claude/assistant_stream_off.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from phi.assistant import Assistant
from phi.tools.duckduckgo import DuckDuckGo
from phi.llm.anthropic import Claude

assistant = Assistant(
llm=Claude(model="claude-3-opus-20240229"),
description="You help people with their health and fitness goals.",
tools=[DuckDuckGo()],
show_tool_calls=True,
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False)
assistant.print_response("Whats happening in France?", markdown=True, stream=False)
8 changes: 8 additions & 0 deletions cookbook/llms/claude/basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from phi.assistant import Assistant
from phi.llm.anthropic import Claude

assistant = Assistant(
llm=Claude(model="claude-3-haiku-20240307"),
description="You help people with their health and fitness goals.",
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True)
8 changes: 8 additions & 0 deletions cookbook/llms/claude/basic_stream_off.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from phi.assistant import Assistant
from phi.llm.anthropic import Claude

assistant = Assistant(
llm=Claude(model="claude-3-haiku-20240307"),
description="You help people with their health and fitness goals.",
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False)
11 changes: 0 additions & 11 deletions cookbook/llms/claude/web_search.py

This file was deleted.

4 changes: 2 additions & 2 deletions cookbook/llms/cohere/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CohereChat function calling

Currently "command-r" model supports function calling
Currently Cohere's "command-r" and "command-r-plus" models supports function calling

> Note: Fork and clone this repository if needed
Expand All @@ -14,7 +14,7 @@ source ~/.venvs/aienv/bin/activate
### 2. Export your CohereChat API Key

```shell
export CO_API_KEY=xxx
export CO_API_KEY=***
```

### 3. Install libraries
Expand Down
7 changes: 4 additions & 3 deletions cookbook/llms/cohere/assistant.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from phi.assistant import Assistant
from phi.tools.duckduckgo import DuckDuckGo
from phi.llm.cohere import CohereChat

assistant = Assistant(
llm=CohereChat(model="command-r"),
description="You help people with their health and fitness goals.",
debug_mode=True,
tools=[DuckDuckGo()],
show_tool_calls=True,
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True)
assistant.print_response("Whats happening in France?", markdown=True)
7 changes: 4 additions & 3 deletions cookbook/llms/cohere/assistant_stream_off.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from phi.assistant import Assistant
from phi.tools.duckduckgo import DuckDuckGo
from phi.llm.cohere import CohereChat

assistant = Assistant(
llm=CohereChat(model="command-r"),
description="You help people with their health and fitness goals.",
debug_mode=True,
tools=[DuckDuckGo()],
show_tool_calls=True,
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False)
assistant.print_response("Whats happening in France?", markdown=True, stream=False)
8 changes: 8 additions & 0 deletions cookbook/llms/cohere/basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from phi.assistant import Assistant
from phi.llm.cohere import CohereChat

assistant = Assistant(
llm=CohereChat(model="command-r"),
description="You help people with their health and fitness goals.",
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True)
8 changes: 8 additions & 0 deletions cookbook/llms/cohere/basic_stream_off.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from phi.assistant import Assistant
from phi.llm.cohere import CohereChat

assistant = Assistant(
llm=CohereChat(model="command-r"),
description="You help people with their health and fitness goals.",
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False)
12 changes: 0 additions & 12 deletions cookbook/llms/cohere/web_search.py

This file was deleted.

14 changes: 5 additions & 9 deletions cookbook/llms/fireworks/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Fireworks AI Function Calling
## Fireworks AI

> Note: Fork and clone this repository if needed
Expand All @@ -17,14 +17,14 @@ pip install -U openai yfinance exa_py duckduckgo-search streamlit phidata

3. Export `FIREWORKS_API_KEY`

```text
export FIREWORKS_API_KEY=<fireworks-api-key>
```shell
export FIREWORKS_API_KEY=***
```

> If you want to use Exa Search, export `EXA_API_KEY` as well
```text
export EXA_API_KEY=<exa-api-key>
```shell
export EXA_API_KEY=***
```

4. Run streamlit app
Expand Down Expand Up @@ -60,7 +60,3 @@ python cookbook/llms/fireworks/pydantic_output.py
```shell
python cookbook/llms/fireworks/tool_call.py
```

```shell
python cookbook/llms/fireworks/web_search.py
```
8 changes: 5 additions & 3 deletions cookbook/llms/fireworks/assistant.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from phi.assistant import Assistant
from phi.llm.fireworks import Fireworks
from phi.tools.duckduckgo import DuckDuckGo

assistant = Assistant(
llm=Fireworks(),
description="You help people with their health and fitness goals.",
llm=Fireworks(),
tools=[DuckDuckGo()],
show_tool_calls=True
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True)
assistant.print_response("Whats happening in France?", markdown=True)
8 changes: 5 additions & 3 deletions cookbook/llms/fireworks/assistant_stream_off.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from phi.assistant import Assistant
from phi.llm.fireworks import Fireworks
from phi.tools.duckduckgo import DuckDuckGo

assistant = Assistant(
llm=Fireworks(),
description="You help people with their health and fitness goals.",
llm=Fireworks(),
tools=[DuckDuckGo()],
show_tool_calls=True
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False)
assistant.print_response("Whats happening in France?", markdown=True, stream=False)
8 changes: 8 additions & 0 deletions cookbook/llms/fireworks/basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from phi.assistant import Assistant
from phi.llm.fireworks import Fireworks

assistant = Assistant(
llm=Fireworks(),
description="You help people with their health and fitness goals.",
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True)
8 changes: 8 additions & 0 deletions cookbook/llms/fireworks/basic_stream_off.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from phi.assistant import Assistant
from phi.llm.fireworks import Fireworks

assistant = Assistant(
llm=Fireworks(),
description="You help people with their health and fitness goals.",
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False)
6 changes: 0 additions & 6 deletions cookbook/llms/fireworks/web_search.py

This file was deleted.

32 changes: 18 additions & 14 deletions cookbook/llms/groq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ source ~/.venvs/aienv/bin/activate
> Need to use OpenAI for embeddings as Groq doesn't support embeddings yet.
```shell
export GROQ_API_KEY=xxx
export GROQ_API_KEY=***
export OPENAI_API_KEY=sk-***
```

Expand All @@ -28,20 +28,32 @@ pip install -r cookbook/llms/groq/requirements.txt

4. Start pgvector

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

```shell
phi start cookbook/llms/groq/resources.py -y
./cookbook/run_pgvector.sh
```

5. Run RAG App
- OR run using the docker run command

```shell
streamlit run cookbook/llms/groq/app.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
```

6. Stop pgvector
5. Run RAG App

```shell
phi stop cookbook/llms/groq/resources.py -y
streamlit run cookbook/llms/groq/app.py
```

## Build AI Assistants with Groq
Expand All @@ -54,14 +66,6 @@ pip install -U groq phidata

2. Run Assistant

- stream on

```shell
python cookbook/llms/groq/assistant.py
```

- stream off

```shell
python cookbook/llms/groq/assistant_stream_off.py
```
7 changes: 4 additions & 3 deletions cookbook/llms/groq/assistant.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from phi.assistant import Assistant
from phi.tools.duckduckgo import DuckDuckGo
from phi.llm.groq import Groq

assistant = Assistant(
llm=Groq(model="mixtral-8x7b-32768"),
description="You help people with their health and fitness goals.",
# debug_mode=True,
tools=[DuckDuckGo()],
show_tool_calls=True,
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True)
assistant.print_response("Whats happening in France?", markdown=True, stream=False)
8 changes: 8 additions & 0 deletions cookbook/llms/groq/basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from phi.assistant import Assistant
from phi.llm.groq import Groq

assistant = Assistant(
llm=Groq(model="mixtral-8x7b-32768"),
description="You help people with their health and fitness goals.",
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
assistant = Assistant(
llm=Groq(model="mixtral-8x7b-32768"),
description="You help people with their health and fitness goals.",
# debug_mode=True,
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False)
Loading

0 comments on commit d3ff406

Please sign in to comment.