-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New Components - zep #15616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - zep #15616
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
329d71c
zep init
michelle0927 5c1ebd6
remove components (documents endpoints deprecated)
michelle0927 af13d14
new components
michelle0927 b7b1cf2
pnpm-lock.yaml
michelle0927 889236e
updates
michelle0927 7e3a6bf
Merge remote-tracking branch 'origin/master' into issue-15601
michelle0927 cf7a805
make userId required
michelle0927 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -8,4 +8,4 @@ export default { | |
console.log(Object.keys(this.$auth)); | ||
}, | ||
}, | ||
}; | ||
}; |
This file contains hidden or 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,55 @@ | ||
import zep from "../../zep.app.mjs"; | ||
import utils from "../../common/utils.mjs"; | ||
|
||
export default { | ||
key: "zep-add-memory", | ||
name: "Add Memory to Session", | ||
description: "Adds memory to an existing session in Zep. [See the documentation](https://help.getzep.com/api-reference/memory/add)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
zep, | ||
sessionId: { | ||
propDefinition: [ | ||
zep, | ||
"sessionId", | ||
], | ||
}, | ||
messages: { | ||
type: "string[]", | ||
label: "Messages", | ||
description: "An array of message objects, where each message contains a role (`norole`, `system`, `assistant`, `user`, `function`, or `tool`) and content. Example: `[{ \"content\": \"content\", \"role_type\": \"norole\" }]` [See the documentation](https://help.getzep.com/api-reference/memory/add) for more information", | ||
}, | ||
factInstruction: { | ||
type: "string", | ||
label: "Fact Instruction", | ||
description: "Additional instruction for generating the facts", | ||
optional: true, | ||
}, | ||
returnContext: { | ||
type: "boolean", | ||
label: "Return Context", | ||
description: "Optionally return memory context relevant to the most recent messages", | ||
optional: true, | ||
}, | ||
summaryInstruction: { | ||
type: "string", | ||
label: "Summary Instructions", | ||
description: "Additional instruction for generating the summary", | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.zep.addMemoryToSession({ | ||
sessionId: this.sessionId, | ||
data: { | ||
messages: utils.parseArray(this.messages), | ||
factInstruction: this.factInstruction, | ||
returnContext: this.returnContext, | ||
summaryInstruction: this.summaryInstruction, | ||
}, | ||
}); | ||
$.export("$summary", `Added memory to session ${this.sessionId}`); | ||
return response; | ||
}, | ||
}; |
This file contains hidden or 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,64 @@ | ||
import zep from "../../zep.app.mjs"; | ||
import utils from "../../common/utils.mjs"; | ||
|
||
export default { | ||
key: "zep-add-user", | ||
name: "Add User", | ||
description: "Adds a user in Zep. [See the documentation](https://help.getzep.com/api-reference/user/add)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
zep, | ||
userId: { | ||
type: "string", | ||
label: "User ID", | ||
description: "The unique identifier of the new user", | ||
}, | ||
email: { | ||
type: "string", | ||
label: "Email", | ||
description: "Email address of the user", | ||
optional: true, | ||
}, | ||
firstName: { | ||
type: "string", | ||
label: "First Name", | ||
description: "First name of the new user", | ||
optional: true, | ||
}, | ||
lastName: { | ||
type: "string", | ||
label: "Last Name", | ||
description: "Last name of the new user", | ||
optional: true, | ||
}, | ||
factRatingInstructions: { | ||
propDefinition: [ | ||
zep, | ||
"factRatingInstructions", | ||
], | ||
}, | ||
metadata: { | ||
propDefinition: [ | ||
zep, | ||
"metadata", | ||
], | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.zep.createUser({ | ||
$, | ||
data: { | ||
email: this.email, | ||
first_name: this.firstName, | ||
last_name: this.lastName, | ||
fact_rating_instructions: utils.parseObject(this.factRatingInstructions), | ||
metadata: utils.parseObject(this.metadata), | ||
user_id: this.userId, | ||
}, | ||
}); | ||
$.export("$summary", `Successfully added user with ID: ${response.id}`); | ||
return response; | ||
}, | ||
}; |
This file contains hidden or 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,50 @@ | ||
import zep from "../../zep.app.mjs"; | ||
import utils from "../../common/utils.mjs"; | ||
|
||
export default { | ||
key: "zep-create-session", | ||
name: "Create Session", | ||
description: "Creates a new session in Zep. [See the documentation](https://help.getzep.com/api-reference/memory/add-session)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
zep, | ||
sessionId: { | ||
type: "string", | ||
label: "Session ID", | ||
description: "The unique identifier of the session", | ||
}, | ||
userId: { | ||
propDefinition: [ | ||
zep, | ||
"userId", | ||
], | ||
}, | ||
factRatingInstructions: { | ||
propDefinition: [ | ||
zep, | ||
"factRatingInstructions", | ||
], | ||
}, | ||
metadata: { | ||
propDefinition: [ | ||
zep, | ||
"metadata", | ||
], | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.zep.createSession({ | ||
$, | ||
data: { | ||
session_id: this.sessionId, | ||
user_id: this.userId, | ||
fact_rating_instructions: utils.parseObject(this.factRatingInstructions), | ||
metadata: utils.parseObject(this.metadata), | ||
}, | ||
}); | ||
$.export("$summary", `Created session with ID ${this.sessionId}`); | ||
return response; | ||
}, | ||
}; |
This file contains hidden or 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,44 @@ | ||
import zep from "../../zep.app.mjs"; | ||
import utils from "../../common/utils.mjs"; | ||
|
||
export default { | ||
key: "zep-update-session", | ||
name: "Update Session", | ||
description: "Updates an existing session in Zep. [See the documentation](https://help.getzep.com/api-reference/memory/update-session)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
zep, | ||
sessionId: { | ||
propDefinition: [ | ||
zep, | ||
"sessionId", | ||
], | ||
}, | ||
metadata: { | ||
propDefinition: [ | ||
zep, | ||
"metadata", | ||
], | ||
description: "An object of key/value pairs representing the metadata to add to the session", | ||
}, | ||
factRatingInstructions: { | ||
propDefinition: [ | ||
zep, | ||
"factRatingInstructions", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.zep.updateSession({ | ||
$, | ||
sessionId: this.sessionId, | ||
data: { | ||
fact_rating_instructions: utils.parseObject(this.factRatingInstructions), | ||
metadata: utils.parseObject(this.metadata), | ||
}, | ||
}); | ||
$.export("$summary", `Successfully updated ssession with ID ${this.sessionId}`); | ||
return response; | ||
}, | ||
}; |
This file contains hidden or 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,30 @@ | ||
function parseObject(obj) { | ||
if (!obj) { | ||
return undefined; | ||
} | ||
|
||
return typeof obj === "string" | ||
? JSON.parse(obj) | ||
: obj; | ||
} | ||
|
||
function parseArray(arr) { | ||
if (!arr) { | ||
return undefined; | ||
} | ||
|
||
if (typeof arr === "string") { | ||
return JSON.parse(arr); | ||
} | ||
|
||
if (Array.isArray(arr)) { | ||
return arr.map((item) => parseObject(item)); | ||
} | ||
|
||
return arr; | ||
} | ||
|
||
export default { | ||
parseObject, | ||
parseArray, | ||
}; |
This file contains hidden or 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,6 +1,6 @@ | ||
{ | ||
"name": "@pipedream/zep", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream Zep Components", | ||
"main": "zep.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.3" | ||
} | ||
} |
This file contains hidden or 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,80 @@ | ||
import zep from "../../zep.app.mjs"; | ||
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
|
||
export default { | ||
props: { | ||
zep, | ||
db: "$.service.db", | ||
timer: { | ||
type: "$.interface.timer", | ||
default: { | ||
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
_getLastTs() { | ||
return this.db.get("lastTs") || 0; | ||
}, | ||
_setLastTs(lastTs) { | ||
this.db.set("lastTs", lastTs); | ||
}, | ||
async processEvent(max) { | ||
const lastTs = this._getLastTs(); | ||
const results = await this.getNewResults(lastTs, max); | ||
results.forEach((item) => this.emitEvent(item)); | ||
}, | ||
async getSessions({ | ||
lastTs, orderBy, max, updateLastTs = true, | ||
}) { | ||
const params = { | ||
page_size: max || 1000, | ||
order_by: orderBy, | ||
asc: false, | ||
}; | ||
|
||
const { sessions: results } = await this.zep.listSessions({ | ||
params, | ||
}); | ||
|
||
const sessions = []; | ||
for (const session of results) { | ||
const ts = Date.parse(session[orderBy]); | ||
if (ts >= lastTs) { | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sessions.push(session); | ||
} else { | ||
break; | ||
} | ||
if (max && sessions.length >= max) { | ||
break; | ||
} | ||
} | ||
|
||
if (!sessions.length) { | ||
return []; | ||
} | ||
if (updateLastTs) { | ||
this._setLastTs(Date.parse(sessions[0][orderBy])); | ||
} | ||
return sessions.reverse(); | ||
}, | ||
emitEvent(item) { | ||
const meta = this.generateMeta(item); | ||
this.$emit(item, meta); | ||
}, | ||
getNewResults() { | ||
throw new Error("getNewResults is not implemented"); | ||
}, | ||
generateMeta() { | ||
throw new Error("generateMeta is not implemented"); | ||
}, | ||
}, | ||
hooks: { | ||
async deploy() { | ||
await this.processEvent(25); | ||
}, | ||
}, | ||
async run() { | ||
await this.processEvent(); | ||
}, | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.