-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
129 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Run `pip install duckduckgo-search sqlalchemy pgvector pypdf anthropic openai` to install dependencies.""" | ||
|
||
from phi.agent import Agent | ||
from phi.model.anthropic import Claude | ||
from phi.knowledge.pdf import PDFUrlKnowledgeBase | ||
from phi.vectordb.pgvector import PgVector | ||
|
||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai" | ||
|
||
knowledge_base = PDFUrlKnowledgeBase( | ||
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"], | ||
vector_db=PgVector(table_name="recipes", db_url=db_url), | ||
) | ||
knowledge_base.load(recreate=True) # Comment out after first run | ||
|
||
agent = Agent( | ||
model=Claude(id="claude-3-5-sonnet-20241022"), | ||
knowledge_base=knowledge_base, | ||
use_tools=True, | ||
show_tool_calls=True, | ||
debug_mode=True, | ||
) | ||
agent.print_response("How to make Thai curry?", markdown=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
This recipe shows how to use personalized memories and summaries in an agent. | ||
Steps: | ||
1. Run: `./cookbook/run_pgvector.sh` to start a postgres and pgvector instance | ||
2. Run: `pip install anthropic sqlalchemy 'psycopg[binary]' pgvector` to install the dependencies | ||
3. Run: `python cookbook/agents/personalized_memories_and_summaries.py` to run the agent | ||
""" | ||
|
||
from rich.pretty import pprint | ||
|
||
from phi.agent import Agent, AgentMemory | ||
from phi.model.anthropic import Claude | ||
from phi.memory.db.postgres import PgMemoryDb | ||
from phi.storage.agent.postgres import PgAgentStorage | ||
|
||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai" | ||
agent = Agent( | ||
model=Claude(id="claude-3-5-sonnet-20241022"), | ||
# Store the memories and summary in a database | ||
memory=AgentMemory( | ||
db=PgMemoryDb(table_name="agent_memory", db_url=db_url), create_user_memories=True, create_session_summary=True | ||
), | ||
# Store agent sessions in a database | ||
storage=PgAgentStorage(table_name="personalized_agent_sessions", db_url=db_url), | ||
# Show debug logs so you can see the memory being created | ||
# debug_mode=True, | ||
) | ||
|
||
# -*- Share personal information | ||
agent.print_response("My name is john billings?", stream=True) | ||
# -*- Print memories | ||
pprint(agent.memory.memories) | ||
# -*- Print summary | ||
pprint(agent.memory.summary) | ||
|
||
# -*- Share personal information | ||
agent.print_response("I live in nyc?", stream=True) | ||
# -*- Print memories | ||
pprint(agent.memory.memories) | ||
# -*- Print summary | ||
pprint(agent.memory.summary) | ||
|
||
# -*- Share personal information | ||
agent.print_response("I'm going to a concert tomorrow?", stream=True) | ||
# -*- Print memories | ||
pprint(agent.memory.memories) | ||
# -*- Print summary | ||
pprint(agent.memory.summary) | ||
|
||
# Ask about the conversation | ||
agent.print_response("What have we been talking about, do you know my name?", stream=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Run `pip install duckduckgo-search sqlalchemy anthropic` to install dependencies.""" | ||
|
||
from phi.agent import Agent | ||
from phi.model.anthropic import Claude | ||
from phi.tools.duckduckgo import DuckDuckGo | ||
from phi.storage.agent.postgres import PgAgentStorage | ||
|
||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai" | ||
|
||
agent = Agent( | ||
model=Claude(), | ||
storage=PgAgentStorage(table_name="agent_sessions", db_url=db_url), | ||
tools=[DuckDuckGo()], | ||
add_history_to_messages=True, | ||
) | ||
agent.print_response("How many people live in Canada?") | ||
agent.print_response("What is their national anthem called?") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters