How to Install and Use Phidata: Your Gateway to Smart Applications πŸš€

Monday, Dec 16, 2024 | 7 minute read

GitHub Trend
How to Install and Use Phidata: Your Gateway to Smart Applications πŸš€

Discover a groundbreaking open-source solution that simplifies the creation of multimodal intelligent agents! 🌟 Easy to use, offering real-time monitoring, supporting collaborative agent teams, and handling diverse data formats, it empowers developers to innovate seamlessly in the smart app landscape! πŸ’‘πŸš€

“The future is here, and the blue ocean of smart applications is unfolding before us!” 🌊

In this rapidly changing era, our lives are being transformed by a variety of smart applications - they seem to spring up like mushrooms after rain! But what powers this smart revolution? The answer is undoubtedly the Phidata Framework! ✨ It is a shining gem that attracts countless developers. Phidata not only provides flexible and easy-to-use tools for developing multimodal intelligent agents but is also the best embodiment of an open-source spirit, encouraging more participation and contributions! Through this framework, developers can bring their imaginations to life, allowing smart applications to integrate seamlessly into our everyday lives!

1. Phidata: The Ultimate Framework for Building Intelligent Agents 🧠

Phidata is an incredibly cool open-source framework designed specifically for developers, aimed at simplifying the process of creating multimodal intelligent agents. πŸ’ͺ With it, developers can build agents with memory, reasoning, and tool integration capabilities, making smart applications more accessible! Whether it’s text, images, audio, or video, Phidata can easily handle various data formats, providing users with rich interactive experiences! 🌈

2. Phidata’s Features: Key Capabilities That Outshine the Competition πŸ’‘

  • Multimodal Support: Supports multiple data processing formats, offering developers more flexibility and space for creativity! ✨
  • Collaborative Agent Team: Developers can form collaborative teams of agents within Phidata, significantly enhancing the ability to tackle complex tasks. 🀝
  • Elegant User Interface: The framework features an intuitive user interface that makes interactions between users and agents feel as natural and smooth as conversing with a friend. πŸ’¬
  • Structured Output: The responses from agents are presented in structured formats, greatly enhancing the usability and readability of results! πŸ“Š
  • Monitoring and Debugging Tools: Built-in monitoring and debugging tools help developers track agent performance in real time, ensuring smooth and efficient application operation. πŸ”§

3. Why Choose Phidata: Reasons Developers Love It 🌟

Many developers are drawn to Phidata because of its easy installation, elegant code implementation, and excellent performance in multi-agent collaboration! πŸ“ˆ Even better, the project provides rich monitoring and debugging tools that enable developers to work more efficiently while building smart applications. Phidata is designed to simplify the creation and management of complex multimodal agents, providing reliable support, allowing developers to quickly implement effective smart applications even in complex environments! πŸ’ͺ

With Phidata, developers can unleash their creativity and potential, stepping into a new era of smarter applications! πŸ˜„


Mastering Phidata: Usage Tips and Tricks πŸ”§

Let’s dive deeper into the usage tips for Phidata, gradually guiding you through code examples to help you better grasp this open-source project! πŸš€

How to Install πŸ“¦

First, make sure you have phidata and its dependency libraries installed in your development environment! Open your terminal and run the following command:

pip install -U phidata
  • Here, pip is Python’s package manager, install is used to install the specified package, and -U indicates that it should upgrade to the latest version! πŸŽ‰

Next, install the libraries needed for specific agents with the following command:

pip install openai duckduckgo-search yfinance lancedb tantivy pypdf sqlalchemy fastapi[standard]
  • This includes openai for accessing OpenAI’s API, yfinance for retrieving financial data, and fastapi, which helps build web applications. Very practical, isn’t it? πŸ’Ό

Creating a Web Search Agent 🌐

Let’s create a simple web search agent! You need to create a file named web_search.py in your project directory and enter the following code:

from phi.agent import Agent  # Import the Agent class for creating agents
from phi.model.openai import OpenAIChat  # Import the OpenAIChat model
from phi.tools.duckduckgo import DuckDuckGo  # Import the DuckDuckGo search tool

# Create an agent named web_agent
web_agent = Agent(
    model=OpenAIChat(id="gpt-4o"),  # Use OpenAI's GPT-4 model
    tools=[DuckDuckGo()],  # Use the DuckDuckGo search tool
    instructions=["Always include sources"],  # Set the agent's instruction to always include sources
    show_tool_calls=True,  # Enable showing tool call details
    markdown=True,  # Enable markdown format for better display
)

# Print response, asking about OpenAI Sora
web_agent.print_response("Tell me about OpenAI Sora?", stream=True)
  • The code imports the necessary modules and tools. When creating the agent, we use OpenAI’s GPT-4 model and integrate DuckDuckGo for web search! How clever, right? 😎
  • The instructions list provides commands for the agent, and the final print_response method poses a question to the agent, displaying its answer in the terminal!

