@getzep/zep-cloud 2.16.0 → 2.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/contextString.d.ts +16 -0
- package/contextString.js +75 -0
- package/dist/contextString.d.ts +16 -0
- package/dist/contextString.js +75 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/index.d.ts +1 -0
- package/index.js +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EntityEdge, EntityNode } from "./api";
|
|
2
|
+
/**
|
|
3
|
+
* Format the date range of an entity edge.
|
|
4
|
+
*
|
|
5
|
+
* @param edge - The entity edge to format.
|
|
6
|
+
* @returns A string representation of the date range.
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatEdgeDateRange(edge: EntityEdge): string;
|
|
9
|
+
/**
|
|
10
|
+
* Compose a search context from entity edges and nodes.
|
|
11
|
+
*
|
|
12
|
+
* @param edges - List of entity edges.
|
|
13
|
+
* @param nodes - List of entity nodes.
|
|
14
|
+
* @returns A formatted string containing facts and entities.
|
|
15
|
+
*/
|
|
16
|
+
export declare function composeContextString(edges: EntityEdge[], nodes: EntityNode[]): string;
|
package/contextString.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatEdgeDateRange = formatEdgeDateRange;
|
|
4
|
+
exports.composeContextString = composeContextString;
|
|
5
|
+
const TEMPLATE_STRING = `
|
|
6
|
+
FACTS and ENTITIES represent relevant context to the current conversation.
|
|
7
|
+
|
|
8
|
+
# These are the most relevant facts and their valid date ranges
|
|
9
|
+
# format: FACT (Date range: from - to)
|
|
10
|
+
<FACTS>
|
|
11
|
+
%facts%
|
|
12
|
+
</FACTS>
|
|
13
|
+
|
|
14
|
+
# These are the most relevant entities
|
|
15
|
+
# ENTITY_NAME: entity summary
|
|
16
|
+
<ENTITIES>
|
|
17
|
+
%entities%
|
|
18
|
+
</ENTITIES>
|
|
19
|
+
`;
|
|
20
|
+
/**
|
|
21
|
+
* Format the date range of an entity edge.
|
|
22
|
+
*
|
|
23
|
+
* @param edge - The entity edge to format.
|
|
24
|
+
* @returns A string representation of the date range.
|
|
25
|
+
*/
|
|
26
|
+
function formatEdgeDateRange(edge) {
|
|
27
|
+
let validAt = "date unknown";
|
|
28
|
+
let invalidAt = "present";
|
|
29
|
+
if (edge.validAt) {
|
|
30
|
+
validAt = formatDate(new Date(edge.validAt));
|
|
31
|
+
}
|
|
32
|
+
if (edge.invalidAt) {
|
|
33
|
+
invalidAt = formatDate(new Date(edge.invalidAt));
|
|
34
|
+
}
|
|
35
|
+
return `${validAt} - ${invalidAt}`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Format a date according to the memory context format.
|
|
39
|
+
*
|
|
40
|
+
* @param date - The date to format.
|
|
41
|
+
* @returns A formatted date string.
|
|
42
|
+
*/
|
|
43
|
+
function formatDate(date) {
|
|
44
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
45
|
+
year: "numeric",
|
|
46
|
+
month: "2-digit",
|
|
47
|
+
day: "2-digit",
|
|
48
|
+
hour: "2-digit",
|
|
49
|
+
minute: "2-digit",
|
|
50
|
+
second: "2-digit",
|
|
51
|
+
hour12: false,
|
|
52
|
+
})
|
|
53
|
+
.format(date)
|
|
54
|
+
.replace(/\//g, "-")
|
|
55
|
+
.replace(",", "")
|
|
56
|
+
.replace(/^(\d{2})-(\d{2})-(\d{4})/, "$3-$1-$2");
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Compose a search context from entity edges and nodes.
|
|
60
|
+
*
|
|
61
|
+
* @param edges - List of entity edges.
|
|
62
|
+
* @param nodes - List of entity nodes.
|
|
63
|
+
* @returns A formatted string containing facts and entities.
|
|
64
|
+
*/
|
|
65
|
+
function composeContextString(edges, nodes) {
|
|
66
|
+
const facts = edges.map((edge) => {
|
|
67
|
+
return ` - ${edge.fact} (${formatEdgeDateRange(edge)})`;
|
|
68
|
+
});
|
|
69
|
+
const entities = nodes.map((node) => {
|
|
70
|
+
return ` - ${node.name}: ${node.summary}`;
|
|
71
|
+
});
|
|
72
|
+
const factsStr = facts.join("\n");
|
|
73
|
+
const entitiesStr = entities.join("\n");
|
|
74
|
+
return TEMPLATE_STRING.replace("%facts%", factsStr).replace("%entities%", entitiesStr);
|
|
75
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EntityEdge, EntityNode } from "./api";
|
|
2
|
+
/**
|
|
3
|
+
* Format the date range of an entity edge.
|
|
4
|
+
*
|
|
5
|
+
* @param edge - The entity edge to format.
|
|
6
|
+
* @returns A string representation of the date range.
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatEdgeDateRange(edge: EntityEdge): string;
|
|
9
|
+
/**
|
|
10
|
+
* Compose a search context from entity edges and nodes.
|
|
11
|
+
*
|
|
12
|
+
* @param edges - List of entity edges.
|
|
13
|
+
* @param nodes - List of entity nodes.
|
|
14
|
+
* @returns A formatted string containing facts and entities.
|
|
15
|
+
*/
|
|
16
|
+
export declare function composeContextString(edges: EntityEdge[], nodes: EntityNode[]): string;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatEdgeDateRange = formatEdgeDateRange;
|
|
4
|
+
exports.composeContextString = composeContextString;
|
|
5
|
+
const TEMPLATE_STRING = `
|
|
6
|
+
FACTS and ENTITIES represent relevant context to the current conversation.
|
|
7
|
+
|
|
8
|
+
# These are the most relevant facts and their valid date ranges
|
|
9
|
+
# format: FACT (Date range: from - to)
|
|
10
|
+
<FACTS>
|
|
11
|
+
%facts%
|
|
12
|
+
</FACTS>
|
|
13
|
+
|
|
14
|
+
# These are the most relevant entities
|
|
15
|
+
# ENTITY_NAME: entity summary
|
|
16
|
+
<ENTITIES>
|
|
17
|
+
%entities%
|
|
18
|
+
</ENTITIES>
|
|
19
|
+
`;
|
|
20
|
+
/**
|
|
21
|
+
* Format the date range of an entity edge.
|
|
22
|
+
*
|
|
23
|
+
* @param edge - The entity edge to format.
|
|
24
|
+
* @returns A string representation of the date range.
|
|
25
|
+
*/
|
|
26
|
+
function formatEdgeDateRange(edge) {
|
|
27
|
+
let validAt = "date unknown";
|
|
28
|
+
let invalidAt = "present";
|
|
29
|
+
if (edge.validAt) {
|
|
30
|
+
validAt = formatDate(new Date(edge.validAt));
|
|
31
|
+
}
|
|
32
|
+
if (edge.invalidAt) {
|
|
33
|
+
invalidAt = formatDate(new Date(edge.invalidAt));
|
|
34
|
+
}
|
|
35
|
+
return `${validAt} - ${invalidAt}`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Format a date according to the memory context format.
|
|
39
|
+
*
|
|
40
|
+
* @param date - The date to format.
|
|
41
|
+
* @returns A formatted date string.
|
|
42
|
+
*/
|
|
43
|
+
function formatDate(date) {
|
|
44
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
45
|
+
year: "numeric",
|
|
46
|
+
month: "2-digit",
|
|
47
|
+
day: "2-digit",
|
|
48
|
+
hour: "2-digit",
|
|
49
|
+
minute: "2-digit",
|
|
50
|
+
second: "2-digit",
|
|
51
|
+
hour12: false,
|
|
52
|
+
})
|
|
53
|
+
.format(date)
|
|
54
|
+
.replace(/\//g, "-")
|
|
55
|
+
.replace(",", "")
|
|
56
|
+
.replace(/^(\d{2})-(\d{2})-(\d{4})/, "$3-$1-$2");
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Compose a search context from entity edges and nodes.
|
|
60
|
+
*
|
|
61
|
+
* @param edges - List of entity edges.
|
|
62
|
+
* @param nodes - List of entity nodes.
|
|
63
|
+
* @returns A formatted string containing facts and entities.
|
|
64
|
+
*/
|
|
65
|
+
function composeContextString(edges, nodes) {
|
|
66
|
+
const facts = edges.map((edge) => {
|
|
67
|
+
return ` - ${edge.fact} (${formatEdgeDateRange(edge)})`;
|
|
68
|
+
});
|
|
69
|
+
const entities = nodes.map((node) => {
|
|
70
|
+
return ` - ${node.name}: ${node.summary}`;
|
|
71
|
+
});
|
|
72
|
+
const factsStr = facts.join("\n");
|
|
73
|
+
const entitiesStr = entities.join("\n");
|
|
74
|
+
return TEMPLATE_STRING.replace("%facts%", factsStr).replace("%entities%", entitiesStr);
|
|
75
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.zepFields = exports.ZepTimeoutError = exports.ZepError = exports.ZepEnvironment = exports.ZepClient = exports.Zep = void 0;
|
|
36
|
+
exports.composeContextString = exports.zepFields = exports.ZepTimeoutError = exports.ZepError = exports.ZepEnvironment = exports.ZepClient = exports.Zep = void 0;
|
|
37
37
|
exports.Zep = __importStar(require("./api"));
|
|
38
38
|
var wrapper_1 = require("./wrapper");
|
|
39
39
|
Object.defineProperty(exports, "ZepClient", { enumerable: true, get: function () { return wrapper_1.ZepClient; } });
|
|
@@ -44,3 +44,5 @@ Object.defineProperty(exports, "ZepError", { enumerable: true, get: function ()
|
|
|
44
44
|
Object.defineProperty(exports, "ZepTimeoutError", { enumerable: true, get: function () { return errors_1.ZepTimeoutError; } });
|
|
45
45
|
var extractor_1 = require("./extractor");
|
|
46
46
|
Object.defineProperty(exports, "zepFields", { enumerable: true, get: function () { return extractor_1.zepFields; } });
|
|
47
|
+
var contextString_1 = require("./contextString");
|
|
48
|
+
Object.defineProperty(exports, "composeContextString", { enumerable: true, get: function () { return contextString_1.composeContextString; } });
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.zepFields = exports.ZepTimeoutError = exports.ZepError = exports.ZepEnvironment = exports.ZepClient = exports.Zep = void 0;
|
|
36
|
+
exports.composeContextString = exports.zepFields = exports.ZepTimeoutError = exports.ZepError = exports.ZepEnvironment = exports.ZepClient = exports.Zep = void 0;
|
|
37
37
|
exports.Zep = __importStar(require("./api"));
|
|
38
38
|
var wrapper_1 = require("./wrapper");
|
|
39
39
|
Object.defineProperty(exports, "ZepClient", { enumerable: true, get: function () { return wrapper_1.ZepClient; } });
|
|
@@ -44,3 +44,5 @@ Object.defineProperty(exports, "ZepError", { enumerable: true, get: function ()
|
|
|
44
44
|
Object.defineProperty(exports, "ZepTimeoutError", { enumerable: true, get: function () { return errors_1.ZepTimeoutError; } });
|
|
45
45
|
var extractor_1 = require("./extractor");
|
|
46
46
|
Object.defineProperty(exports, "zepFields", { enumerable: true, get: function () { return extractor_1.zepFields; } });
|
|
47
|
+
var contextString_1 = require("./contextString");
|
|
48
|
+
Object.defineProperty(exports, "composeContextString", { enumerable: true, get: function () { return contextString_1.composeContextString; } });
|