llm-exe 1.0.2 → 2.0.0-beta.2
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/dist/embedding/openai.js +2 -4
- package/dist/embedding/openai.js.map +1 -1
- package/dist/executor/llm-openai-function.d.ts +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/chat.d.ts +9 -2
- package/dist/interfaces/openai.d.ts +2 -1
- package/dist/interfaces/prompt.d.ts +1 -0
- package/dist/llm/_base.d.ts +1 -1
- package/dist/llm/_base.js +2 -2
- package/dist/llm/_base.js.map +1 -1
- package/dist/llm/bedrock.d.ts +95 -0
- package/dist/llm/bedrock.js +194 -0
- package/dist/llm/bedrock.js.map +1 -0
- package/dist/llm/index.d.ts +1 -1
- package/dist/llm/index.js +2 -2
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/openai.d.ts +5 -4
- package/dist/llm/openai.js +25 -21
- package/dist/llm/openai.js.map +1 -1
- package/dist/parser/parsers/JsonParser.js +2 -1
- package/dist/parser/parsers/JsonParser.js.map +1 -1
- package/dist/prompt/_base.d.ts +2 -0
- package/dist/prompt/_base.js +11 -2
- package/dist/prompt/_base.js.map +1 -1
- package/dist/prompt/chat.d.ts +2 -2
- package/dist/prompt/chat.js +14 -5
- package/dist/prompt/chat.js.map +1 -1
- package/dist/state/dialogue.d.ts +2 -2
- package/dist/state/dialogue.js.map +1 -1
- package/dist/utils/const.d.ts +6 -4
- package/dist/utils/const.js +9 -7
- package/dist/utils/const.js.map +1 -1
- package/dist/utils/modules/handlebars/hbs.d.ts +1 -0
- package/dist/utils/modules/handlebars/hbs.js +28 -1
- package/dist/utils/modules/handlebars/hbs.js.map +1 -1
- package/dist/utils/modules/handlebars/helpers/index.js +7 -5
- package/dist/utils/modules/handlebars/helpers/index.js.map +1 -1
- package/dist/utils/modules/handlebars/index.d.ts +1 -1
- package/dist/utils/modules/handlebars/index.js +7 -7
- package/dist/utils/modules/handlebars/index.js.map +1 -1
- package/dist/utils/modules/handlebars/templates/index.js +2 -2
- package/dist/utils/modules/index.d.ts +1 -1
- package/dist/utils/modules/index.js +2 -1
- package/dist/utils/modules/index.js.map +1 -1
- package/dist/utils/modules/json.d.ts +1 -0
- package/dist/utils/modules/json.js +22 -2
- package/dist/utils/modules/json.js.map +1 -1
- package/dist/utils/modules/openai.js +2 -1
- package/dist/utils/modules/openai.js.map +1 -1
- package/dist/utils/modules/replaceTemplateString.d.ts +1 -0
- package/dist/utils/modules/replaceTemplateString.js +19 -3
- package/dist/utils/modules/replaceTemplateString.js.map +1 -1
- package/package.json +5 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isObjectStringified = exports.maybeParseJSON = exports.maybeStringifyJSON = void 0;
|
|
3
|
+
exports.helpJsonMarkup = exports.isObjectStringified = exports.maybeParseJSON = exports.maybeStringifyJSON = void 0;
|
|
4
4
|
const maybeStringifyJSON = (objOrMaybeString) => {
|
|
5
5
|
if (!objOrMaybeString || typeof objOrMaybeString !== "object") {
|
|
6
6
|
return objOrMaybeString;
|
|
@@ -18,7 +18,8 @@ const maybeParseJSON = (objOrMaybeJSON) => {
|
|
|
18
18
|
return {};
|
|
19
19
|
if (typeof objOrMaybeJSON === "string") {
|
|
20
20
|
try {
|
|
21
|
-
const
|
|
21
|
+
const cleanMarkdown = helpJsonMarkup(objOrMaybeJSON);
|
|
22
|
+
const result = JSON.parse(cleanMarkdown);
|
|
22
23
|
if (typeof result === "object" && result !== null) {
|
|
23
24
|
return result;
|
|
24
25
|
}
|
|
@@ -54,4 +55,23 @@ function isObjectStringified(maybeObject) {
|
|
|
54
55
|
return canDecode;
|
|
55
56
|
}
|
|
56
57
|
exports.isObjectStringified = isObjectStringified;
|
|
58
|
+
function helpJsonMarkup(str) {
|
|
59
|
+
if (typeof str !== "string") {
|
|
60
|
+
return str;
|
|
61
|
+
}
|
|
62
|
+
// TODO: improve?
|
|
63
|
+
const input = str.trim();
|
|
64
|
+
const markdownJsonStartsWith = "```json";
|
|
65
|
+
const markdownJsonEndsWith = "```";
|
|
66
|
+
if (input.substring(0, markdownJsonStartsWith.length) ===
|
|
67
|
+
markdownJsonStartsWith &&
|
|
68
|
+
input.substring(input.length - markdownJsonEndsWith.length, input.length) ===
|
|
69
|
+
markdownJsonEndsWith) {
|
|
70
|
+
return str
|
|
71
|
+
.substring(markdownJsonStartsWith.length, input.length - markdownJsonEndsWith.length)
|
|
72
|
+
?.trim();
|
|
73
|
+
}
|
|
74
|
+
return str;
|
|
75
|
+
}
|
|
76
|
+
exports.helpJsonMarkup = helpJsonMarkup;
|
|
57
77
|
//# sourceMappingURL=json.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"src/","sources":["utils/modules/json.ts"],"names":[],"mappings":";;;AAAO,MAAM,kBAAkB,GAAG,CAAC,gBAAqB,EAAU,EAAE;IAClE,IAAI,CAAC,gBAAgB,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE;QAC7D,OAAO,gBAAgB,CAAC;KACzB;IACD,IAAI;QACF,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;QAChD,OAAO,MAAM,CAAC;KACf;IAAC,OAAO,KAAK,EAAE,GAAE;IAClB,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AATW,QAAA,kBAAkB,sBAS7B;AAEK,MAAM,cAAc,GAAG,CAC5B,cAAmB,EACT,EAAE;IACZ,IAAI,CAAC,cAAc;QAAE,OAAO,EAAc,CAAC;IAE3C,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE;QACtC,IAAI;YACF,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"src/","sources":["utils/modules/json.ts"],"names":[],"mappings":";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
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateOpenAiPrice = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
4
5
|
const const_1 = require("../const");
|
|
5
6
|
/**
|
|
6
7
|
* Calculate the API call cost based on input and output tokens.
|
|
@@ -14,7 +15,7 @@ function calculateOpenAiPrice(model, input_tokens, output_tokens) {
|
|
|
14
15
|
output_cost: 0,
|
|
15
16
|
total_cost: 0,
|
|
16
17
|
};
|
|
17
|
-
const price = const_1.OpenAiPricing[
|
|
18
|
+
const price = (0, utils_1.get)(const_1.OpenAiPricing, model, [0, 0, 0]);
|
|
18
19
|
if (price) {
|
|
19
20
|
const [amount, inputAmount, outputAmount] = price;
|
|
20
21
|
if (inputAmount && input_tokens) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.js","sourceRoot":"src/","sources":["utils/modules/openai.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"src/","sources":["utils/modules/openai.ts"],"names":[],"mappings":";;;AAAA,mCAA8B;AAE9B,oCAAyC;AAEzC;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,KAAsB,EACtB,YAAoB,EACpB,aAAqB;IAErB,MAAM,GAAG,GAAG;QACV,UAAU,EAAE,CAAC;QACb,WAAW,EAAE,CAAC;QACd,UAAU,EAAE,CAAC;KACd,CAAC;IAEF,MAAM,KAAK,GAAG,IAAA,WAAG,EAAC,qBAAa,EAAE,KAAK,EAAE,CAAC,CAAC,EAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAA;IAChD,IAAI,KAAK,EAAE;QACT,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC;QAClD,IAAI,WAAW,IAAI,YAAY,EAAE;YAC/B,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,YAAY,GAAG,MAAM,CAAC,GAAG,WAAW,CAAC;SAC3D;QACD,IAAI,YAAY,IAAI,aAAa,EAAE;YACjC,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,aAAa,GAAG,MAAM,CAAC,GAAG,YAAY,CAAC;SAC9D;QAED,GAAG,CAAC,YAAY,CAAC,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,GAAG,CAAC,aAAa,CAAC,CAAC;KAC5D;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAzBD,oDAyBC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { PromptTemplateOptions } from "../../types";
|
|
2
2
|
export declare function replaceTemplateString(templateString?: string, substitutions?: Record<string, any>, configuration?: PromptTemplateOptions): string;
|
|
3
|
+
export declare function replaceTemplateStringAsync(templateString?: string, substitutions?: Record<string, any>, configuration?: PromptTemplateOptions): Promise<string>;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.replaceTemplateString = void 0;
|
|
3
|
+
exports.replaceTemplateStringAsync = exports.replaceTemplateString = void 0;
|
|
4
4
|
const handlebars_1 = require("./handlebars");
|
|
5
|
+
const hbs_1 = require("./handlebars/hbs");
|
|
5
6
|
function replaceTemplateString(templateString, substitutions = {}, configuration = {
|
|
6
7
|
helpers: [],
|
|
7
8
|
partials: [],
|
|
8
9
|
}) {
|
|
9
10
|
if (!templateString)
|
|
10
11
|
return templateString || "";
|
|
11
|
-
const
|
|
12
|
-
const template =
|
|
12
|
+
const instance = (0, handlebars_1.useHandlebars)(configuration, hbs_1.hbs);
|
|
13
|
+
const template = instance.compile(templateString);
|
|
13
14
|
const res = template(substitutions, {
|
|
14
15
|
allowedProtoMethods: {
|
|
15
16
|
substring: true,
|
|
@@ -18,4 +19,19 @@ function replaceTemplateString(templateString, substitutions = {}, configuration
|
|
|
18
19
|
return res;
|
|
19
20
|
}
|
|
20
21
|
exports.replaceTemplateString = replaceTemplateString;
|
|
22
|
+
function replaceTemplateStringAsync(templateString, substitutions = {}, configuration = {
|
|
23
|
+
helpers: [],
|
|
24
|
+
partials: [],
|
|
25
|
+
}) {
|
|
26
|
+
if (!templateString)
|
|
27
|
+
return Promise.resolve(templateString || "");
|
|
28
|
+
const instance = (0, handlebars_1.useHandlebars)(configuration, hbs_1.hbsAsync);
|
|
29
|
+
const template = instance.compile(templateString);
|
|
30
|
+
return template(substitutions, {
|
|
31
|
+
allowedProtoMethods: {
|
|
32
|
+
substring: true,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.replaceTemplateStringAsync = replaceTemplateStringAsync;
|
|
21
37
|
//# sourceMappingURL=replaceTemplateString.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replaceTemplateString.js","sourceRoot":"src/","sources":["utils/modules/replaceTemplateString.ts"],"names":[],"mappings":";;;AACA,6CAA6C;
|
|
1
|
+
{"version":3,"file":"replaceTemplateString.js","sourceRoot":"src/","sources":["utils/modules/replaceTemplateString.ts"],"names":[],"mappings":";;;AACA,6CAA6C;AAC7C,0CAAoD;AACpD,SAAgB,qBAAqB,CACnC,cAAuB,EACvB,gBAAqC,EAAE,EACvC,gBAAuC;IACrC,OAAO,EAAE,EAAE;IACX,QAAQ,EAAE,EAAE;CACb;IAED,IAAI,CAAC,cAAc;QAAE,OAAO,cAAc,IAAI,EAAE,CAAC;IAEjD,MAAM,QAAQ,GAAG,IAAA,0BAAa,EAAC,aAAa,EAAE,SAAG,CAAC,CAAC;IACnD,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAClD,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,EAAE;QAClC,mBAAmB,EAAE;YACnB,SAAS,EAAE,IAAI;SAChB;KACF,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC;AAlBD,sDAkBC;AAGD,SAAgB,0BAA0B,CACxC,cAAuB,EACvB,gBAAqC,EAAE,EACvC,gBAAuC;IACrC,OAAO,EAAE,EAAE;IACX,QAAQ,EAAE,EAAE;CACb;IAED,IAAI,CAAC,cAAc;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC;IAClE,MAAM,QAAQ,GAAG,IAAA,0BAAa,EAAC,aAAa,EAAE,cAAQ,CAAC,CAAA;IACvD,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAClD,OAAO,QAAQ,CAAC,aAAa,EAAE;QAC7B,mBAAmB,EAAE;YACnB,SAAS,EAAE,IAAI;SAChB;KACF,CAA+B,CAAA;AAClC,CAAC;AAhBD,gEAgBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "llm-exe",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"description": "Simplify building LLM-powered apps with easy-to-use base components, supporting text and chat-based prompts with handlebars template engine, output parsers, and flexible function calling capabilities.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"scripts": {
|
|
24
24
|
"tsc": "tsc --project ./tsconfig.json && tsc-alias -p ./tsconfig.json -w",
|
|
25
25
|
"tsc-ci": "tsc --project ./tsconfig.json && tsc-alias -p ./tsconfig.json",
|
|
26
|
-
"tsc-build": "tsc --project ./tsconfig-build.json && tsc-alias -p tsconfig-build.json",
|
|
26
|
+
"tsc-build": "tsc --project ./tsconfig-build.json && tsc-alias -p tsconfig-build.json -w",
|
|
27
27
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --coverage --forceExit",
|
|
28
28
|
"docs:dev": "vuepress dev docs --clean-temp --clean-cache",
|
|
29
29
|
"docs:build": "vuepress build docs --clean-temp --clean-cache",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"exponential-backoff": "3.1.1",
|
|
38
|
-
"handlebars": "4.7.
|
|
38
|
+
"handlebars": "4.7.6",
|
|
39
|
+
"handlebars-async-helpers": "^1.0.6",
|
|
39
40
|
"json-schema-to-ts": "^2.8.2",
|
|
40
41
|
"jsonschema": "1.4.1",
|
|
41
42
|
"lodash.camelcase": "^4.3.0",
|
|
@@ -45,7 +46,6 @@
|
|
|
45
46
|
"lodash.set": "^4.3.2",
|
|
46
47
|
"lodash.unescape": "^4.0.1",
|
|
47
48
|
"object-assign-deep": "0.4.0",
|
|
48
|
-
"openai": "^3.2.1",
|
|
49
49
|
"uuid": "^9.0.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"eslint-config-prettier": "^8.8.0",
|
|
69
69
|
"eslint-plugin-prettier": "^4.2.1",
|
|
70
70
|
"jest": "^29.5.0",
|
|
71
|
+
"openai": "^4.24.1",
|
|
71
72
|
"prettier": "^2.8.8",
|
|
72
73
|
"ts-jest": "^29.1.0",
|
|
73
74
|
"ts-node": "^10.9.1",
|