Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FalkorDB Multi Graph ability #61

Merged
merged 5 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,33 @@ chat_agent = ChatAgent(
```
Pass in subset of `['search', 'vision', 'locate', 'stocks']` as `include_from_defaults` for different set of default tools upon initialization.

### Multi-Graph
kingjulio8238 marked this conversation as resolved.
Show resolved Hide resolved
When using FalkorDB database, you can create multi-agents. Here is an example of how to set up personal agents for different users:

```python
# User A personal agent
chat_agent_user_a = ChatAgent(
"Personal Agent",
memory_stream_json_user_a,
entity_knowledge_store_json_user_a,
system_persona_txt_user_a,
user_persona_txt_user_a,
past_chat_json_user_a,
user_id='user_a_id'
)

# User B personal agent
chat_agent_user_b = ChatAgent(
"Personal Agent",
memory_stream_json_user_b,
entity_knowledge_store_json_user_b,
system_persona_txt_user_b,
user_persona_txt_user_b,
past_chat_json_user_b,
user_id='user_b_id'
)
```

### Adding Custom Tools
```python
def multiply(a: int, b: int) -> int:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies = [
"neo4j==5.17.0",
"python-dotenv==1.0.1",
"pyvis==0.3.2",
"streamlit==1.31.1",
"streamlit==1.38.0",
"llama-index==0.11.4",
"llama-index-agent-openai==0.3.0",
"llama-index-core==0.11.4",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FalkorDB==1.0.8
neo4j==5.17.0
python-dotenv==1.0.1
pyvis==0.3.2
streamlit==1.31.1
streamlit==1.38.0
llama-index==0.11.4
llama-index-agent-openai==0.3.0
llama-index-core==0.11.4
Expand Down
7 changes: 4 additions & 3 deletions src/memary/agent/base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,20 @@ class Agent(object):

def __init__(
self,
name,
agent_name,
memory_stream_json,
entity_knowledge_store_json,
system_persona_txt,
user_persona_txt,
past_chat_json,
user_id='falkor',
llm_model_name="llama3",
vision_model_name="llava",
include_from_defaults=["search", "locate", "vision", "stocks"],
debug=True,
):
load_dotenv()
self.name = name
self.name = agent_name
self.model = llm_model_name

googlemaps_api_key = os.getenv("GOOGLEMAPS_API_KEY")
Expand All @@ -83,7 +84,7 @@ def __init__(
if self.falkordb_url is not None:
from llama_index.graph_stores.falkordb import FalkorDBGraphStore
# initialize FalkorDB graph resources
self.graph_store = FalkorDBGraphStore(self.falkordb_url, decode_responses=True)
self.graph_store = FalkorDBGraphStore(self.falkordb_url, database=user_id, decode_responses=True)
galshubeli marked this conversation as resolved.
Show resolved Hide resolved
else:
from llama_index.graph_stores.neo4j import Neo4jGraphStore
# Neo4j credentials
Expand Down
6 changes: 4 additions & 2 deletions src/memary/agent/chat_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,25 @@ class ChatAgent(Agent):

def __init__(
self,
name,
agent_name,
memory_stream_json,
entity_knowledge_store_json,
system_persona_txt,
user_persona_txt,
past_chat_json,
user_id='falkor',
llm_model_name="llama3",
vision_model_name="llava",
include_from_defaults=["search", "locate", "vision", "stocks"],
):
super().__init__(
name,
agent_name,
memory_stream_json,
entity_knowledge_store_json,
system_persona_txt,
user_persona_txt,
past_chat_json,
user_id,
llm_model_name,
vision_model_name,
include_from_defaults,
Expand Down
29 changes: 18 additions & 11 deletions streamlit_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,11 @@
from memary.agent.chat_agent import ChatAgent

load_dotenv()

system_persona_txt = "data/system_persona.txt"
user_persona_txt = "data/user_persona.txt"
past_chat_json = "data/past_chat.json"
memory_stream_json = "data/memory_stream.json"
entity_knowledge_store_json = "data/entity_knowledge_store.json"
chat_agent = ChatAgent(
"Personal Agent",
memory_stream_json,
entity_knowledge_store_json,
system_persona_txt,
user_persona_txt,
past_chat_json,
)


def create_graph(nodes, edges):
g = Network(
Expand Down Expand Up @@ -69,7 +59,7 @@ def fill_graph(nodes, edges, cypher_query):

if chat_agent.falkordb_url is not None:
falkordb = FalkorDB.from_url(chat_agent.falkordb_url)
session = falkordb.select_graph('falkor')
session = falkordb.select_graph(user_id)
result = session.query(cypher_query).result_set
for record in result:
path = record[0]
Expand Down Expand Up @@ -117,7 +107,23 @@ def get_models(llm_models, vision_models):
answer = ""
external_response = ""
st.title("memary")
# Create a two column layout (HTML table)
col1, col2 = st.columns([3, 1], vertical_alignment="bottom")

# Create a text input field for user ID
with col1:
user_id = st.text_input(
"Enter a user ID (Available only with FalkorDB)",
)
# Create a button to apply the switch user ID
with col2:
st.write("")
submit = st.button("Switch User ID")
galshubeli marked this conversation as resolved.
Show resolved Hide resolved

# If the user ID is empty, set it to "falkor"
if len(user_id) == 0:
user_id = "falkor"

llm_models = ["gpt-3.5-turbo"]
vision_models = ["gpt-4-vision-preview"]
get_models(llm_models, vision_models)
Expand All @@ -143,6 +149,7 @@ def get_models(llm_models, vision_models):
system_persona_txt,
user_persona_txt,
past_chat_json,
user_id,
selected_llm_model,
selected_vision_model,
)
Expand Down