Skip to content

Commit

Permalink
Merge branch 'anyscale-models-phi-1210' into together-models-phi-1209
Browse files Browse the repository at this point in the history
  • Loading branch information
manthanguptaa authored Oct 4, 2024
2 parents ba29d2a + cdf82a5 commit 7ccd90c
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 52 deletions.
1 change: 0 additions & 1 deletion cookbook/providers/anyscale/.env-template

This file was deleted.

51 changes: 36 additions & 15 deletions cookbook/providers/anyscale/README.md
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
```


14 changes: 9 additions & 5 deletions cookbook/providers/anyscale/agent.py
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")

13 changes: 9 additions & 4 deletions cookbook/providers/anyscale/agent_stream.py
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)
11 changes: 11 additions & 0 deletions cookbook/providers/anyscale/basic.py
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")
13 changes: 13 additions & 0 deletions cookbook/providers/anyscale/basic_stream.py
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)
5 changes: 0 additions & 5 deletions cookbook/providers/anyscale/cli.py

This file was deleted.

23 changes: 23 additions & 0 deletions cookbook/providers/anyscale/data_analyst.py
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)
17 changes: 17 additions & 0 deletions cookbook/providers/anyscale/finance_agent.py
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)
14 changes: 0 additions & 14 deletions cookbook/providers/anyscale/news_search.py

This file was deleted.

27 changes: 19 additions & 8 deletions cookbook/providers/anyscale/structured_output.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import List
from pydantic import BaseModel, Field
from rich.pretty import pprint # noqa

from pydantic import BaseModel, Field
from phi.agent import Agent, RunResponse # noqa
from phi.model.anyscale import Anyscale

Expand All @@ -17,15 +16,27 @@ class MovieScript(BaseModel):
storyline: str = Field(..., description="3 sentence storyline for the movie. Make it exciting!")


movie_writer = Agent(
# Agent that uses JSON mode
json_mode_agent = Agent(
model=Anyscale(id="mistralai/Mixtral-8x7B-Instruct-v0.1"),
description="You write movie scripts.",
response_model=MovieScript,
)

# Agent that uses structured outputs
structured_output_agent = Agent(
model=Anyscale(id="mistralai/Mixtral-8x7B-Instruct-v0.1"),
description="You help people write movie scripts.",
description="You write movie scripts.",
response_model=MovieScript,
debug_mode=True,
structured_outputs=True,
)


# Get the response in a variable
# run: RunResponse = movie_writer.run("New York")
# pprint(run.content)
# json_mode_response: RunResponse = json_mode_agent.run("New York")
# pprint(json_mode_response.content)
# structured_output_response: RunResponse = structured_output_agent.run("New York")
# pprint(structured_output_response.content)

movie_writer.print_response("New York")
json_mode_agent.print_response("New York")
structured_output_agent.print_response("New York")
8 changes: 8 additions & 0 deletions cookbook/providers/anyscale/web_search.py
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)

0 comments on commit 7ccd90c

Please sign in to comment.