当前位置: 首页> 健康> 知识 > 河南一情况_全球优秀企业网站_谈谈你对seo概念的理解_关键词查找的方法有以下几种

河南一情况_全球优秀企业网站_谈谈你对seo概念的理解_关键词查找的方法有以下几种

时间:2025/7/11 15:15:31来源:https://blog.csdn.net/lovechris00/article/details/144892909 浏览次数:1次
河南一情况_全球优秀企业网站_谈谈你对seo概念的理解_关键词查找的方法有以下几种

文章目录

    • 关于 phidata
      • 安装
      • 主要特点
    • 简单优雅
    • 强大而灵活
    • 默认多模态
    • 多代理编排
    • 一个漂亮的代理UI与您的代理聊天
    • 代理RAG
    • 结构化输出
    • 推理代理(实验)
    • 演示代理
    • 监控和调试
      • 监控
      • 调试
    • 寻求帮助
    • 更多例子
      • 可以编写和运行python代码的代理
      • 可以使用SQL分析数据的代理


关于 phidata

Phidata是一个用于构建多模态代理的框架,使用phidata来:

  • 用记忆、知识、工具和推理构建多模态代理。
  • 建立可以一起解决问题的代理团队。
  • 使用漂亮的代理UI与您的代理聊天。

  • github : https://github.com/phidatahq/phidata
  • 官网:https://www.phidata.com/
  • 官方文档:https://docs.phidata.com/introduction
  • Cookbook : https://github.com/phidatahq/phidata/tree/main/cookbook

在这里插入图片描述


安装

pip install -U phidata

主要特点

  • 简单优雅
  • 强大而灵活
  • 默认多模态
  • 多代理编排
  • 一个漂亮的代理UI与您的代理聊天
  • 内置代理RAG
  • 结构化输出
  • 推理代理
  • 内置监控和调试
  • 演示代理

简单优雅

Phidata代理简单而优雅,生成最少、漂亮的代码。

例如,你可以用10行代码创建一个web搜索代理,创建一个文件web_search.py

from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.tools.duckduckgo import DuckDuckGoweb_agent = Agent(model=OpenAIChat(id="gpt-4o"),tools=[DuckDuckGo()],instructions=["Always include sources"],show_tool_calls=True,markdown=True,
)
web_agent.print_response("Tell me about OpenAI Sora?", stream=True)

安装库,导出OPENAI_API_KEY并运行代理:

pip install phidata openai duckduckgo-searchexport OPENAI_API_KEY=sk-xxxxpython web_search.py

强大而灵活

Phidata代理可以使用多种工具并按照说明完成复杂的任务。

例如,您可以创建一个金融代理,使用工具来查询金融数据,创建文件finance_agent.py

from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.tools.yfinance import YFinanceToolsfinance_agent = Agent(name="Finance Agent",model=OpenAIChat(id="gpt-4o"),tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)],instructions=["Use tables to display data"],show_tool_calls=True,markdown=True,
)
finance_agent.print_response("Summarize analyst recommendations for NVDA", stream=True)

安装库并运行代理:

pip install yfinancepython finance_agent.py

默认多模态

Phidata代理支持文本、图像、音频和视频。

例如,您可以创建一个可以理解图像并根据需要进行工具调用的图像代理,创建一个文件image_agent.py

from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.tools.duckduckgo import DuckDuckGoagent = Agent(model=OpenAIChat(id="gpt-4o"),tools=[DuckDuckGo()],markdown=True,
)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"],stream=True,
)

运行代理:

python image_agent.py

多代理编排

Phidata代理可以作为一个团队一起工作来完成复杂的任务,创建文件agent_team.py

from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.tools.duckduckgo import DuckDuckGo
from phi.tools.yfinance import YFinanceToolsweb_agent = Agent(name="Web Agent",role="Search the web for information",model=OpenAIChat(id="gpt-4o"),tools=[DuckDuckGo()],instructions=["Always include sources"],show_tool_calls=True,markdown=True,
)finance_agent = Agent(name="Finance Agent",role="Get financial data",model=OpenAIChat(id="gpt-4o"),tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True)],instructions=["Use tables to display data"],show_tool_calls=True,markdown=True,
)agent_team = Agent(team=[web_agent, finance_agent],model=OpenAIChat(id="gpt-4o"),instructions=["Always include sources", "Use tables to display data"],show_tool_calls=True,markdown=True,
)agent_team.print_response("Summarize analyst recommendations and share the latest news for NVDA", stream=True)

