Skip to content

Commit ee2f7c0

Browse files
Merge remote-tracking branch 'origin/main'
2 parents 94d84f9 + 194aaad commit ee2f7c0

142 files changed

Lines changed: 10907 additions & 13087 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.fernignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
src/zep_cloud/client.py
33
src/zep_cloud/graph/utils.py
44
src/zep_cloud/external_clients/
5-
src/zep_cloud/extractor/
65
examples/
7-
src/zep_cloud/langchain/
86
pyproject.toml
97
poetry.lock
108
README.md

.github/workflows/release-cloud.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ env:
1010
jobs:
1111
release:
1212
runs-on: ubuntu-latest
13-
if: github.event.release.target_commitish == 'main'
13+
if: github.event.release.target_commitish == 'main' || github.event.release.target_commitish == 'v3'
1414
permissions:
1515
id-token: write
1616
contents: write

examples/chat_history/chat_history_shoe_purchase.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
history = [
22
{
3-
"role": "Jane",
4-
"role_type": "user",
3+
"name": "Jane",
4+
"role": "user",
55
"content": (
66
"Hi there, I'm looking for a new pair of shoes. I'm not sure where"
77
" to start."
88
),
99
},
1010
{
11+
"name": "assistant",
1112
"role": "assistant",
12-
"role_type": "assistant",
1313
"content": (
1414
"Hello! I'd be happy to help you find the perfect pair of shoes. To"
1515
" get started, could you tell me what brand you're interested in,"
1616
" or if you're open to any brand?"
1717
),
1818
},
1919
{
20-
"role": "Jane",
21-
"role_type": "user",
20+
"name": "Jane",
21+
"role": "user",
2222
"content": "I like Nike and Adidas, but I'm open to other brands too.",
2323
},
2424
{
25+
"name": "assistant",
2526
"role": "assistant",
26-
"role_type": "assistant",
2727
"content": (
2828
"That's great! It's important to find the right shoe for your"
2929
" needs. Could you tell me what you'll be using these shoes for"
@@ -32,43 +32,43 @@
3232
),
3333
},
3434
{
35-
"role": "Jane",
36-
"role_type": "user",
35+
"name": "Jane",
36+
"role": "user",
3737
"content": "I'll be using them for running.",
3838
},
3939
{
40+
"name": "assistant",
4041
"role": "assistant",
41-
"role_type": "assistant",
4242
"content": (
4343
"Fantastic! Now, could you please provide me with your shoe size"
4444
" and foot width? This information will help me narrow down the"
4545
" options for you."
4646
),
4747
},
4848
{
49-
"role": "Jane",
50-
"role_type": "user",
49+
"name": "Jane",
50+
"role": "user",
5151
"content": ("I wear a men's size 10, and I'm not sure about the foot width."),
5252
},
5353
{
54+
"name": "assistant",
5455
"role": "assistant",
55-
"role_type": "assistant",
5656
"content": (
5757
"Thank you. Based on your size, I'll make sure to suggest shoes"
5858
" with a wide range of sizes and widths available."
5959
),
6060
},
6161
{
62-
"role": "Jane",
63-
"role_type": "user",
62+
"name": "Jane",
63+
"role": "user",
6464
"content": (
6565
"I have a bit of a pronation issue. Do I need to consider that"
6666
" while choosing shoes?"
6767
),
6868
},
6969
{
70+
"name": "assistant",
7071
"role": "assistant",
71-
"role_type": "assistant",
7272
"content": (
7373
"Yes, pronation is essential when choosing running shoes. It refers"
7474
" to the way your foot rolls inward or outward when you walk or"
@@ -78,22 +78,22 @@
7878
),
7979
},
8080
{
81-
"role": "Jane",
82-
"role_type": "user",
81+
"name": "Jane",
82+
"role": "user",
8383
"content": "Great, I have a budget of around $120.",
8484
},
8585
{
86+
"name": "assistant",
8687
"role": "assistant",
87-
"role_type": "assistant",
8888
"content": (
8989
"Perfect! I'll make sure to find the best running shoes that fit"
9090
" your preferences, taking into account your brand preferences,"
9191
" running needs, size, and budget."
9292
),
9393
},
9494
{
95+
"name": "assistant",
9596
"role": "assistant",
96-
"role_type": "assistant",
9797
"content": (
9898
"I've found a few great options for you. The first one is the"
9999
" Brooks Ghost 14, which is known for its cushioning and support,"
@@ -103,16 +103,16 @@
103103
"metadata": {"bar": "foo"},
104104
},
105105
{
106-
"role": "Jane",
107-
"role_type": "user",
106+
"name": "Jane",
107+
"role": "user",
108108
"content": (
109109
"I've heard good things about Brooks, but I was kind of hoping to"
110110
" get a Nike or an Adidas shoe."
111111
),
112112
},
113113
{
114+
"name": "assistant",
114115
"role": "assistant",
115-
"role_type": "assistant",
116116
"content": (
117117
"I understand. In that case, I'd recommend the Adidas Ultraboost"
118118
" 21. It's a popular choice among runners for its comfort, energy"
@@ -121,13 +121,13 @@
121121
),
122122
},
123123
{
124-
"role": "Jane",
125-
"role_type": "user",
124+
"name": "Jane",
125+
"role": "user",
126126
"content": "They're nice looking. Yes, I think I'll go with those.",
127127
},
128128
{
129+
"name": "assistant",
129130
"role": "assistant",
130-
"role_type": "assistant",
131131
"content": (
132132
"Excellent choice! To complete the purchase, I'll need you to"
133133
" provide your credit card information in our secure payment form."

examples/chat_history/memory.py

Lines changed: 22 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
44
This script demonstrates the following functionality:
55
- Creating a user.
6-
- Creating a session associated with the created user.
7-
- Adding messages to the session.
8-
- Searching the session memory for a specific query.
9-
- Searching the session memory with MMR reranking.
10-
- Searching the session memory with a metadata filter.
11-
- optionally deleting the session.
6+
- Creating a thread associated with the created user.
7+
- Adding messages to the thread.
8+
- Searching the thread memory for a specific query.
9+
- Searching the thread memory with MMR reranking.
10+
- optionally deleting the thread.
1211
"""
1312

1413
import asyncio
@@ -50,74 +49,40 @@ async def main() -> None:
5049
email="user@example.com",
5150
first_name="Jane",
5251
last_name="Smith",
53-
metadata={"vip": "true"},
5452
)
5553

56-
# await asyncio.sleep(1)
5754
print(f"User added: {user_id}")
58-
session_id = uuid.uuid4().hex # unique session id. can be any alphanum string
55+
thread_id = uuid.uuid4().hex # unique thread id. can be any alphanum string
5956

60-
# Create session associated with the above user
61-
print(f"\n---Creating session: {session_id}")
57+
# Create thread associated with the above user
58+
print(f"\n---Creating thread: {thread_id}")
6259

63-
await client.memory.add_session(
64-
session_id=session_id,
60+
await client.thread.create(
61+
thread_id=thread_id,
6562
user_id=user_id,
66-
metadata={"foo": "bar"},
6763
)
68-
# await asyncio.sleep(1)
69-
# Update session metadata
70-
print(f"\n---Updating session: {session_id}")
71-
await client.memory.update_session(session_id=session_id, metadata={"bar": "foo"})
72-
# await asyncio.sleep(3)
73-
# Get session
74-
print(f"\n---Getting session: {session_id}")
75-
session = await client.memory.get_session(session_id)
76-
print(f"Session details: {session}")
77-
# await asyncio.sleep(3)
78-
79-
# Add Memory for session
80-
print(f"\n---Add Memory for Session: {session_id}")
64+
65+
print(f"\n---Getting thread: {thread_id}")
66+
thread = await client.thread.get(thread_id)
67+
print(f"thread details: {thread}")
68+
69+
print(f"\n---Add messages to the thread: {thread_id}")
8170
for m in history:
8271
print(f"{m['role']}: {m['content']}")
83-
await client.memory.add(session_id=session_id, messages=[Message(**m)])
72+
await client.thread.add_messages(thread_id=thread_id, messages=[Message(**m)])
8473
# await asyncio.sleep(0.5)
8574

8675
# Wait for the messages to be processed
8776
await asyncio.sleep(50)
8877

89-
# Synthesize a question from most recent messages.
90-
# Useful for RAG apps. This is faster than using an LLM chain.
91-
print("\n---Synthesize a question from most recent messages")
92-
question = await client.memory.synthesize_question(session_id, last_n_messages=3)
93-
print(f"Question: {question}")
94-
95-
# Classify the session.
96-
# Useful for semantic routing, filtering, and many other use cases.
97-
print("\n---Classify the session")
98-
classes = [
99-
"low spender <$50",
100-
"medium spender >=$50, <$100",
101-
"high spender >=$100",
102-
"unknown",
103-
]
104-
classification = await client.memory.classify_session(
105-
session_id, name="spender_category", classes=classes, persist=True
106-
)
107-
print(f"Classification: {classification}")
108-
109-
# Get Memory for session
110-
print(f"\n---Get Perpetual Memory for Session: {session_id}")
111-
memory = await client.memory.get(session_id)
112-
print(f"Memory: {memory}")
113-
print("\n---End of Memory")
11478

115-
print(f"Memory context: {memory.context}")
79+
print(f"\n---Get user context for thread: {thread_id}")
80+
memory = await client.thread.get_user_context(thread_id)
81+
print(f"Context: {memory.context}")
11682

117-
# Delete Memory for session
83+
# Delete thread and wipe thread memory
11884
# Uncomment to run
119-
# print(f"\n6---deleteMemory for Session: {session_id}")
120-
# await client.memory.delete(session_id)
85+
# await client.thread.delete(thread_id)
12186

12287

12388
if __name__ == "__main__":
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
"""
2+
Example of using the Zep Python SDK asynchronously with Graph functionality.
3+
4+
This script demonstrates the following functionality:
5+
- Creating a graph.
6+
- Updating a graph.
7+
- Adding episodes to the graph (text and JSON).
8+
- Retrieving nodes from the graph.
9+
- Retrieving edges from the graph.
10+
- Searching the graph for specific content.
11+
12+
The script showcases various operations using the Zep Graph API, including
13+
graph management, adding different types of episodes, and querying the graph structure.
14+
"""
15+
16+
import asyncio
17+
import os
18+
import uuid
19+
20+
from dotenv import find_dotenv, load_dotenv
21+
22+
from zep_cloud.client import AsyncZep
23+
24+
load_dotenv(
25+
dotenv_path=find_dotenv()
26+
) # load environment variables from .env file, if present
27+
28+
API_KEY = os.environ.get("ZEP_API_KEY") or "YOUR_API_KEY"
29+
30+
31+
async def main() -> None:
32+
client = AsyncZep(
33+
api_key=API_KEY,
34+
)
35+
36+
graph_id = f"slack:{uuid.uuid4().hex}"
37+
print(f"Creating graph {graph_id}...")
38+
graph = await client.graph.create(
39+
graph_id=graph_id,
40+
name="My Graph",
41+
description="This is my graph",
42+
)
43+
await asyncio.sleep(2)
44+
print(f"graph {graph_id} created {graph}")
45+
46+
print(f"Adding episode to graph {graph_id}...")
47+
await client.graph.add(
48+
graph_id=graph_id,
49+
data="This is a test episode",
50+
type="text",
51+
)
52+
await asyncio.sleep(2)
53+
print(f"Adding more meaningful episode to graph {graph_id}...")
54+
await client.graph.add(
55+
graph_id=graph_id,
56+
data="Eric Clapton is a rock star",
57+
type="text",
58+
)
59+
await asyncio.sleep(2)
60+
print(f"Adding a JSON episode to graph {graph_id}...")
61+
json_string = '{"name": "Eric Clapton", "age": 78, "genre": "Rock"}'
62+
await client.graph.add(
63+
graph_id=graph_id,
64+
data=json_string,
65+
type="json",
66+
)
67+
await asyncio.sleep(20)
68+
69+
# TODO: Need to enable non-message episodic content retrieval
70+
print(f"Getting episodes from graph {graph_id}...")
71+
results = await client.graph.episode.get_by_graph_id(graph_id, lastn=2)
72+
await asyncio.sleep(2)
73+
print(f"Episodes from graph {graph_id} {results.episodes}")
74+
episode = await client.graph.episode.get(results.episodes[0].uuid_)
75+
await asyncio.sleep(2)
76+
print(f"Episode {episode.uuid_} from graph {graph_id} {episode}")
77+
78+
print(f"Getting nodes from graph {graph_id}...")
79+
nodes = await client.graph.node.get_by_graph_id(graph_id)
80+
await asyncio.sleep(2)
81+
print(f"Nodes from graph {graph_id} {nodes}")
82+
83+
print(f"Getting edges from graph {graph_id}...")
84+
edges = await client.graph.edge.get_by_graph_id(graph_id)
85+
await asyncio.sleep(2)
86+
print(f"Edges from graph {graph_id} {edges}")
87+
88+
print(f"Searching graph {graph_id}...")
89+
search_results = await client.graph.search(
90+
graph_id=graph_id,
91+
query="Eric Clapton",
92+
)
93+
await asyncio.sleep(2)
94+
print(f"Search results from graph {graph_id} {search_results}")
95+
96+
# await client.graph.delete(graph_id)
97+
# print(f"graph {graph_id} deleted")
98+
99+
100+
if __name__ == "__main__":
101+
asyncio.run(main())

0 commit comments

Comments
 (0)