-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'anyscale-models-phi-1210' into together-models-phi-1209
- Loading branch information
Showing
12 changed files
with
145 additions
and
52 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,54 +1,75 @@ | ||
## Anyscale Endpoints | ||
# Anyscale Cookbook | ||
|
||
> Note: Fork and clone this repository if needed | ||
1. Create a virtual environment | ||
### 1. Create and activate a virtual environment | ||
|
||
```shell | ||
python3 -m venv ~/.venvs/aienv | ||
source ~/.venvs/aienv/bin/activate | ||
``` | ||
|
||
2. Install libraries | ||
### 2. Export your `ANYSCALE_API_KEY` | ||
|
||
```shell | ||
pip install -U openai phidata | ||
export ANYSCALE_API_KEY=*** | ||
``` | ||
|
||
3. Export `ANYSCALE_API_KEY` | ||
### 3. Install libraries | ||
|
||
```shell | ||
export ANYSCALE_API_KEY=*** | ||
pip install -U openai duckduckgo-search duckdb yfinance phidata | ||
``` | ||
|
||
### 4. Run Agent without Tools | ||
|
||
- Streaming on | ||
|
||
```shell | ||
python cookbook/providers/anyscale/basic_stream.py | ||
``` | ||
|
||
- Streaming off | ||
|
||
```shell | ||
python cookbook/providers/anyscale/basic.py | ||
``` | ||
|
||
4. Test Anyscale Assistant | ||
### 5. Run Agent with Tools | ||
|
||
- Streaming | ||
- Yahoo Finance with streaming on | ||
|
||
```shell | ||
python cookbook/providers/anyscale/agent_stream.py | ||
``` | ||
|
||
- Without Streaming | ||
- Yahoo Finance without streaming | ||
|
||
```shell | ||
python cookbook/providers/anyscale/agent.py | ||
``` | ||
|
||
5. Test Structured output | ||
- Finance Agent | ||
|
||
```shell | ||
python cookbook/providers/anyscale/structured_output.py | ||
python cookbook/providers/anyscale/finance_agent.py | ||
``` | ||
|
||
6. Test function calling | ||
- Data Analyst | ||
|
||
```shell | ||
python cookbook/providers/anyscale/web_search.py | ||
python cookbook/providers/anyscale/data_analyst.py | ||
``` | ||
|
||
7. Test CLI App | ||
- DuckDuckGo Search | ||
```shell | ||
python cookbook/providers/together/web_search.py | ||
``` | ||
|
||
### 6. Run Agent that returns structured output | ||
|
||
```shell | ||
python cookbook/providers/anyscale/cli.py | ||
python cookbook/providers/anyscale/structured_output.py | ||
``` | ||
|
||
|
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 |
---|---|---|
@@ -1,16 +1,20 @@ | ||
"""Run `pip install yfinance` to install dependencies.""" | ||
|
||
from phi.agent import Agent, RunResponse # noqa | ||
from phi.model.anyscale import Anyscale | ||
from phi.tools.yfinance import YFinanceTools | ||
|
||
agent = Agent( | ||
model=Anyscale(id="mistralai/Mixtral-8x7B-Instruct-v0.1"), | ||
description="You help people with their health and fitness goals.", | ||
markdown=True, | ||
tools=[YFinanceTools(stock_price=True)], | ||
show_tool_calls=True, | ||
markdown=True, | ||
) | ||
|
||
# Get the response in a variable | ||
# run: RunResponse = agent.run("Share a 2 sentence quick and healthy breakfast recipe.") | ||
# run: RunResponse = agent.run("What is the stock price of NVDA and TSLA") | ||
# print(run.content) | ||
|
||
# Print the response on the terminal | ||
agent.print_response("Share a 2 sentence quick and healthy breakfast recipe.", markdown=True) | ||
# Print the response in the terminal | ||
agent.print_response("What is the stock price of NVDA and TSLA") | ||
|
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 |
---|---|---|
@@ -1,17 +1,22 @@ | ||
"""Run `pip install yfinance` to install dependencies.""" | ||
|
||
from typing import Iterator # noqa | ||
from phi.agent import Agent, RunResponse # noqa | ||
from phi.model.anyscale import Anyscale | ||
from phi.tools.yfinance import YFinanceTools | ||
|
||
agent = Agent( | ||
model=Anyscale(id="mistralai/Mixtral-8x7B-Instruct-v0.1"), | ||
description="You help people with their health and fitness goals.", | ||
tools=[YFinanceTools(stock_price=True)], | ||
instructions=["Use tables where possible."], | ||
markdown=True, | ||
show_tool_calls=True, | ||
) | ||
|
||
# Get the response in a variable | ||
# run: RunResponse = agent.run("Share a 2 sentence quick and healthy breakfast recipe.", stream=True) | ||
# run_response: Iterator[RunResponse] = agent.run("What is the stock price of NVDA and TSLA", stream=True) | ||
# for chunk in run_response: | ||
# print(chunk.content) | ||
|
||
# Print the response on the terminal | ||
agent.print_response("Share a 2 sentence quick and healthy breakfast recipe.", stream=True) | ||
# Print the response in the terminal | ||
agent.print_response("What is the stock price of NVDA and TSLA", stream=True) |
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,11 @@ | ||
from phi.agent import Agent, RunResponse # noqa | ||
from phi.model.anyscale import Anyscale | ||
|
||
agent = Agent(model=Anyscale(id="mistralai/Mixtral-8x7B-Instruct-v0.1"), markdown=True) | ||
|
||
# Get the response in a variable | ||
# run: RunResponse = agent.run("Share a 2 sentence horror story") | ||
# print(run.content) | ||
|
||
# Print the response in the terminal | ||
agent.print_response("Share a 2 sentence horror story") |
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,13 @@ | ||
from typing import Iterator # noqa | ||
from phi.agent import Agent, RunResponse # noqa | ||
from phi.model.anyscale import Anyscale | ||
|
||
agent = Agent(model=Anyscale(id="mistralai/Mixtral-8x7B-Instruct-v0.1"), markdown=True) | ||
|
||
# Get the response in a variable | ||
# run_response: Iterator[RunResponse] = agent.run("Share a 2 sentence horror story", stream=True) | ||
# for chunk in run_response: | ||
# print(chunk.content) | ||
|
||
# Print the response in the terminal | ||
agent.print_response("Share a 2 sentence horror story", stream=True) |
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
"""Run `pip install duckdb` to install dependencies.""" | ||
|
||
from textwrap import dedent | ||
from phi.agent import Agent | ||
from phi.model.anyscale import Anyscale | ||
from phi.tools.duckdb import DuckDbTools | ||
|
||
duckdb_tools = DuckDbTools(create_tables=False, export_tables=False, summarize_tables=False) | ||
duckdb_tools.create_table_from_path( | ||
path="https://phidata-public.s3.amazonaws.com/demo_data/IMDB-Movie-Data.csv", table="movies" | ||
) | ||
|
||
agent = Agent( | ||
model=Anyscale(id="mistralai/Mixtral-8x7B-Instruct-v0.1"), | ||
tools=[duckdb_tools], | ||
markdown=True, | ||
show_tool_calls=True, | ||
additional_context=dedent("""\ | ||
You have access to the following tables: | ||
- movies: contains information about movies from IMDB. | ||
"""), | ||
) | ||
agent.print_response("What is the average rating of movies?", stream=False) |
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,17 @@ | ||
"""Run `pip install yfinance` to install dependencies.""" | ||
|
||
from phi.agent import Agent | ||
from phi.model.anyscale import Anyscale | ||
from phi.tools.yfinance import YFinanceTools | ||
|
||
agent = Agent( | ||
model=Anyscale(id="mistralai/Mixtral-8x7B-Instruct-v0.1"), | ||
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, stock_fundamentals=True)], | ||
show_tool_calls=True, | ||
description="You are an investment analyst that researches stocks and helps users make informed decisions.", | ||
instructions=["Use tables to display data where possible."], | ||
markdown=True, | ||
) | ||
|
||
# agent.print_response("Share the NVDA stock price and analyst recommendations", stream=True) | ||
agent.print_response("Summarize fundamentals for TSLA", stream=True) |
This file was deleted.
Oops, something went wrong.
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
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,8 @@ | ||
"""Run `pip install duckduckgo-search` to install dependencies.""" | ||
|
||
from phi.agent import Agent | ||
from phi.model.anyscale import Anyscale | ||
from phi.tools.duckduckgo import DuckDuckGo | ||
|
||
agent = Agent(model=Anyscale(id="mistralai/Mixtral-8x7B-Instruct-v0.1"), tools=[DuckDuckGo()], show_tool_calls=True, markdown=True) | ||
agent.print_response("Whats happening in France?", stream=True) |