Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Created November 23, 2024 00:13
Show Gist options
  • Save amosgyamfi/b57438e2264f6a659c87d765bdb9f467 to your computer and use it in GitHub Desktop.
Save amosgyamfi/b57438e2264f6a659c87d765bdb9f467 to your computer and use it in GitHub Desktop.
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
from phi.playground import Playground, serve_playground_app
# 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="tmp/lancedb",
search_type=SearchType.vector,
embedder=OpenAIEmbedder(model="text-embedding-3-small"),
),
)
knowledge_base.load()
retrieval_agent = Agent(
model=OpenAIChat(id="gpt-4o-mini"),
# Add the knowledge base to the agent
knowledge=knowledge_base,
show_tool_calls=True,
markdown=True,
)
# retrieval_agent.print_response(
# "How do I make chicken and galangal in coconut milk soup", stream=True
# )
# Create playground with both agents
app = Playground(agents=[retrieval_agent]).get_app()
if __name__ == "__main__":
serve_playground_app("retrieval_agent:app", reload=True, port=7777)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment