-
Notifications
You must be signed in to change notification settings - Fork 11
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
bf5dfbe
commit 0656fc9
Showing
4 changed files
with
466 additions
and
2,137 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 |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import uuid | ||
|
||
from zep_python import APIError, ZepClient | ||
import asyncio | ||
from zep_python import APIError, ZepClient, Session | ||
from zep_python.user import CreateUserRequest, UpdateUserRequest | ||
|
||
|
||
def main() -> None: | ||
async def main() -> None: | ||
base_url = "http://localhost:8000" # TODO: Replace with Zep API URL | ||
api_key = "YOUR_API_KEY" # TODO: Replace with your API key | ||
|
||
with ZepClient(base_url, api_key) as client: | ||
# Create multiple users | ||
for i in range(3): | ||
user_id = uuid.uuid4().hex | ||
user_id = f"user{i}"+uuid.uuid4().hex | ||
user_request = CreateUserRequest( | ||
user_id=user_id, | ||
email=f"user{i}@example.com", | ||
|
@@ -20,13 +21,14 @@ def main() -> None: | |
metadata={"foo": "bar"}, | ||
) | ||
try: | ||
user = client.user.add(user_request) | ||
user = await client.user.aadd(user_request) | ||
print(f"Created user {i+1}: {user.user_id}") | ||
except APIError as e: | ||
print(f"Failed to create user {i+1}: {e}") | ||
|
||
# Update the first user | ||
user_id = client.user.list()[0].user_id | ||
user_list = await client.user.alist(1) | ||
user_id = user_list[0].user_id | ||
user_request = UpdateUserRequest( | ||
user_id=user_id, | ||
email="[email protected]", | ||
|
@@ -35,25 +37,36 @@ def main() -> None: | |
metadata={"foo": "updated_bar"}, | ||
) | ||
try: | ||
updated_user = client.user.update(user_request) | ||
updated_user = await client.user.aupdate(user_request) | ||
print(f"Updated user: {updated_user.user_id}") | ||
except APIError as e: | ||
print(f"Failed to update user: {e}") | ||
|
||
# Create a Session for the first user | ||
session_id = uuid.uuid4().hex | ||
session = Session( | ||
session_id=session_id, user_id=user_id, metadata={"session": i + 1} | ||
) | ||
try: | ||
result = await client.memory.aadd_session(session) | ||
print(f"Created session {i+1}: {result}") | ||
except APIError as e: | ||
print(f"Failed to create session {i+1}: {e}") | ||
|
||
# Delete the second user | ||
user_id = client.user.list()[1].user_id | ||
user_list = await client.user.alist(1, 1) | ||
user_id = user_list[0].user_id | ||
try: | ||
client.user.delete(user_id) | ||
await client.user.adelete(user_id) | ||
print(f"Deleted user: {user_id}") | ||
except APIError as e: | ||
print(f"Failed to delete user: {e}") | ||
|
||
# List all users | ||
try: | ||
users_generator = client.user.list_chunked() | ||
users_generator = client.user.alist_chunked() | ||
print("All users:") | ||
while True: | ||
users = next(users_generator, None) | ||
async for users in users_generator: | ||
if users is None: | ||
break | ||
for user in users: | ||
|
@@ -63,4 +76,4 @@ def main() -> None: | |
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
asyncio.run(main()) |
Oops, something went wrong.