Skip to content

Commit

Permalink
remove experimental and deps
Browse files Browse the repository at this point in the history
  • Loading branch information
danielchalef committed Oct 5, 2023
1 parent bf5dfbe commit 0656fc9
Show file tree
Hide file tree
Showing 4 changed files with 466 additions and 2,137 deletions.
37 changes: 25 additions & 12 deletions examples/user_example.py
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",
Expand All @@ -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]",
Expand All @@ -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:
Expand All @@ -63,4 +76,4 @@ def main() -> None:


if __name__ == "__main__":
main()
asyncio.run(main())
Loading

0 comments on commit 0656fc9

Please sign in to comment.