AI Personal Learning
and practical guidance

PhiData: Building an AI assistant with memory, knowledge and tools

General Introduction

PhiData is a framework designed for developing intelligent AI assistants. It enables AI assistants to conduct long-term conversations, provide accurate business context, and perform a variety of operations through enhanced memory, knowledge integration, and tool invocation capabilities.PhiData not only enhances the intelligence of AI assistants, but also extends their application scope, enabling them to understand and respond to user needs with greater precision.

 


PhiData: Building an Artificial Intelligence Assistant with Memory, Knowledge and Tools-1

 

PhiData: Building an AI Assistant with Memory, Knowledge and Tools-2

 

 

Function List

  • Memory: store chat history and maintain long-term conversations
  • Knowledge: Storing information through vector databases to provide business contexts
  • Tools: call APIs to get data, send emails, perform database queries, etc.
  • Data analysis: using SQL, DuckDb and other tools for data analysis
  • Report generation: conduct research and generate reports
  • Q&A: Answer questions from PDFs, APIs, and more!
  • Article and video summaries: summarize article and video content

 

 

Using Help

Installation of Phidata

  1. https://github.com/phidatahq/phidata
  2. Make sure you have Python and pip installed in your development environment.
  3. Execute the following command in the command line tool to install Phidata:
    pip install -U phidata
    

     

Environment Configuration

  1. Setting environment variables, e.g. when using OpenAI's API, requires settingOPENAI_API_KEY::
    export OPENAI_API_KEY=sk-xxxx
    

 

Quick Start

Creating an AI assistant capable of using DuckDuckGo for web searches

  1. Creating Documentsassistant.py::
    from phi.assistant import Assistant
    from phi.tools.duckduckgo import DuckDuckGo
    
    assistant = Assistant(tools=[DuckDuckGo()], show_tool_calls=True)
    assistant.print_response("What's happening in France?", markdown=True)
    
  2. Install the library and run Assistant:
    pip install openai duckduckgo-search
    python assistant.py
    

 

Create an assistant that can query financial data

  1. Creating Documentsfinance_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. Install the library and run Assistant:
    pip install yfinance
    python finance_assistant.py
    

 

Advanced Applications

PhiData is not only suitable for building basic AI assistants, but also has a range of advanced features including data model generation, SQL data analysis, and Python code execution. Here are some examples of advanced features:

Helpers for writing and running Python code

  1. Creating Documentspython_assistant.py::
    from phi.assistant.python import PythonAssistant
    
    assistant = PythonAssistant()
    assistant.print_response("Write a Python script to calculate the Fibonacci sequence.")
    
  2. Install the library and run Assistant:
    pip install openai
    python python_assistant.py
    

With the steps above, you can quickly get started and build your own intelligent AI assistant that takes full advantage of the power of PhiData.

 

Why phidata

 

Question:LLM has a limited background to take action.
Solution:Add memories, knowledge and tools.

Memory:by combiningChat HistoryStored in a database, it enables LLM to have long conversations.
Knowledge:By storing the information in a vector database, the LLM provides theOperational context.
Tools:Enables LLMs to take data from APIs, send emails or query databases, etc.manipulateThe

Memory and knowledge make LL.Smarter.And the tools make themautonomyThe

 

How does it work?

Step 1:Create an `Assistant`
Step 2:Adding tools (functions), knowledge (vectordb) and storage (database)
Step 3:Build your AI app with Streamlit, FastApi or Django

 

(for) instance

1. Create a virtual environment

Open `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

`assistant.py` creates a file using an assistant that can search the web using DuckDuckGo.

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

Use the helper `OpenAI` by default. Set your `OPENAI_API_KEY` (which you can get from [here are]Get one).

export OPENAI_API_KEY=sk-***

Install `openai` & `duckduckgo`.

pip install openai duckduckgo-search

Running Assistant

python assistant.py

 

demonstrations

View the following AI applications built with phidata:

[PDF AI] summarize and answer the questions in the PDF.
[ArXiv AI] uses the ArXiv API to answer questions about ArXiv papers.
[HackerNews AI]Summarize stories, users and share the latest news from HackerNews.

AI Easy Learning

The layman's guide to getting started with AI

Help you learn how to utilize AI tools at a low cost and from a zero base.AI, like office software, is an essential skill for everyone. Mastering AI will give you an edge in your job search and half the effort in your future work and studies.

View Details>
May not be reproduced without permission:Chief AI Sharing Circle " PhiData: Building an AI assistant with memory, knowledge and tools

Chief AI Sharing Circle

Chief AI Sharing Circle specializes in AI learning, providing comprehensive AI learning content, AI tools and hands-on guidance. Our goal is to help users master AI technology and explore the unlimited potential of AI together through high-quality content and practical experience sharing. Whether you are an AI beginner or a senior expert, this is the ideal place for you to gain knowledge, improve your skills and realize innovation.

Contact Us
en_USEnglish