运行代理团队:

python agent_team.py

一个漂亮的代理UI与您的代理聊天

Phidata为与您的代理交互提供了一个漂亮的UI。让我们来看看,创建一个文件playground.py

在这里插入图片描述


注:Phidata不存储任何数据,所有代理数据都本地存储在sqlite数据库中。

from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.storage.agent.sqlite import SqlAgentStorage
from phi.tools.duckduckgo import DuckDuckGo
from phi.tools.yfinance import YFinanceTools
from phi.playground import Playground, serve_playground_appweb_agent = Agent(name="Web Agent",model=OpenAIChat(id="gpt-4o"),tools=[DuckDuckGo()],instructions=["Always include sources"],storage=SqlAgentStorage(table_name="web_agent", db_file="agents.db"),add_history_to_messages=True,markdown=True,
)finance_agent = Agent(name="Finance Agent",model=OpenAIChat(id="gpt-4o"),tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)],instructions=["Use tables to display data"],storage=SqlAgentStorage(table_name="finance_agent", db_file="agents.db"),add_history_to_messages=True,markdown=True,
)app = Playground(agents=[finance_agent, web_agent]).get_app()if __name__ == "__main__":serve_playground_app("playground:app", reload=True)

通过运行以下命令使用phidata进行身份验证:

phi auth

或者从phidata.app导出工作区的PHI_API_KEY

export PHI_API_KEY=phi-***

安装依赖项并运行 Agent Playground:

pip install 'fastapi[standard]' sqlalchemypython playground.py
  • 打开提供的链接 或导航到 http://phidata.app/playground
  • 选择 localhost:7777 端点并开始与您的代理聊天!

AgentPlayground.mp4


代理RAG

我们是第一个使用自动RAG范式开创代理RAG的人。使用代理RAG(或自动rag),代理可以在其知识库(向量db)中搜索完成任务所需的特定信息,而不是总是在提示中插入“上下文”。

这样可以节省令牌并提高响应质量rag_agent.py

from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.embedder.openai import OpenAIEmbedder
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.lancedb import LanceDb, SearchType# Create a knowledge base from a PDF
knowledge_base = PDFUrlKnowledgeBase(urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],# Use LanceDB as the vector databasevector_db=LanceDb(table_name="recipes",uri="tmp/lancedb",search_type=SearchType.vector,embedder=OpenAIEmbedder(model="text-embedding-3-small"),),
)
# Comment out after first run as the knowledge base is loaded
knowledge_base.load()agent = Agent(model=OpenAIChat(id="gpt-4o"),# Add the knowledge base to the agentknowledge=knowledge_base,show_tool_calls=True,markdown=True,
)
agent.print_response("How do I make chicken and galangal in coconut milk soup", stream=True)

安装库并运行代理:

pip install lancedb tantivy pypdf sqlalchemypython rag_agent.py

结构化输出

代理可以将其输出以结构化格式作为Pydantic模型返回。

创建一个文件structured_output.py

from typing import List
from pydantic import BaseModel, Field
from phi.agent import Agent
from phi.model.openai import OpenAIChat# Define a Pydantic model to enforce the structure of the output
class MovieScript(BaseModel):setting: str = Field(..., description="Provide a nice setting for a blockbuster movie.")ending: str = Field(..., description="Ending of the movie. If not available, provide a happy ending.")genre: str = Field(..., description="Genre of the movie. If not available, select action, thriller or romantic comedy.")name: str = Field(..., description="Give a name to this movie")characters: List[str] = Field(..., description="Name of characters for this movie.")storyline: str = Field(..., description="3 sentence storyline for the movie. Make it exciting!")# Agent that uses JSON mode
json_mode_agent = Agent(model=OpenAIChat(id="gpt-4o"),description="You write movie scripts.",response_model=MovieScript,
)
# Agent that uses structured outputs
structured_output_agent = Agent(model=OpenAIChat(id="gpt-4o"),description="You write movie scripts.",response_model=MovieScript,structured_outputs=True,
)json_mode_agent.print_response("New York")
structured_output_agent.print_response("New York")

  • 运行structured_output.py文件
