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.
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
- https://github.com/phidatahq/phidata
- Make sure you have Python and pip installed in your development environment.
- Execute the following command in the command line tool to install Phidata:
pip install -U phidata
Environment Configuration
- Setting environment variables, e.g. when using OpenAI's API, requires setting
OPENAI_API_KEY
::export OPENAI_API_KEY=sk-xxxx
Quick Start
Creating an AI assistant capable of using DuckDuckGo for web searches
- Creating Documents
assistant.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)
- Install the library and run Assistant:
pip install openai duckduckgo-search python assistant.py
Create an assistant that can query financial data
- Creating Documents
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.")
- 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
- Creating Documents
python_assistant.py
::from phi.assistant.python import PythonAssistant assistant = PythonAssistant() assistant.print_response("Write a Python script to calculate the Fibonacci sequence.")
- 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 DuckDuckGoassistant = 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.