From 2822bdf6adc753bea0980bd378c61920e7eaadf2 Mon Sep 17 00:00:00 2001 From: Ashpreet Bedi Date: Wed, 23 Oct 2024 13:33:17 +0100 Subject: [PATCH] README --- README.md | 11 +++-- cookbook/agents/07_monitoring.py | 4 ++ cookbook/agents/08_debugging.py | 4 ++ .../{python_agent.py => 09_python_agent.py} | 1 - .../{data_analyst.py => 10_data_analyst.py} | 1 - ...ured_output.py => 11_structured_output.py} | 0 cookbook/agents/movie_agent.py | 42 ------------------- cookbook/agents/telemetry.py | 26 ------------ 8 files changed, 13 insertions(+), 76 deletions(-) create mode 100644 cookbook/agents/07_monitoring.py create mode 100644 cookbook/agents/08_debugging.py rename cookbook/agents/{python_agent.py => 09_python_agent.py} (99%) rename cookbook/agents/{data_analyst.py => 10_data_analyst.py} (99%) rename cookbook/agents/{structured_output.py => 11_structured_output.py} (100%) delete mode 100644 cookbook/agents/movie_agent.py delete mode 100644 cookbook/agents/telemetry.py diff --git a/README.md b/README.md index 126e03507..b2ba7c45b 100644 --- a/README.md +++ b/README.md @@ -292,7 +292,8 @@ The Agent Playground includes a few demo agents that you can test with. If you h Phidata comes with built-in monitoring. You can set `monitoring=True` on any agent to track sessions or set `PHI_MONITORING=true` in your environment. -> Note: Run `phi auth` first to authenticate your local account. +> [!NOTE] +> Run `phi auth` to authenticate your local account or export the `PHI_API_KEY` ```python from phi.agent import Agent @@ -307,7 +308,7 @@ Run the agent and monitor the results on [phidata.app/sessions](https://www.phid # You can also set the environment variable # export PHI_MONITORING=true -python agent_monitor.py +python monitoring.py ``` View the agent session on [phidata.app/sessions](https://www.phidata.app/sessions) @@ -365,11 +366,9 @@ python_agent = PythonAgent( python_agent.print_response("What is the average rating of movies?") ``` -- Install pandas and run the `python_agent.py` +- Run the `python_agent.py` ```shell -pip install pandas - python python_agent.py ``` @@ -506,6 +505,6 @@ Phidata logs which model an agent used so we can prioritize features for the mos You can disable this by setting `PHI_TELEMETRY=false` in your environment. -

+

⬆️ Back to Top

diff --git a/cookbook/agents/07_monitoring.py b/cookbook/agents/07_monitoring.py new file mode 100644 index 000000000..bda701f31 --- /dev/null +++ b/cookbook/agents/07_monitoring.py @@ -0,0 +1,4 @@ +from phi.agent import Agent + +agent = Agent(markdown=True, monitoring=True) +agent.print_response("Share a 2 sentence horror story") diff --git a/cookbook/agents/08_debugging.py b/cookbook/agents/08_debugging.py new file mode 100644 index 000000000..7ad79b916 --- /dev/null +++ b/cookbook/agents/08_debugging.py @@ -0,0 +1,4 @@ +from phi.agent import Agent + +agent = Agent(markdown=True, debug_mode=True) +agent.print_response("Share a 2 sentence horror story") diff --git a/cookbook/agents/python_agent.py b/cookbook/agents/09_python_agent.py similarity index 99% rename from cookbook/agents/python_agent.py rename to cookbook/agents/09_python_agent.py index 9300ee152..a3dd04b14 100644 --- a/cookbook/agents/python_agent.py +++ b/cookbook/agents/09_python_agent.py @@ -22,5 +22,4 @@ pip_install=True, show_tool_calls=True, ) - python_agent.print_response("What is the average rating of movies?") diff --git a/cookbook/agents/data_analyst.py b/cookbook/agents/10_data_analyst.py similarity index 99% rename from cookbook/agents/data_analyst.py rename to cookbook/agents/10_data_analyst.py index bf9f140dd..fad91f1f6 100644 --- a/cookbook/agents/data_analyst.py +++ b/cookbook/agents/10_data_analyst.py @@ -21,7 +21,6 @@ indent=2, ), ) - data_analyst.print_response( "Show me a histogram of ratings. " "Choose an appropriate bucket size but share how you chose it. " diff --git a/cookbook/agents/structured_output.py b/cookbook/agents/11_structured_output.py similarity index 100% rename from cookbook/agents/structured_output.py rename to cookbook/agents/11_structured_output.py diff --git a/cookbook/agents/movie_agent.py b/cookbook/agents/movie_agent.py deleted file mode 100644 index 1804f4d3b..000000000 --- a/cookbook/agents/movie_agent.py +++ /dev/null @@ -1,42 +0,0 @@ -from typing import List -from rich.pretty import pprint # noqa -from pydantic import BaseModel, Field -from phi.agent import Agent, RunResponse # noqa -from phi.model.openai import OpenAIChat - - -class MovieScript(BaseModel): - setting: str = Field(..., description="Provide a nice setting for a blockbuster movie.") - ending: str = Field(..., description="Ending of the movie. If not available, provide a happy ending.") - genre: str = Field( - ..., description="Genre of the movie. If not available, select action, thriller or romantic comedy." - ) - name: str = Field(..., description="Give a name to this movie") - characters: List[str] = Field(..., description="Name of characters for this movie.") - storyline: str = Field(..., description="3 sentence storyline for the movie. Make it exciting!") - - -# Agent that uses JSON mode -json_mode_agent = Agent( - model=OpenAIChat(id="gpt-4o"), - description="You write movie scripts.", - response_model=MovieScript, -) - -# Agent that uses structured outputs -structured_output_agent = Agent( - model=OpenAIChat(id="gpt-4o-2024-08-06"), - description="You write movie scripts.", - response_model=MovieScript, - structured_outputs=True, -) - - -# Get the response in a variable -# 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) - -json_mode_agent.print_response("New York") -structured_output_agent.print_response("New York") diff --git a/cookbook/agents/telemetry.py b/cookbook/agents/telemetry.py deleted file mode 100644 index 46af6fcd2..000000000 --- a/cookbook/agents/telemetry.py +++ /dev/null @@ -1,26 +0,0 @@ -import asyncio - -from phi.agent import Agent -from phi.model.openai import OpenAIChat -from phi.tools.yfinance import YFinanceTools -from phi.storage.agent.postgres import PgAgentStorage - -agent = Agent( - model=OpenAIChat(id="gpt-4o"), - tools=[YFinanceTools(stock_price=True)], - show_tool_calls=True, - markdown=True, - debug_mode=True, - storage=PgAgentStorage(table_name="agent_sessions", db_url="postgresql+psycopg://ai:ai@localhost:5532/ai"), -) - - -async def main(): - await agent.aprint_response("What is the stock price of NVDA and TSLA") - await agent.aprint_response("What is the stock price of NVDA and TSLA", stream=True) - - -asyncio.run(main()) - -agent.print_response("What is the stock price of NVDA and TSLA?") -agent.print_response("What is the stock price of NVDA and TSLA?", stream=True)