-
Notifications
You must be signed in to change notification settings - Fork 12
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
1 parent
e312f00
commit dd57c52
Showing
4 changed files
with
120 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ poetry.lock | |
README.md | ||
.github | ||
Makefile | ||
.gitignore |
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 |
---|---|---|
|
@@ -2,3 +2,8 @@ dist/ | |
.mypy_cache/ | ||
__pycache__/ | ||
poetry.toml | ||
.idea/ | ||
.vscode/ | ||
*.env | ||
.venv/ | ||
venv/ |
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,99 @@ | ||
""" | ||
Example of using the Zep Python SDK asynchronously with Graph functionality. | ||
This script demonstrates the following functionality: | ||
- Creating a group. | ||
- Updating a group. | ||
- Adding episodes to the group (text and JSON). | ||
- Retrieving nodes from the group. | ||
- Retrieving edges from the group. | ||
- Searching the group for specific content. | ||
The script showcases various operations using the Zep Graph API, including | ||
group management, adding different types of episodes, and querying the graph structure. | ||
""" | ||
|
||
# ... rest of the file remains unchanged ... | ||
|
||
import asyncio | ||
import os | ||
import uuid | ||
|
||
from dotenv import find_dotenv, load_dotenv | ||
|
||
from zep_cloud.client import AsyncZep | ||
|
||
load_dotenv( | ||
dotenv_path=find_dotenv() | ||
) # load environment variables from .env file, if present | ||
|
||
API_KEY = os.environ.get("ZEP_API_KEY") or "YOUR_API_KEY" | ||
|
||
|
||
async def main() -> None: | ||
client = AsyncZep( | ||
api_key=API_KEY, | ||
) | ||
|
||
group_id = uuid.uuid4().hex | ||
print(f"Creating group {group_id}...") | ||
group = await client.group.add( | ||
group_id=group_id, | ||
name="My Group", | ||
description="This is my group", | ||
) | ||
print(f"Group {group_id} created {group}") | ||
|
||
print(f"Updating group {group_id}...") | ||
group = await client.group.update( | ||
group_id=group_id, | ||
name="My Group 2", | ||
description="This is my group 2", | ||
) | ||
print(f"Group {group_id} updated {group}") | ||
|
||
print(f"Adding episode to group {group_id}...") | ||
await client.graph.add( | ||
group_id=group_id, | ||
text="This is a test episode", | ||
) | ||
|
||
print(f"Adding more meaningful episode to group {group_id}...") | ||
await client.graph.add( | ||
group_id=group_id, | ||
text="Eric Clapton is a rock star", | ||
) | ||
|
||
print(f"Adding a JSON episode to group {group_id}...") | ||
json_string = '{"name": "Eric Clapton", "age": 78, "genre": "Rock"}' | ||
await client.graph.add( | ||
group_id=group_id, | ||
json=json_string, | ||
) | ||
await asyncio.sleep(10) | ||
|
||
# TODO: Need to enable non-message episodic content retrieval | ||
# print(f"Getting episodes from group {group_id}...") | ||
# results = await client.graph.episode.get_by_group_id(group_id, lastn=2) | ||
# print(f"Episodes from group {group_id} {results.episodes}") | ||
# episode = await client.graph.episode.get_by_uuid(results.episodes[0].uuid_) | ||
# print(f"Episode {episode.uuid_} from group {group_id} {episode}") | ||
|
||
print(f"Getting nodes from group {group_id}...") | ||
nodes = await client.graph.node.get_by_group_id(group_id) | ||
print(f"Nodes from group {group_id} {nodes}") | ||
|
||
print(f"Getting edges from group {group_id}...") | ||
edges = await client.graph.edge.get_by_group_id(group_id) | ||
print(f"Edges from group {group_id} {edges}") | ||
|
||
print(f"Searching group {group_id}...") | ||
search_results = await client.graph.search( | ||
group_id == group_id, | ||
query="Eric Clapton", | ||
) | ||
print(f"Search results from group {group_id} {search_results}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
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