这是用户在 2024-6-5 22:41 为 https://docs.phidata.com/introduction 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?

Assistant

Why phidata 为什么选择 phidata?

Problem: LLMs have limited context and cannot take actions.
问题:LLMs 上下文有限,无法执行操作。

Solution: Add memory, knowledge and tools.
解决方案:添加内存、知识和工具。

  • Memory: Enables LLMs to have long-term conversations by storing chat history in a database.
    记忆:通过在数据库中存储聊天记录,使LLMs能够进行长时间的对话。
  • Knowledge: Provides LLMs with business context by storing information in a vector database.
    知识:通过在向量数据库中存储信息,为LLMs提供业务上下文。
  • Tools: Enable LLMs to take actions like pulling data from an API, sending emails or querying a database.
    工具:启用 LLMs 执行操作,例如从 API 中提取数据、发送电子邮件或查询数据库。

Memory & knowledge make LLMs smarter while tools make them autonomous.
记忆和知识使LLMs更聪明,而工具使它们更自主。

How it works 工作原理

  • Step 1: Create an Assistant
    步骤 1:创建 Assistant
  • Step 2: Add Tools (functions), Knowledge (vectordb) and Storage (database) 
  • Step 3: Serve using Streamlit, FastApi or Django to build your AI application
    步骤 3:使用 Streamlit、FastApi 或 Django 部署服务,构建您的 AI 应用程序

LLM = Large Language Model
LLM = 大型语言模型

Example 例子

1

Create a virtual environment
创建虚拟环境

Open the Terminal and create a python virtual environment.
打开 Terminal 并创建一个 python 虚拟环境。

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

Install phidata 安装 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

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. 

Assistant