Skip to content

Commit

Permalink
Improve phi-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Nov 1, 2024
1 parent c2c0c3d commit 6000493
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 10 deletions.
3 changes: 1 addition & 2 deletions cookbook/providers/ollama/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Ollama Cookbook

> Note: Fork and clone this repository if needed
> Ollama Model class has been designed to work with llama models. Support for more model classes coming soon
### 1. [Install](https://github.com/ollama/ollama?tab=readme-ov-file#macos) ollama and run models

Run your chat model

```shell
ollama run llama3.2
ollama run llama3.1:8b
```

Message `/bye` to exit the chat model
Expand Down
2 changes: 1 addition & 1 deletion cookbook/providers/ollama/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from phi.tools.yfinance import YFinanceTools

agent = Agent(
model=Ollama(id="llama3.2"),
model=Ollama(id="llama3.1:8b"),
tools=[YFinanceTools(stock_price=True)],
show_tool_calls=True,
markdown=True,
Expand Down
2 changes: 1 addition & 1 deletion cookbook/providers/ollama/agent_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from phi.tools.yfinance import YFinanceTools

agent = Agent(
model=Ollama(id="llama3.2"),
model=Ollama(id="llama3.1:8b"),
tools=[YFinanceTools(stock_price=True)],
instructions=["Use tables where possible."],
markdown=True,
Expand Down
33 changes: 33 additions & 0 deletions cookbook/providers/ollama/agent_team.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from phi.agent import Agent
from phi.model.ollama import Ollama
from phi.tools.duckduckgo import DuckDuckGo
from phi.tools.yfinance import YFinanceTools

web_agent = Agent(
name="Web Agent",
role="Search the web for information",
model=Ollama(id="llama3.1:8b"),
tools=[DuckDuckGo()],
instructions=["Always include sources"],
show_tool_calls=True,
markdown=True,
)

finance_agent = Agent(
name="Finance Agent",
role="Get financial data",
model=Ollama(id="llama3.1:8b"),
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True)],
instructions=["Use tables to display data"],
show_tool_calls=True,
markdown=True,
)

agent_team = Agent(
team=[web_agent, finance_agent],
instructions=["Always include sources", "Use tables to display data"],
show_tool_calls=True,
markdown=True,
)

agent_team.print_response("Summarize analyst recommendations and share the latest news for NVDA", stream=True)
2 changes: 1 addition & 1 deletion cookbook/providers/ollama/basic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from phi.agent import Agent, RunResponse # noqa
from phi.model.ollama import Ollama

agent = Agent(model=Ollama(id="llama3.2"), markdown=True)
agent = Agent(model=Ollama(id="llama3.1:8b"), markdown=True)

# Get the response in a variable
# run: RunResponse = agent.run("Share a 2 sentence horror story")
Expand Down
2 changes: 1 addition & 1 deletion cookbook/providers/ollama/basic_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from phi.agent import Agent, RunResponse # noqa
from phi.model.ollama import Ollama

agent = Agent(model=Ollama(id="llama3.2"), markdown=True)
agent = Agent(model=Ollama(id="llama3.1:8b"), markdown=True)

# Get the response in a variable
# run_response: Iterator[RunResponse] = agent.run("Share a 2 sentence horror story", stream=True)
Expand Down
2 changes: 1 addition & 1 deletion cookbook/providers/ollama/data_analyst.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)

agent = Agent(
model=Ollama(id="llama3.2"),
model=Ollama(id="llama3.1:8b"),
tools=[duckdb_tools],
markdown=True,
show_tool_calls=True,
Expand Down
2 changes: 1 addition & 1 deletion cookbook/providers/ollama/finance_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from phi.tools.yfinance import YFinanceTools

agent = Agent(
model=Ollama(id="llama3.2"),
model=Ollama(id="llama3.1:8b"),
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.",
Expand Down
2 changes: 1 addition & 1 deletion cookbook/providers/ollama/structured_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MovieScript(BaseModel):

# Agent that uses JSON mode
movie_agent = Agent(
model=Ollama(id="llama3.2"),
model=Ollama(id="llama3.1:8b"),
description="You write movie scripts.",
response_model=MovieScript,
)
Expand Down
2 changes: 1 addition & 1 deletion cookbook/providers/ollama/web_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
from phi.model.ollama import Ollama
from phi.tools.duckduckgo import DuckDuckGo

agent = Agent(model=Ollama(id="llama3.2"), tools=[DuckDuckGo()], show_tool_calls=True, markdown=True)
agent = Agent(model=Ollama(id="llama3.1:8b"), tools=[DuckDuckGo()], show_tool_calls=True, markdown=True)
agent.print_response("Whats happening in France?", stream=True)
4 changes: 4 additions & 0 deletions phi/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2756,6 +2756,8 @@ def print_response(
)
panels.append(response_panel)

# Final update to remove the "Thinking..." status
panels = [p for p in panels if not isinstance(p, Status)]
live_log.update(Group(*panels))

async def aprint_response(
Expand Down Expand Up @@ -2972,6 +2974,8 @@ async def aprint_response(
)
panels.append(response_panel)

# Final update to remove the "Thinking..." status
panels = [p for p in panels if not isinstance(p, Status)]
live_log.update(Group(*panels))

def cli_app(
Expand Down

0 comments on commit 6000493

Please sign in to comment.