mirror of
https://github.com/Shubhamsaboo/awesome-llm-apps.git
synced 2026-05-04 05:58:33 -05:00
30 lines
1019 B
Python
30 lines
1019 B
Python
from phi.agent import Agent
|
|
from phi.model.openai import OpenAIChat
|
|
from phi.knowledge.pdf import PDFUrlKnowledgeBase
|
|
from phi.vectordb.lancedb import LanceDb, SearchType
|
|
from phi.playground import Playground, serve_playground_app
|
|
from phi.tools.duckduckgo import DuckDuckGo
|
|
|
|
db_uri = "tmp/lancedb"
|
|
# 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 database
|
|
vector_db=LanceDb(table_name="recipes", uri=db_uri, search_type=SearchType.vector),
|
|
)
|
|
# Load the knowledge base: Comment out after first run
|
|
knowledge_base.load(upsert=True)
|
|
|
|
rag_agent = Agent(
|
|
model=OpenAIChat(id="gpt-4o"),
|
|
agent_id="rag-agent",
|
|
knowledge=knowledge_base, # Add the knowledge base to the agent
|
|
tools=[DuckDuckGo()],
|
|
show_tool_calls=True,
|
|
markdown=True,
|
|
)
|
|
|
|
app = Playground(agents=[rag_agent]).get_app()
|
|
|
|
if __name__ == "__main__":
|
|
serve_playground_app("rag_agent:app", reload=True) |