Skip to content

Commit

Permalink
change-knowledge_base-to-knowledge-phi-2000
Browse files Browse the repository at this point in the history
  • Loading branch information
ysolanky committed Nov 19, 2024
1 parent aa4ecaf commit e2d2ad0
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 301 deletions.
42 changes: 10 additions & 32 deletions cookbook/integrations/chromadb/agent.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,22 @@
import typer
from rich.prompt import Prompt
from typing import Optional

from phi.agent import Agent
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.chroma import ChromaDb


knowledge_base = PDFUrlKnowledgeBase(
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=ChromaDb(collection="recipes"),
)

# Comment out after first run
knowledge_base.load(recreate=False)

agent = Agent(
knowledge=knowledge_base,
# Show tool calls in the response
show_tool_calls=True,
# Enable the agent to search the knowledge base
search_knowledge=True,
# Enable the agent to read the chat history
read_chat_history=True,
)

def pdf_agent(user: str = "user"):
run_id: Optional[str] = None

agent = Agent(
run_id=run_id,
user_id=user,
knowledge_base=knowledge_base,
use_tools=True,
show_tool_calls=True,
debug_mode=True,
)
if run_id is None:
run_id = agent.run_id
print(f"Started Run: {run_id}\n")
else:
print(f"Continuing Run: {run_id}\n")

while True:
message = Prompt.ask(f"[bold] :sunglasses: {user} [/bold]")
if message in ("exit", "bye"):
break
agent.print_response(message)


if __name__ == "__main__":
typer.run(pdf_agent)
agent.print_response("How do I make pad thai?", markdown=True)
42 changes: 10 additions & 32 deletions cookbook/integrations/lancedb/agent.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import typer
from rich.prompt import Prompt
from typing import Optional

from phi.agent import Agent
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.lancedb import LanceDb

# type: ignore
db_url = "/tmp/lancedb"

