from agno.agent import Agent from agno.knowledge.pdf_url import PDFUrlKnowledgeBase from agno.models.cerebras import Cerebras from agno.vectordb.pgvector import PgVector db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai" knowledge_base = PDFUrlKnowledgeBase( urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"], vector_db=PgVector(table_name="recipes", db_url=db_url), ) knowledge_base.load(recreate=True) # 首次运行时注释掉此行 agent = Agent( model=Cerebras(id="llama-4-scout-17b-16e-instruct"), knowledge=knowledge_base, ) agent.print_response("How to make Thai curry?", markdown=True)
创建虚拟环境
打开 Terminal 并创建一个 python 虚拟环境。
Terminal
python3 -m venv .venv source .venv/bin/activate
设置您的 API 密钥
export CEREBRAS_API_KEY=xxx
安装库
pip install -U agno cerebras-cloud-sdk
启动您的 Postgres 服务器
确保您的 Postgres 服务器正在运行,并且可以从 db_url 中使用的连接字符串访问。
db_url
运行智能体(首次)
首次运行将加载并索引 PDF。这可能需要一些时间。
python cookbook/models/cerebras/basic_knowledge.py
后续运行
首次运行后,注释掉或删除 knowledge_base.load(recreate=True) 以避免每次都重新加载 PDF。
knowledge_base.load(recreate=True)