To start the agent, remember to execute the following command and replace it with your OpenAI API key:

export OPENAI_API_KEY=sk-xxxx  # Replace with your OpenAI API key
python web_search.py

Creating a Financial Agent πŸ’Ή

Next, we will create a financial analysis agent. Create a new file named finance_agent.py and enter this code:

from phi.agent import Agent  # Import the Agent class
from phi.model.openai import OpenAIChat  # Import the OpenAIChat model
from phi.tools.yfinance import YFinanceTools  # Import YFinanceTools for financial data

# Create an agent named finance_agent
finance_agent = Agent(
    name="Finance Agent",  # Set the agent's name
    model=OpenAIChat(id="gpt-4o"),  # Continue using OpenAI's GPT-4 model
    tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)],  # Utilize YFinanceTools for comprehensive financial data
    instructions=["Use tables to display data"],  # Set agent's instruction
    show_tool_calls=True,  # Enable showing tool call details
    markdown=True,  # Enable markdown for better output
)

# Print a summary of analyst recommendations for NVDA
finance_agent.print_response("Summarize analyst recommendations for NVDA", stream=True)
  • This code uses YFinanceTools to fetch financial data, setting instructions for the agent to display data in tables, enhancing the intuitiveness of the results! πŸ“ˆ

Simply run the command:

python finance_agent.py

Creating an Image Processing Agent πŸ–ΌοΈ

Next, let’s create an agent capable of handling images. Create a new file named image_agent.py and write the following code:

from phi.agent import Agent  # Import the Agent class
from phi.model.openai import OpenAIChat  # Import the OpenAIChat model
from phi.tools.duckduckgo import DuckDuckGo  # Also use the DuckDuckGo search tool

# Create an agent named agent
agent = Agent(
    model=OpenAIChat(id="gpt-4o"),  # Use OpenAI's GPT-4 model
    tools=[DuckDuckGo()],  # Use the DuckDuckGo search tool
    markdown=True,  # Enable markdown
)

# Print image information and related news
agent.print_response(
    "Tell me about this image and give me the latest news about it.", 
    images=["https://upload.wikimedia.org/wikipedia/commons/b/bf/Krakow_-_Kosciol_Mariacki.jpg"],  # Specify the image URL
    stream=True,
)
  • With this approach, the agent can not only accept images but also provide relevant information! Imagine retrieving background details and recent news about an imageβ€”how convenient is that! πŸ“Έ

Run it with:

python image_agent.py

Creating Collaborative Agents 🀝

Finally, let’s set up an example with a team of agents working together. Create a file named agent_team.py and add this code:

from phi.agent import Agent  # Import the Agent class
from phi.model.openai import OpenAIChat  # Import the OpenAIChat model
from phi.tools.duckduckgo import DuckDuckGo  # Import the DuckDuckGo tool
from phi.tools.yfinance import YFinanceTools  # Import YFinanceTools

# Create Web Agent
web_agent = Agent(
    name="Web Agent",  # Set the Web agent's name
    role="Search the web for information",  # Set the agent's role
    model=OpenAIChat(id="gpt-4o"),  # Use the GPT-4 model
    tools=[DuckDuckGo()],  # Add the DuckDuckGo tool
    instructions=["Always include sources"],  # Set instructions
    show_tool_calls=True,  # Enable showing tool calls
    markdown=True,  # Enable markdown display
)

# Create Finance Agent
finance_agent = Agent(
    name="Finance Agent",  # Set the Finance agent's name
    role="Get financial data",  # Set the agent's role to get financial data
    model=OpenAIChat(id="gpt-4o"),  # Use the same model
    tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True)],  # Use YFinanceTools for financial data
    instructions=["Use tables to display data"],  # Set instructions
    show_tool_calls=True,  # Enable showing tool calls
    markdown=True,  # Enable markdown display
)

# Create the agent team
agent_team = Agent(
    team=[web_agent, finance_agent],  # Combine Web Agent and Finance Agent 
    model=OpenAIChat(id="gpt-4o"),  # Use the GPT-4 model
    instructions=["Always include sources", "Use tables to display data"],  # Set team execution instructions
    show_tool_calls=True,  # Enable showing call details
    markdown=True,  # Enable markdown
)

# Print response, asking to summarize analyst ratings for NVDA and share the latest news
agent_team.print_response("Summarize analyst recommendations and share the latest news for NVDA", stream=True)
  • This code creates two distinct agents: one for web searches and another for retrieving financial data. Such combinations undoubtedly provide more comprehensive information! πŸ“Š

To run this agent team, simply enter:

python agent_team.py

With these engaging examples, you’ll be able to quickly master Phidata and create various types of intelligent agents, making the development process even easier and more fun! πŸŽ‰

Β© 2024 - 2025 GitHub Trend

πŸ“ˆ Fun Projects πŸ”