knowledge_base = PDFUrlKnowledgeBase(
Expand All @@ -17,31 +12,14 @@
# Comment out after first run
knowledge_base.load(recreate=False)

agent = Agent(
knowledge=knowledge_base,
# Show tool calls in the response
show_tool_calls=True,
# Enable the agent to search the knowledge base
search_knowledge=True,
# Enable the agent to read the chat history
read_chat_history=True,
)

def pdf_agent(user: str = "user"):
run_id: Optional[str] = None

agent = Agent(
run_id=run_id,
user_id=user,
knowledge_base=knowledge_base,
use_tools=True,
show_tool_calls=True,
# Uncomment the following line to use traditional RAG
# add_references_to_prompt=True,
)
if run_id is None:
run_id = agent.run_id
print(f"Started Run: {run_id}\n")
else:
print(f"Continuing Run: {run_id}\n")

while True:
message = Prompt.ask(f"[bold] :sunglasses: {user} [/bold]")
if message in ("exit", "bye"):
break
agent.print_response(message)


if __name__ == "__main__":
typer.run(pdf_agent)
agent.print_response("How do I make pad thai?", markdown=True)
50 changes: 14 additions & 36 deletions cookbook/integrations/pinecone/agent.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import os
import typer
from typing import Optional
from rich.prompt import Prompt
from os import getenv

from phi.agent import Agent
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.pineconedb import PineconeDB

api_key = os.getenv("PINECONE_API_KEY")
api_key = getenv("PINECONE_API_KEY")
index_name = "thai-recipe-index"

vector_db = PineconeDB(
Expand All @@ -24,35 +21,16 @@
)

# Comment out after first run
knowledge_base.load(recreate=False, upsert=True)


def pinecone_agent(user: str = "user"):
run_id: Optional[str] = None

agent = Agent(
run_id=run_id,
user_id=user,
knowledge_base=knowledge_base,
use_tools=True,
show_tool_calls=True,
debug_mode=True,
# Uncomment the following line to use traditional RAG
# add_references_to_prompt=True,
)

if run_id is None:
run_id = agent.run_id
print(f"Started Run: {run_id}\n")
else:
print(f"Continuing Run: {run_id}\n")

while True:
message = Prompt.ask(f"[bold] :sunglasses: {user} [/bold]")
if message in ("exit", "bye"):
break
agent.print_response(message)

knowledge_base.load(recreate=False)

agent = Agent(
knowledge=knowledge_base,
# Show tool calls in the response
show_tool_calls=True,
# Enable the agent to search the knowledge base
search_knowledge=True,
# Enable the agent to read the chat history
read_chat_history=True,
)

if __name__ == "__main__":
typer.run(pinecone_agent)
agent.print_response("How do I make pad thai?", markdown=True)
53 changes: 15 additions & 38 deletions cookbook/integrations/qdrant/agent.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import os
import typer
from typing import Optional
from rich.prompt import Prompt
from os import getenv

from phi.agent import Agent
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.qdrant import Qdrant

api_key = os.getenv("QDRANT_API_KEY")
qdrant_url = os.getenv("QDRANT_URL")
api_key = getenv("QDRANT_API_KEY")
qdrant_url = getenv("QDRANT_URL")
collection_name = "thai-recipe-index"

vector_db = Qdrant(
Expand All @@ -23,36 +20,16 @@
)

# Comment out after first run
knowledge_base.load(recreate=True, upsert=True)


def qdrant_agent(user: str = "user"):
run_id: Optional[str] = None

agent = Agent(
run_id=run_id,
user_id=user,
knowledge_base=knowledge_base,
tool_calls=True,
use_tools=True,
show_tool_calls=True,
debug_mode=True,
# Uncomment the following line to use traditional RAG
# add_references_to_prompt=True,
)

if run_id is None:
run_id = agent.run_id
print(f"Started Run: {run_id}\n")
else:
print(f"Continuing Run: {run_id}\n")

while True:
message = Prompt.ask(f"[bold] :sunglasses: {user} [/bold]")
if message in ("exit", "bye"):
break
agent.print_response(message)

knowledge_base.load(recreate=False)

agent = Agent(
knowledge=knowledge_base,
# Show tool calls in the response
show_tool_calls=True,
# Enable the agent to search the knowledge base
search_knowledge=True,
# Enable the agent to read the chat history
read_chat_history=True,
)

if __name__ == "__main__":
typer.run(qdrant_agent)
agent.print_response("How do I make pad thai?", markdown=True)
38 changes: 10 additions & 28 deletions cookbook/integrations/singlestore/agent.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import typer
from typing import Optional
from os import getenv

from sqlalchemy.engine import create_engine

from phi.assistant import Assistant
from phi.agent import Agent
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.singlestore import S2VectorDb

Expand Down Expand Up @@ -33,28 +31,12 @@
# Comment out after first run
knowledge_base.load(recreate=False)


def pdf_assistant(user: str = "user"):
run_id: Optional[str] = None

assistant = Assistant(
run_id=run_id,
user_id=user,
knowledge_base=knowledge_base,
use_tools=True,
show_tool_calls=True,
# Uncomment the following line to use traditional RAG
# add_references_to_prompt=True,
)
if run_id is None:
run_id = assistant.run_id
print(f"Started Run: {run_id}\n")
else:
print(f"Continuing Run: {run_id}\n")

while True:
assistant.cli_app(markdown=True)


if __name__ == "__main__":
typer.run(pdf_assistant)
agent = Agent(
knowledge_base=knowledge_base,
# Show tool calls in the response
show_tool_calls=True,
# Enable the agent to search the knowledge base
search_knowledge=True,
# Enable the agent to read the chat history
read_chat_history=True,
)
4 changes: 2 additions & 2 deletions cookbook/knowledge/arxiv_kb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

# Create an agent with the knowledge base
agent = Agent(
knowledge_base=knowledge_base,
add_references_to_prompt=True,
knowledge=knowledge_base,
add_context=True,
)

# Ask the agent about the knowledge base
Expand Down
4 changes: 2 additions & 2 deletions cookbook/knowledge/combined_kb.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@

# Initialize the Agent with the combined knowledge base
agent = Agent(
knowledge_base=knowledge_base,
add_references_to_prompt=True,
knowledge=knowledge_base,
add_context=True,
)

knowledge_base.load(recreate=False)
Expand Down
4 changes: 2 additions & 2 deletions cookbook/knowledge/csv_kb.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

# Initialize the Agent with the knowledge_base
agent = Agent(
knowledge_base=knowledge_base,
add_references_to_prompt=True,
knowledge=knowledge_base,
add_context=True,
)

# Use the agent
Expand Down
43 changes: 0 additions & 43 deletions cookbook/knowledge/custom_references.py

This file was deleted.

4 changes: 2 additions & 2 deletions cookbook/knowledge/docx_kb.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

# Create an agent with the knowledge base
agent = Agent(
knowledge_base=knowledge_base,
add_references_to_prompt=True,
knowledge=knowledge_base,
add_context=True,
)

# Ask the agent about the knowledge base
Expand Down
4 changes: 2 additions & 2 deletions cookbook/knowledge/json_kb.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

# Initialize the Agent with the knowledge_base
agent = Agent(
knowledge_base=knowledge_base,
add_references_to_prompt=True,
knowledge=knowledge_base,
add_context=True,
)

# Use the agent
Expand Down
Loading

0 comments on commit e2d2ad0

Please sign in to comment.