Skip to content
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

Add end session method #71

Merged
merged 10 commits into from
May 14, 2024
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ Zep: Long-Term Memory for ‍AI Assistants.
<br />

<p align="center">
<a href="https://docs.getzep.com/deployment/quickstart/">Quick Start</a> |
<a href="https://docs.getzep.com/">Documentation</a> |
<a href="https://docs.getzep.com/sdk/langchain/">LangChain</a> and
<a href="https://docs.getzep.com/sdk/langchain/">LlamaIndex</a> Support |
<a href="https://help.getzep.com">Documentation</a> |
<a href="https://help.getzep.com/langchain/overview">LangChain</a> |
<a href="https://discord.gg/W8Kw6bsgXQ">Discord</a><br />
<a href="https://www.getzep.com">www.getzep.com</a>
</p>
Expand Down
12 changes: 9 additions & 3 deletions examples/memory/memory_example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async function main() {

const client = new ZepClient({
apiKey: projectApiKey,
environment: "https://api.development.getzep.com/api/v2",
});

// Create a user
Expand Down Expand Up @@ -58,11 +59,16 @@ async function main() {
// Add memory. We could do this in a batch, but we'll do it one by one rather to
// ensure that summaries and other artifacts are generated correctly.
try {
const messages = [];
for (const { role, role_type, content } of history) {
await client.memory.add(sessionID, {
messages: [{ role, roleType: role_type, content }],
});
messages.push({ role, roleType: role_type, content });
}
await client.memory.add(sessionID, {
messages: messages,
factInstruction:
"Extract only the brand, model, size and budget for the specific show being purchased.\n" +
'- Your fact answer should be in the format: "- Brand: Nike, Model: Air Zoom Pegasus 38, Size: 5, Budget: $80`',
});
console.debug("Added new memory for session ", sessionID);
} catch (error) {
console.debug("Got error:", error);
Expand Down
26 changes: 13 additions & 13 deletions src/api/resources/document/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Document {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -139,7 +139,7 @@ export class Document {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -252,7 +252,7 @@ export class Document {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -366,7 +366,7 @@ export class Document {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -479,7 +479,7 @@ export class Document {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -594,7 +594,7 @@ export class Document {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -699,7 +699,7 @@ export class Document {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -804,7 +804,7 @@ export class Document {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -909,7 +909,7 @@ export class Document {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -1014,7 +1014,7 @@ export class Document {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -1117,7 +1117,7 @@ export class Document {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -1232,7 +1232,7 @@ export class Document {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -1351,7 +1351,7 @@ export class Document {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down
122 changes: 107 additions & 15 deletions src/api/resources/memory/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class Memory {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -160,7 +160,7 @@ export class Memory {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -247,7 +247,7 @@ export class Memory {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -341,7 +341,7 @@ export class Memory {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -446,7 +446,7 @@ export class Memory {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -511,6 +511,98 @@ export class Memory {
}
}

/**
* End a session by ID
*
* @param {string} sessionId - Session ID
* @param {Zep.EndSessionRequest} request
* @param {Memory.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Zep.NotFoundError}
* @throws {@link Zep.InternalServerError}
*
* @example
* await zep.memory.endSession("sessionId")
*/
public async endSession(
sessionId: string,
request: Zep.EndSessionRequest = {},
requestOptions?: Memory.RequestOptions
): Promise<Zep.Session> {
const _response = await (this._options.fetcher ?? core.fetcher)({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.ZepEnvironment.Default,
`sessions/${encodeURIComponent(sessionId)}/end`
),
method: "POST",
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
},
contentType: "application/json",
body: await serializers.EndSessionRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
});
if (_response.ok) {
return await serializers.Session.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
});
}

if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 404:
throw new Zep.NotFoundError(
await serializers.ApiError.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
})
);
case 500:
throw new Zep.InternalServerError(
await serializers.ApiError.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
})
);
default:
throw new errors.ZepError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}

switch (_response.error.reason) {
case "non-json":
throw new errors.ZepError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ZepTimeoutError();
case "unknown":
throw new errors.ZepError({
message: _response.error.errorMessage,
});
}
}

/**
* extract data from a session by session id
*
Expand Down Expand Up @@ -540,7 +632,7 @@ export class Memory {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -642,7 +734,7 @@ export class Memory {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -735,7 +827,7 @@ export class Memory {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -812,7 +904,7 @@ export class Memory {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -913,7 +1005,7 @@ export class Memory {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -1005,7 +1097,7 @@ export class Memory {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -1100,7 +1192,7 @@ export class Memory {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -1200,7 +1292,7 @@ export class Memory {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -1291,7 +1383,7 @@ export class Memory {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down Expand Up @@ -1388,7 +1480,7 @@ export class Memory {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down
Loading
Loading