python structured_output.py

  • 输出是MovieScript类的对象,如下所示:
MovieScript(
│   setting='A bustling and vibrant New York City',
│   ending='The protagonist saves the city and reconciles with their estranged family.',
│   genre='action',
│   name='City Pulse',
│   characters=['Alex Mercer', 'Nina Castillo', 'Detective Mike Johnson'],
│   storyline='In the heart of New York City, a former cop turned vigilante, Alex Mercer, teams up with a street-smart activist, Nina Castillo, to take down a corrupt political figure who threatens to destroy the city. As they navigate through the intricate web of power and deception, they uncover shocking truths that push them to the brink of their abilities. With time running out, they must race against the clock to save New York and confront their own demons.'
)

推理代理(实验)

推理帮助代理逐步解决问题,根据需要回溯和纠正。reasoning_agent.py创建文件。

from phi.agent import Agent
from phi.model.openai import OpenAIChattask = ("Three missionaries and three cannibals need to cross a river. ""They have a boat that can carry up to two people at a time. ""If, at any time, the cannibals outnumber the missionaries on either side of the river, the cannibals will eat the missionaries. ""How can all six people get across the river safely? Provide a step-by-step solution and show the solutions as an ascii diagram"
)reasoning_agent = Agent(model=OpenAIChat(id="gpt-4o"), reasoning=True, markdown=True, structured_outputs=True)
reasoning_agent.print_response(task, stream=True, show_full_reasoning=True)

运行推理代理:

python reasoning_agent.py

警告:推理是一个实验性的特性,会打破约20%的时间。它不能代替o1。

这是一个由好奇心推动的实验,结合了COT和工具使用。对这个初始版本设定你的期望很低。例如:它将无法计算“草莓”中的“r”。


演示代理

代理游乐场包括一些您可以测试的演示代理。如果您对其他演示代理有建议,请在我们的社区论坛中告诉我们。

在这里插入图片描述


监控和调试


监控

Phidata带有内置监控。您可以在任何代理上设置monitoring=True以跟踪会话或在您的环境中设置PHI_MONITORING=true

运行phi auth以验证您的本地帐户或导出PHI_API_KEY

from phi.agent import Agentagent = Agent(markdown=True, monitoring=True)
agent.print_response("Share a 2 sentence horror story")

运行代理并监控结果 phidata.app/sessions

# You can also set the environment variable
# export PHI_MONITORING=truepython monitoring.py

查看代理会话phidata.app/sessions

在这里插入图片描述


调试

Phidata还包括一个内置的调试器,它将在终端中显示调试日志。您可以在任何代理上设置debug_mode=True以跟踪会话或在您的环境中设置PHI_DEBUG=true

from phi.agent import Agentagent = Agent(markdown=True, debug_mode=True)
agent.print_response("Share a 2 sentence horror story")

在这里插入图片描述


寻求帮助

  • 阅读文档docs.phidata.com
  • 把你的问题发到社区论坛上
  • 和我们聊不和

更多例子


可以编写和运行python代码的代理

PythonAgent可以通过编写和运行python代码来完成任务。

python_agent = PythonAgent(model=OpenAIChat(id="gpt-4o"),files=[CsvFile(path="https://phidata-public.s3.amazonaws.com/demo_data/IMDB-Movie-Data.csv",description="Contains information about movies from IMDB.",)],markdown=True,pip_install=True,show_tool_calls=True,
)

运行python_agent.py

python python_agent.py

可以使用SQL分析数据的代理

创建一个文件data_analyst.py

from phi.model.openai import OpenAIChat
from phi.agent.duckdb import DuckDbAgentdata_analyst = DuckDbAgent(model=OpenAIChat(model="gpt-4o"),markdown=True,semantic_model=json.dumps({"tables": [{"name": "movies","description": "Contains information about movies from IMDB.","path": "https://phidata-public.s3.amazonaws.com/demo_data/IMDB-Movie-Data.csv",}]},indent=2,),
)

安装Duckdb并运行data_analyst.py文件

pip install duckdbpython data_analyst.py

2024-01-02

关键字:河南一情况_全球优秀企业网站_谈谈你对seo概念的理解_关键词查找的方法有以下几种

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: