Use phidata to turn any LLM into an AI Assistant (aka Agent) that can:

  • Search the web using DuckDuckGo, Google etc.
  • Pull data from APIs like yfinance, polygon etc.
  • Analyze data using SQL, DuckDb, etc.
  • Conduct research and generate reports.
  • Answer questions from PDFs, APIs, etc.
  • Summarize articles, videos, etc.
  • Perform tasks like sending emails, querying databases, etc.
  • And much more…

Assistant

Why phidata

Problem: We need to turn general-purpose LLMs into specialized assistants tailored to our use-case.

Solution: Extend LLMs with memory, knowledge and tools:

  • Memory: Stores chat history in a database and enables LLMs to have long-term conversations.
  • Knowledge: Stores information in a vector database and provides LLMs with business context.
  • Tools: Enable LLMs to take actions like pulling data from an API, sending emails or querying a database.

Memory & knowledge make LLMs smarter while tools make them autonomous.

How it works

  • Step 1: Create an Assistant
  • Step 2: Add Tools (functions), Knowledge (vectordb) and Storage (database)
  • Step 3: Serve using Streamlit, FastApi or Django to build your AI application

LLM = Large Language Model

Example

Build a Web Search Assistant

1

Create a virtual environment

Open the Terminal and create a python virtual environment.

python3 -m venv ~/.venvs/aienv
source ~/.venvs/aienv/bin/activate
2

Install phidata

pip install -U phidata
3

Create an Assistant

Create a file assistant.py with an Assistant that can search the web using DuckDuckGo.

assistant.py
from phi.assistant import Assistant
from phi.tools.duckduckgo import DuckDuckGo

assistant = Assistant(tools=[DuckDuckGo()], show_tool_calls=True)
assistant.print_response("Whats happening in France?", markdown=True)
4

Run the Assistant

Assistants use OpenAI by default. Set your OPENAI_API_KEY (you can get one from here).

export OPENAI_API_KEY=sk-***

Install openai & duckduckgo

pip install openai duckduckgo-search

Run the Assistant

python assistant.py

Build a Finance Assistant

1

Create a Finance Assistant

Create a file finance_assistant.py

finance_assistant.py
from phi.assistant import Assistant
from phi.llm.openai import OpenAIChat
from phi.tools.yfinance import YFinanceTools

assistant = Assistant(
    llm=OpenAIChat(model="gpt-4o"),
    tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)],
    show_tool_calls=True,
    markdown=True,
)
assistant.print_response("What is the stock price of NVDA")
assistant.print_response("Write a comparison between NVDA and AMD, use all tools available.")
2

Run the Assistant

Install yfinance

pip install yfinance

Run the Assistant

python finance_assistant.py

Demos

Checkout the following AI Applications built using phidata:

  • PDF AI summarizes and answers questions from PDFs.
  • ArXiv AI answers questions about ArXiv papers using the ArXiv API.
  • HackerNews AI summarize stories, users and shares what’s new on HackerNews.

Next Steps

  1. Read the basics to learn more about phidata.
  2. Read about Assistants and how to customize them.
  3. Checkout the cookbook for in-depth examples and code.

Looking to build an AI product?

We’ve helped many companies build AI products, the general workflow is:

  1. Build an Assistant with proprietary data to perform tasks specific to your product.
  2. Connect your product to the Assistant via an API.
  3. Monitor and Improve your AI product.

We also provide dedicated support and development, book a call to get started.