-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from getzep/feat/users
feat/users
- Loading branch information
Showing
18 changed files
with
840 additions
and
90 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,3 +1,4 @@ | ||
.idea | ||
# Logs | ||
logs | ||
*.log | ||
|
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,4 +1,6 @@ | ||
import { v4 as uuidv4 } from "uuid"; | ||
import { | ||
ICreateUserRequest, | ||
ISession, | ||
Memory, | ||
MemorySearchPayload, | ||
|
@@ -10,28 +12,39 @@ import { | |
|
||
import { history } from "./history"; | ||
|
||
import { v4 as uuidv4 } from "uuid"; | ||
function sleep(ms: number) { | ||
const date = Date.now(); | ||
let currentDate = 0; | ||
do { | ||
currentDate = Date.now(); | ||
} while (currentDate - date < ms); | ||
} | ||
|
||
async function main() { | ||
const baseURL = "http://localhost:8000"; // Replace with Zep API URL | ||
const client = await ZepClient.init(baseURL); | ||
|
||
// Create a user | ||
const userId = uuidv4(); | ||
const userRequest: ICreateUserRequest = { | ||
user_id: userId, | ||
metadata: { foo: "bar" }, | ||
email: "[email protected]", | ||
first_name: "A", | ||
last_name: "User", | ||
}; | ||
const user = await client.user.add(userRequest); | ||
console.debug("Created user ", user.toDict()); | ||
|
||
// Example session ID | ||
let sessionID = uuidv4(); | ||
|
||
function sleep(ms: number) { | ||
const date = Date.now(); | ||
let currentDate = 0; | ||
do { | ||
currentDate = Date.now(); | ||
} while (currentDate - date < ms); | ||
} | ||
const sessionID = uuidv4(); | ||
|
||
// Add session | ||
// Add session associated with the above user | ||
try { | ||
const sessionData: ISession = { | ||
session_id: sessionID, | ||
metadata: { foo: "bar" }, | ||
user_id: user.user_id, | ||
}; | ||
const session = new Session(sessionData); | ||
|
||
|
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,72 @@ | ||
import { v4 as uuidv4 } from "uuid"; | ||
import { | ||
ICreateUserRequest, | ||
IUpdateUserRequest, | ||
ZepClient, | ||
} from "../../src/index"; | ||
|
||
async function main() { | ||
const BASE_URL = "http://localhost:8000"; // TODO: Replace with Zep API URL | ||
// const API_KEY = "YOUR_API_KEY"; // TODO: Replace with your API key | ||
|
||
const client = await ZepClient.init(BASE_URL, API_KEY); | ||
|
||
// Create multiple users | ||
for (let i = 0; i < 3; i++) { | ||
const userId = uuidv4(); | ||
const userRequest: ICreateUserRequest = { | ||
user_id: userId, | ||
email: `user${i}@example.com`, | ||
first_name: `John${i}`, | ||
last_name: `Doe${i}`, | ||
metadata: { foo: "bar" }, | ||
}; | ||
|
||
try { | ||
const user = await client.user.add(userRequest); | ||
console.log(`Created user ${i + 1}: ${user.user_id}`); | ||
} catch (e) { | ||
console.log(`Failed to create user ${i + 1}: ${e}`); | ||
} | ||
} | ||
|
||
// Update the first user | ||
const { user_id } = (await client.user.list())[0]; | ||
const userRequest: IUpdateUserRequest = { | ||
user_id, | ||
email: "[email protected]", | ||
first_name: "UpdatedJohn", | ||
last_name: "UpdatedDoe", | ||
metadata: { foo: "updated_bar" }, | ||
}; | ||
|
||
try { | ||
const updatedUser = await client.user.update(userRequest); | ||
console.log(`Updated user: ${updatedUser.user_id}`); | ||
} catch (e) { | ||
console.log(`Failed to update user: ${e}`); | ||
} | ||
|
||
// Delete the second user | ||
const userIdToDelete = (await client.user.list())[1].user_id; | ||
try { | ||
await client.user.delete(userIdToDelete); | ||
console.log(`Deleted user: ${userIdToDelete}`); | ||
} catch (e) { | ||
console.log(`Failed to delete user: ${e}`); | ||
} | ||
|
||
// List all users | ||
try { | ||
console.log("All users:"); | ||
for await (const users of client.user.listChunked()) { | ||
for (const user of users) { | ||
console.log(user.user_id); | ||
} | ||
} | ||
} catch (e) { | ||
console.log(`Failed to list users: ${e}`); | ||
} | ||
} | ||
|
||
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
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
Oops, something went wrong.